Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix : set language with ui-culture on auth-code-flow #20935

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions npm/ng-packs/packages/core/src/lib/services/config-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class ConfigStateService {
private updateSubject = new Subject<void>();
private readonly store = new InternalStore({} as ApplicationConfigurationDto);

public uiCultureFromAuthCodeFlow: string;

setState(config: ApplicationConfigurationDto) {
this.store.set(config);
}
Expand Down Expand Up @@ -53,7 +55,11 @@ export class ConfigStateService {
if (!appState.localization.currentCulture.cultureName) {
throw new Error('culture name should defined');
}
return this.getlocalizationResource(appState.localization.currentCulture.cultureName).pipe(

const cultureName =
this.uiCultureFromAuthCodeFlow ?? appState.localization.currentCulture.cultureName;

return this.getlocalizationResource(cultureName).pipe(
map(result => ({ ...appState, localization: { ...appState.localization, ...result } })),
);
}
Expand All @@ -71,10 +77,10 @@ export class ConfigStateService {
}

refreshLocalization(lang: string): Observable<null> {
if(this.includeLocalizationResources){
if (this.includeLocalizationResources) {
return this.refreshAppState().pipe(map(() => null));
}

return this.getlocalizationResource(lang)
.pipe(
tap(result =>
Expand Down Expand Up @@ -145,7 +151,7 @@ export class ConfigStateService {
return keys.reduce((acc, key) => ({ ...acc, [key]: features.values[key] }), {});
}

getFeatures$(keys: string[]): Observable<{ [key: string]: string; } | undefined> {
getFeatures$(keys: string[]): Observable<{ [key: string]: string } | undefined> {
return this.store.sliceState(({ features }) => {
if (!features?.values) return;

Expand All @@ -168,10 +174,13 @@ export class ConfigStateService {

const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1);

return keysFound.reduce((acc, key) => {
acc[key] = settings[key];
return acc;
}, {} as Record<string, string>);
return keysFound.reduce(
(acc, key) => {
acc[key] = settings[key];
return acc;
},
{} as Record<string, string>,
);
}

getSettings$(keyword?: string) {
Expand All @@ -183,10 +192,13 @@ export class ConfigStateService {

const keysFound = Object.keys(settings).filter(key => key.indexOf(keyword) > -1);

return keysFound.reduce((acc, key) => {
acc[key] = settings[key];
return acc;
}, {} as Record<string, string>);
return keysFound.reduce(
(acc, key) => {
acc[key] = settings[key];
return acc;
},
{} as Record<string, string>,
);
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { noop } from '@abp/ng.core';
import { Params } from '@angular/router';
import { from, of } from 'rxjs';
import { filter, from, of, tap } from 'rxjs';
import { AuthFlowStrategy } from './auth-flow-strategy';
import { isTokenExpired } from '../utils';

Expand All @@ -9,6 +9,7 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {

async init() {
this.checkRememberMeOption();
this.setUICulture();

return super
.init()
Expand Down Expand Up @@ -68,4 +69,17 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy {
const culture = { culture: lang, 'ui-culture': lang };
return { ...(lang && culture), ...queryParams };
}

private setUICulture() {
this.oAuthService.events
.pipe(
filter(event => event.type === 'token_received'),
tap(e => {
const urlParams = new URLSearchParams(window.location.search);
this.configState.uiCultureFromAuthCodeFlow = urlParams.get('ui-culture');
window.history.replaceState(null, '', window.location.pathname);
}),
)
.subscribe();
}
masum-ulu marked this conversation as resolved.
Show resolved Hide resolved
}
Loading