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

[Editor] : Access account settings #1048

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -9,7 +9,7 @@
}

let windowLocation
Object.defineProperties((global as any).window, {

Check warning on line 12 in libs/api/repository/src/lib/gn4/auth/auth.service.spec.ts

View workflow job for this annotation

GitHub Actions / Format check, lint, unit tests

Unexpected any. Specify a different type
location: {
get: () => new URL(windowLocation),
},
Expand Down Expand Up @@ -91,4 +91,14 @@
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
Loading