diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts index 7ff597570a..bb34126673 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts @@ -1,12 +1,15 @@ -import { MeResponseApiModel } from '@geonetwork-ui/data-access/gn4' -import { MeUserModel } from '@geonetwork-ui/common/domain/model/user/user.model' +import { + MeResponseApiModel, + UserApiModel, +} from '@geonetwork-ui/data-access/gn4' +import { UserModel } from '@geonetwork-ui/common/domain/model/user/user.model' import { Injectable } from '@angular/core' import { AvatarServiceInterface } from '../auth/avatar.service.interface' @Injectable() export class Gn4PlatformMapper { constructor(private avatarService: AvatarServiceInterface) {} - userFromApi(apiUser: MeResponseApiModel): MeUserModel { + userFromMeApi(apiUser: MeResponseApiModel): UserModel { if (!apiUser) return null const { hash, @@ -18,6 +21,22 @@ export class Gn4PlatformMapper { ...user } = apiUser const icon = this.avatarService.getProfileIcon(hash) - return { ...user, profileIcon: icon } as MeUserModel + return { ...user, profileIcon: icon } as UserModel + } + userFromApi(apiUser: UserApiModel): UserModel { + if (!apiUser) return null + const { + enabled, + emailAddresses, + organisation, + kind, + lastLoginDate, + accountNonExpired, + accountNonLocked, + id, + credentialsNonExpired, + ...user + } = apiUser + return { ...apiUser, id: id + '' } as UserModel } } diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts index 74dccf646a..2dbc9915ad 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts @@ -107,12 +107,12 @@ describe('Gn4PlatformService', () => { { username: 'ken', email: 'ken@sf2.com', - id: 1, + id: '1', }, { username: 'ryu', email: 'ryu@sf2.com', - id: 2, + id: '2', }, ]) }) diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts index 59fcda460b..5f641e7865 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts @@ -7,10 +7,7 @@ import { UsersApiService, } from '@geonetwork-ui/data-access/gn4' import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface' -import { - MeUserModel, - UserModel, -} from '@geonetwork-ui/common/domain/model/user/user.model' +import { UserModel } from '@geonetwork-ui/common/domain/model/user/user.model' import { Organization } from '@geonetwork-ui/common/domain/model/record' import { Gn4PlatformMapper } from './gn4-platform.mapper' @@ -18,7 +15,7 @@ const minApiVersion = '4.2.0' @Injectable() export class Gn4PlatformService implements PlatformServiceInterface { private readonly type = 'GeoNetwork' - private me$: Observable + private me$: Observable private users$: Observable isAnonymous$: Observable @@ -48,11 +45,14 @@ export class Gn4PlatformService implements PlatformServiceInterface { private mapper: Gn4PlatformMapper ) { this.me$ = this.meApi.getMe().pipe( - map((apiUser) => this.mapper.userFromApi(apiUser)), + map((apiUser) => this.mapper.userFromMeApi(apiUser)), shareReplay({ bufferSize: 1, refCount: true }) ) this.isAnonymous$ = this.me$.pipe(map((user) => !user || !('id' in user))) - this.users$ = this.usersApi.getUsers().pipe(shareReplay()) + this.users$ = this.usersApi.getUsers().pipe( + map((users) => users.map((user) => this.mapper.userFromApi(user))), + shareReplay() + ) } getTye(): string { @@ -66,7 +66,7 @@ export class Gn4PlatformService implements PlatformServiceInterface { return this.isApiCompatible$ } - getMe(): Observable { + getMe(): Observable { return this.me$ } diff --git a/libs/common/domain/src/lib/model/user/user.model.ts b/libs/common/domain/src/lib/model/user/user.model.ts index efb591071c..61ed23805c 100644 --- a/libs/common/domain/src/lib/model/user/user.model.ts +++ b/libs/common/domain/src/lib/model/user/user.model.ts @@ -1,4 +1,4 @@ -export interface MeUserModel { +export interface UserModel { id: string profile: string username: string @@ -9,13 +9,8 @@ export interface MeUserModel { profileIcon?: string } -export interface UserModel { - profile?: string - surname?: string +export interface UserModela { enabled?: boolean - username?: string - id?: number - email?: string emailAddresses?: Set organisation?: string kind?: string @@ -23,5 +18,4 @@ export interface UserModel { accountNonExpired?: boolean accountNonLocked?: boolean credentialsNonExpired?: boolean - name?: string } diff --git a/libs/common/domain/src/lib/platform.service.interface.ts b/libs/common/domain/src/lib/platform.service.interface.ts index 6d84d9fa90..14d464cac8 100644 --- a/libs/common/domain/src/lib/platform.service.interface.ts +++ b/libs/common/domain/src/lib/platform.service.interface.ts @@ -1,5 +1,5 @@ import { Observable } from 'rxjs' -import { MeUserModel, UserModel } from './model/user/user.model' +import { UserModel } from './model/user/user.model' import { Organization } from './model/record/organization.model' export abstract class PlatformServiceInterface { @@ -7,7 +7,7 @@ export abstract class PlatformServiceInterface { abstract getApiVersion(): Observable abstract isApiCompatible(): Observable - abstract getMe(): Observable + abstract getMe(): Observable abstract isAnonymous(): Observable abstract getUsers(): Observable abstract getUsersByOrganization( diff --git a/libs/common/fixtures/src/lib/user.fixtures.ts b/libs/common/fixtures/src/lib/user.fixtures.ts index 81183be9d9..9d55502797 100644 --- a/libs/common/fixtures/src/lib/user.fixtures.ts +++ b/libs/common/fixtures/src/lib/user.fixtures.ts @@ -1,6 +1,6 @@ -import { MeUserModel } from '@geonetwork-ui/common/domain/model/user/user.model' +import { UserModel } from '@geonetwork-ui/common/domain/model/user/user.model' -export const USER_FIXTURE = (): MeUserModel => ({ +export const USER_FIXTURE = (): UserModel => ({ id: '46798', profile: 'Administrator', username: 'Gravin', @@ -12,7 +12,7 @@ export const USER_FIXTURE = (): MeUserModel => ({ 'https://www.gravatar.com/avatar/dbdffd183622800bcf8587328daf43a6?d=mp', }) -export const USER_FIXTURE_ANON = (): MeUserModel => ({ +export const USER_FIXTURE_ANON = (): UserModel => ({ id: '161', profile: 'Administrator', username: 'ghost16', @@ -24,7 +24,7 @@ export const USER_FIXTURE_ANON = (): MeUserModel => ({ 'https://www.gravatar.com/avatar/dbdffd183622800bcf8587328daf43a6?d=mp', }) -export const USERS_FIXTURE = (): MeUserModel[] => [ +export const USERS_FIXTURE = (): UserModel[] => [ USER_FIXTURE(), USER_FIXTURE_ANON(), { diff --git a/libs/feature/catalog/src/lib/my-org/my-org.service.spec.ts b/libs/feature/catalog/src/lib/my-org/my-org.service.spec.ts index 7a19836c3b..824c64f1b0 100644 --- a/libs/feature/catalog/src/lib/my-org/my-org.service.spec.ts +++ b/libs/feature/catalog/src/lib/my-org/my-org.service.spec.ts @@ -4,7 +4,7 @@ import { AvatarServiceInterface } from '@geonetwork-ui/api/repository/gn4' import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface' import { BehaviorSubject, of } from 'rxjs' import { UserApiModel } from '@geonetwork-ui/data-access/gn4' -import { MeUserModel } from '@geonetwork-ui/common/domain/model/user/user.model' +import { UserModel } from '@geonetwork-ui/common/domain/model/user/user.model' import { HttpClientTestingModule } from '@angular/common/http/testing' import { TranslateService } from '@ngx-translate/core' import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface' @@ -27,7 +27,7 @@ class orgServiceMock { organisations$ = orgs$ } -const userSubject = new BehaviorSubject(null) +const userSubject = new BehaviorSubject(null) const allUsersSubject = new BehaviorSubject([]) class PlatformServiceMock { @@ -68,7 +68,7 @@ describe('MyOrgService', () => { }) it('should update myOrgDataSubject when authService user$ emits a user', () => { - const user: MeUserModel = { + const user: UserModel = { organisation: 'Géo2France', id: '2', profile: 'profile', diff --git a/libs/ui/elements/src/lib/user-preview/user-preview.component.ts b/libs/ui/elements/src/lib/user-preview/user-preview.component.ts index 213bb891e2..779ac1b654 100644 --- a/libs/ui/elements/src/lib/user-preview/user-preview.component.ts +++ b/libs/ui/elements/src/lib/user-preview/user-preview.component.ts @@ -1,5 +1,5 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core' -import { MeUserModel } from '@geonetwork-ui/common/domain/model/user/user.model' +import { UserModel } from '@geonetwork-ui/common/domain/model/user/user.model' @Component({ selector: 'gn-ui-user-preview', @@ -7,7 +7,7 @@ import { MeUserModel } from '@geonetwork-ui/common/domain/model/user/user.model' changeDetection: ChangeDetectionStrategy.OnPush, }) export class UserPreviewComponent { - @Input() user: MeUserModel + @Input() user: UserModel @Input() avatarPlaceholder?: string get userFullName() {