Skip to content

Commit

Permalink
Merge pull request #1048 from geonetwork/ME-access-account-settings
Browse files Browse the repository at this point in the history
[Editor] : Access account settings
  • Loading branch information
cmoinier authored Nov 27, 2024
2 parents f396dd7 + 23830d0 commit 15e7729
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 10 deletions.
12 changes: 12 additions & 0 deletions apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,18 @@ describe('dashboard (authenticated)', () => {
})
})
})
describe('Account settings access', () => {
it('should navigate to the account settings page', () => {
cy.visit('/catalog/search')
cy.get('md-editor-sidebar')
.find('gn-ui-button')
.first()
.find('a')
.invoke('removeAttr', 'target')
.click()
cy.url().should('include', '/admin.console')
})
})
})

describe('Logging in and out', () => {
Expand Down
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 @@ -20,13 +20,15 @@
>
<gn-ui-button
type="default"
class="w-10 h-10 flex justify-center items-center hover:cursor-pointer"
class="w-10 h-10 flex justify-center items-center hover:cursor-pointer mb-1"
>
<gn-ui-user-preview
[user]="user"
[avatarPlaceholder]="placeholder$ | async"
extraClass="w-10 h-10"
></gn-ui-user-preview>
<a [href]="settingsUrl" target="_blank">
<gn-ui-user-preview
[user]="user"
[avatarPlaceholder]="placeholder$ | async"
extraClass="w-10 h-10"
></gn-ui-user-preview>
</a>
</gn-ui-button>
<gn-ui-button
type="default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export class SidebarComponent implements OnInit {
public placeholder$ = this.avatarService.getPlaceholder()
organisations$: Observable<Organization[]>

get settingsUrl() {
return this.authService.settingsUrl
}

constructor(
public platformService: PlatformServiceInterface,
private avatarService: AvatarServiceInterface,
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='
)
})
})
})
13 changes: 13 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,17 @@ export class AuthService {
return this.baseLogoutUrl
}

get settingsUrl() {
return this.baseSettingsUrl.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
) {}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<figure class="text-center">
<div
class="w-10 h-10 border border-primary rounded-full capitalize"
[matTooltip]="userFullName"
>
<div class="w-10 h-10 rounded-full capitalize" [matTooltip]="userFullName">
<gn-ui-avatar
[avatarUrl]="user.profileIcon"
[avatarPlaceholder]="avatarPlaceholder"
Expand Down
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 15e7729

Please sign in to comment.