Skip to content

Commit

Permalink
feat: make settings url configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
cmoinier committed Nov 27, 2024
1 parent 9b86248 commit f19ce2e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
5 changes: 5 additions & 0 deletions apps/metadata-editor/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { EditorRouterService } from './router.service'
import {
LOGIN_URL,
LOGOUT_URL,
SETTINGS_URL,
provideGn4,
provideRepositoryUrl,
} from '@geonetwork-ui/api/repository'
Expand Down Expand Up @@ -75,6 +76,10 @@ import { FeatureEditorModule } from '@geonetwork-ui/feature/editor'
provide: LOGOUT_URL,
useFactory: () => getGlobalConfig().LOGOUT_URL,
},
{
provide: SETTINGS_URL,
useFactory: () => getGlobalConfig().SETTINGS_URL,
},
],
bootstrap: [AppComponent],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ export class SidebarComponent implements OnInit {
organisations$: Observable<Organization[]>

get settingsUrl() {
return (
this.authService.loginUrl.split('/catalog')[0] +
'/admin.console#/organization/users?userOrGroup='
)
return this.authService.settingsUrl
}

constructor(
Expand Down
1 change: 1 addition & 0 deletions conf/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ proxy_path = ""
# Example to use the georchestra login page:
# login_url = "/cas/login?service=${current_url}"
# logout_url = "/geonetwork/signout"
# settings_url = "/geonetwork/srv/\${lang3}/admin.console#/organization/users?userOrGroup="
# This optional URL should point to the static html page wc-embedder.html which allows to display a web component (like chart and table) via a permalink.
# URLs can be indicated from the root of the same server starting with a "/" or as an external URL. Be conscious of potential CORS issues when using an external URL.
# The default location in the dockerized datahub app for example is "/datahub/wc-embedder.html".
Expand Down
10 changes: 10 additions & 0 deletions libs/api/repository/src/lib/gn4/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,14 @@ describe('AuthService', () => {
expect(service.logoutUrl).toEqual('/geonetwork/signout')
})
})
describe('Settings', () => {
beforeEach(() => {
service = TestBed.inject(AuthService)
})
it('should return the logout url', () => {
expect(service.settingsUrl).toEqual(
'/geonetwork/srv/fre/admin.console#/organization/users?userOrGroup='
)
})
})
})
14 changes: 14 additions & 0 deletions libs/api/repository/src/lib/gn4/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ export const LOGIN_URL = new InjectionToken<string>('loginUrl')
export const DEFAULT_GN4_LOGOUT_URL = `/geonetwork/signout`
export const LOGOUT_URL = new InjectionToken<string>('logoutUrl')

export const DEFAULT_GN4_SETTINGS_URL = `/geonetwork/srv/\${lang3}/admin.console#/organization/users?userOrGroup=`
export const SETTINGS_URL = new InjectionToken<string>('settingsUrl')

@Injectable({
providedIn: 'root',
})
export class AuthService {
baseLoginUrl = this.baseLoginUrlToken || DEFAULT_GN4_LOGIN_URL
baseLogoutUrl = this.baseLogoutUrlToken || DEFAULT_GN4_LOGOUT_URL
baseSettingsUrl = this.baseSettingsUrlToken || DEFAULT_GN4_SETTINGS_URL

get loginUrl() {
let baseUrl = this.baseLoginUrl
const locationHasQueryParams = !!window.location.search
Expand All @@ -34,9 +39,18 @@ export class AuthService {
return this.baseLogoutUrl
}

get settingsUrl() {
let baseUrl = this.baseSettingsUrl

Check failure on line 43 in libs/api/repository/src/lib/gn4/auth/auth.service.ts

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

'baseUrl' is never reassigned. Use 'const' instead
return baseUrl.replace(
'${lang3}',
LANG_2_TO_3_MAPPER[this.translateService.currentLang]
)
}

constructor(
@Optional() @Inject(LOGIN_URL) private baseLoginUrlToken: string,
@Optional() @Inject(LOGOUT_URL) private baseLogoutUrlToken: string,
@Optional() @Inject(SETTINGS_URL) private baseSettingsUrlToken: string,
private translateService: TranslateService
) {}
}
1 change: 1 addition & 0 deletions libs/util/app-config/src/lib/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export function loadAppConfig() {
: undefined,
LOGIN_URL: parsedGlobalSection.login_url,
LOGOUT_URL: parsedGlobalSection.logout_url,
SETTINGS_URL: parsedGlobalSection.settings_url,
WEB_COMPONENT_EMBEDDER_URL:
parsedGlobalSection.web_component_embedder_url,
LANGUAGES: parsedGlobalSection.languages,
Expand Down
1 change: 1 addition & 0 deletions libs/util/app-config/src/lib/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface GlobalConfig {
METADATA_LANGUAGE?: string
LOGIN_URL?: string
LOGOUT_URL?: string
SETTINGS_URL?: string
WEB_COMPONENT_EMBEDDER_URL?: string
LANGUAGES?: string[]
CONTACT_EMAIL?: string
Expand Down

0 comments on commit f19ce2e

Please sign in to comment.