diff --git a/apps/mina-sidor-fa/src/app/pages/my-account/my-account.component.html b/apps/mina-sidor-fa/src/app/pages/my-account/my-account.component.html
index 941b29a..7a04e18 100644
--- a/apps/mina-sidor-fa/src/app/pages/my-account/my-account.component.html
+++ b/apps/mina-sidor-fa/src/app/pages/my-account/my-account.component.html
@@ -73,7 +73,7 @@
-
diff --git a/apps/mina-sidor-fa/src/app/pages/my-account/my-account.component.ts b/apps/mina-sidor-fa/src/app/pages/my-account/my-account.component.ts
index dcd699a..aa2593c 100644
--- a/apps/mina-sidor-fa/src/app/pages/my-account/my-account.component.ts
+++ b/apps/mina-sidor-fa/src/app/pages/my-account/my-account.component.ts
@@ -1,9 +1,9 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Router } from '@angular/router';
import { IconType } from '@msfa-enums/icon-type.enum';
+import { Employee } from '@msfa-models/employee.model';
import { Organization } from '@msfa-models/organization.model';
import { Role } from '@msfa-models/role.model';
-import { User } from '@msfa-models/user.model';
import { UserService } from '@msfa-services/api/user.service';
import { RoleService } from '@msfa-services/role.service';
import { combineLatest, Observable } from 'rxjs';
@@ -16,7 +16,7 @@ import { filter, map } from 'rxjs/operators';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MyAccountComponent {
- user$: Observable = this.userService.user$;
+ user$: Observable = this.userService.user$;
selectedOrganization$: Observable = this.userService.selectedOrganization$;
organizations$: Observable = this.userService.organizations$;
otherOrganizations$: Observable = combineLatest([
@@ -33,10 +33,6 @@ export class MyAccountComponent {
constructor(private userService: UserService, private roleService: RoleService, private router: Router) {}
- userHasRole(userRoles: Role[], currentRole: Role): boolean {
- return userRoles.some(role => role.type === currentRole.type);
- }
-
loginWithOrganization(organization: Organization): void {
this.userService.setSelectedOrganization(organization);
}
diff --git a/apps/mina-sidor-fa/src/app/pages/my-account/my-account.module.ts b/apps/mina-sidor-fa/src/app/pages/my-account/my-account.module.ts
index 02e308a..2738bef 100644
--- a/apps/mina-sidor-fa/src/app/pages/my-account/my-account.module.ts
+++ b/apps/mina-sidor-fa/src/app/pages/my-account/my-account.module.ts
@@ -2,6 +2,7 @@ import { DigiNgSkeletonBaseModule } from '@af/digi-ng/_skeleton/skeleton-base';
import { CommonModule } from '@angular/common';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
+import { HideTextModule } from '@msfa-shared/components/hide-text/hide-text.module';
import { IconModule } from '@msfa-shared/components/icon/icon.module';
import { LayoutModule } from '@msfa-shared/components/layout/layout.module';
import { OrganizationPickerFormModule } from '@msfa-shared/components/organization-picker-form/organization-picker-form.module';
@@ -19,6 +20,7 @@ import { MyAccountComponent } from './my-account.component';
DigiNgSkeletonBaseModule,
OrganizationPickerFormModule,
RolesDialogModule,
+ HideTextModule,
],
})
export class MyAccountModule {}
diff --git a/apps/mina-sidor-fa/src/app/shared/components/layout/components/navigation/navigation.component.ts b/apps/mina-sidor-fa/src/app/shared/components/layout/components/navigation/navigation.component.ts
index 75e406e..7d7e7e6 100644
--- a/apps/mina-sidor-fa/src/app/shared/components/layout/components/navigation/navigation.component.ts
+++ b/apps/mina-sidor-fa/src/app/shared/components/layout/components/navigation/navigation.component.ts
@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { IconType } from '@msfa-enums/icon-type.enum';
+import { Employee } from '@msfa-models/employee.model';
import { Organization } from '@msfa-models/organization.model';
-import { User } from '@msfa-models/user.model';
@Component({
selector: 'msfa-navigation',
@@ -10,7 +10,7 @@ import { User } from '@msfa-models/user.model';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NavigationComponent {
- @Input() user: User;
+ @Input() user: Employee;
@Input() selectedOrganization: Organization;
iconType = IconType;
}
diff --git a/apps/mina-sidor-fa/src/app/shared/components/layout/layout.component.ts b/apps/mina-sidor-fa/src/app/shared/components/layout/layout.component.ts
index d42da6a..20a41b0 100644
--- a/apps/mina-sidor-fa/src/app/shared/components/layout/layout.component.ts
+++ b/apps/mina-sidor-fa/src/app/shared/components/layout/layout.component.ts
@@ -3,14 +3,14 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { UnsubscribeDirective } from '@msfa-directives/unsubscribe.directive';
+import { Employee } from '@msfa-models/employee.model';
import { Organization } from '@msfa-models/organization.model';
import { Role } from '@msfa-models/role.model';
-import { User } from '@msfa-models/user.model';
import { AuthenticationService } from '@msfa-services/api/authentication.service';
import { UserService } from '@msfa-services/api/user.service';
import { mapPathsToBreadcrumbs } from '@msfa-utils/map-paths-to-breadcrumbs.util';
import { BehaviorSubject, Observable } from 'rxjs';
-import { filter, map } from 'rxjs/operators';
+import { filter } from 'rxjs/operators';
@Component({
selector: 'msfa-layout',
@@ -27,11 +27,8 @@ export class LayoutComponent extends UnsubscribeDirective {
private _breadcrumbsItems$ = new BehaviorSubject([this._startBreadcrumb]);
isLoggedIn$: Observable = this.authenticationService.isLoggedIn$;
selectedOrganization$: Observable = this.userService.selectedOrganization$;
- user$: Observable = this.userService.user$;
- roles$: Observable = this.user$.pipe(
- filter(user => !!user),
- map(user => user.roles)
- );
+ user$: Observable = this.userService.user$.pipe(filter(user => !!user));
+ roles$: Observable = this.userService.userRoles$.pipe(filter(roles => !!roles?.length));
get breadcrumbsItems(): NavigationBreadcrumbsItem[] {
return this._breadcrumbsItems$.getValue();
diff --git a/apps/mina-sidor-fa/src/app/shared/guards/role.guard.ts b/apps/mina-sidor-fa/src/app/shared/guards/role.guard.ts
index 68a35b4..2a4773b 100644
--- a/apps/mina-sidor-fa/src/app/shared/guards/role.guard.ts
+++ b/apps/mina-sidor-fa/src/app/shared/guards/role.guard.ts
@@ -14,9 +14,9 @@ export class RoleGuard implements CanActivate {
canActivate(route: ActivatedRouteSnapshot): Observable {
const expectedRole: RoleEnum = route.data.expectedRole as RoleEnum;
- return this.userService.user$.pipe(
- filter(user => !!user),
- map(({ roles }) => {
+ return this.userService.userRoles$.pipe(
+ filter(roles => !!roles?.length),
+ map(roles => {
const userHasRole = roles.some(role => role.type === expectedRole);
if (userHasRole) {
diff --git a/apps/mina-sidor-fa/src/app/shared/models/user.model.ts b/apps/mina-sidor-fa/src/app/shared/models/user.model.ts
index 09f0bf2..d9fac15 100644
--- a/apps/mina-sidor-fa/src/app/shared/models/user.model.ts
+++ b/apps/mina-sidor-fa/src/app/shared/models/user.model.ts
@@ -1,22 +1,6 @@
-import { OrganizationResponse } from './api/organization.response.model';
-import { UserInfoResponse } from './api/user-info.response.model';
-import { mapResponseToOrganization, Organization } from './organization.model';
-import { mapResponseToRoles } from './role.model';
-import { UserInfo } from './user-info.model';
+import { Employee } from './employee.model';
+import { Organization } from './organization.model';
-export interface User extends UserInfo {
+export interface User extends Employee {
organizations: Organization[];
}
-
-export function mapUserApiResponseToUser(userInfo: UserInfoResponse, organizations: OrganizationResponse[]): User {
- const { id, firstName, lastName, roles } = userInfo;
-
- return {
- id,
- firstName,
- lastName,
- fullName: `${firstName} ${lastName}`,
- roles: mapResponseToRoles(roles),
- organizations: organizations ? organizations.map(organization => mapResponseToOrganization(organization)) : [],
- };
-}
diff --git a/apps/mina-sidor-fa/src/app/shared/services/api/user.service.ts b/apps/mina-sidor-fa/src/app/shared/services/api/user.service.ts
index be6713d..dc47be0 100644
--- a/apps/mina-sidor-fa/src/app/shared/services/api/user.service.ts
+++ b/apps/mina-sidor-fa/src/app/shared/services/api/user.service.ts
@@ -3,11 +3,13 @@ import { Injectable } from '@angular/core';
import { SELECTED_ORGANIZATION_NUMBER_KEY } from '@msfa-constants/local-storage-keys';
import { UnsubscribeDirective } from '@msfa-directives/unsubscribe.directive';
import { environment } from '@msfa-environment';
+import { EmployeeResponse } from '@msfa-models/api/employee.response.model';
import { OrganizationResponse } from '@msfa-models/api/organization.response.model';
import { UserInfoResponse } from '@msfa-models/api/user-info.response.model';
+import { Employee, mapResponseToEmployee } from '@msfa-models/employee.model';
import { mapResponseToOrganization, Organization } from '@msfa-models/organization.model';
+import { Role } from '@msfa-models/role.model';
import { mapResponseToUserInfo, UserInfo } from '@msfa-models/user-info.model';
-import { User } from '@msfa-models/user.model';
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
import { filter, map, switchMap } from 'rxjs/operators';
import { AuthenticationService } from './authentication.service';
@@ -16,12 +18,16 @@ import { AuthenticationService } from './authentication.service';
providedIn: 'root',
})
export class UserService extends UnsubscribeDirective {
- private _apiBaseUrl = `${environment.api.url}/auth`;
+ private _apiAuthUrl = `${environment.api.url}/auth`;
+ private _apiUserUrl = `${environment.api.url}/users/currentUser`;
+
private _isLoggedIn$: Observable = this.authenticationService.isLoggedIn$;
private _organizations$ = new BehaviorSubject(null);
public organizations$: Observable = this._organizations$.asObservable();
- private _user$ = new BehaviorSubject(null);
- public user$: Observable = this._user$.asObservable();
+ private _user$ = new BehaviorSubject(null);
+ public user$: Observable = this._user$.asObservable();
+ private _userRoles$ = new BehaviorSubject(null);
+ public userRoles$: Observable = this._userRoles$.asObservable();
private _selectedOrganizationNumber$ = new BehaviorSubject(null);
constructor(private httpClient: HttpClient, private authenticationService: AuthenticationService) {
@@ -39,28 +45,37 @@ export class UserService extends UnsubscribeDirective {
combineLatest([this._isLoggedIn$, this.selectedOrganization$])
.pipe(
filter(([loggedIn, selectedOrganization]) => !!(loggedIn && selectedOrganization)),
- switchMap(() => this._fetchUserInfo$())
+ switchMap(() => combineLatest([this._fetchUserInfo$(), this._fetchCurrentUser$()]))
)
- .subscribe(userInfo => {
- this._user$.next({ ...userInfo, organizations: this._organizations$.value });
+ .subscribe(([userInfo, currentUser]) => {
+ this._userRoles$.next(userInfo.roles);
+ this._user$.next(currentUser);
})
);
}
private _fetchOrganizations$(): Observable {
- return this.httpClient.get<{ data: OrganizationResponse[] }>(`${this._apiBaseUrl}/organizations`).pipe(
+ return this.httpClient.get<{ data: OrganizationResponse[] }>(`${this._apiAuthUrl}/organizations`).pipe(
filter(response => !!response?.data),
map(({ data }) => data.map(organization => mapResponseToOrganization(organization)))
);
}
private _fetchUserInfo$(): Observable {
- return this.httpClient.get<{ data: UserInfoResponse }>(`${this._apiBaseUrl}/userinfo`).pipe(
+ return this.httpClient.get<{ data: UserInfoResponse }>(`${this._apiAuthUrl}/userinfo`).pipe(
filter(response => !!response?.data),
map(({ data }) => mapResponseToUserInfo(data))
);
}
+ private _fetchCurrentUser$(): Observable {
+ console.log('fetching current user');
+ return this.httpClient.get<{ data: EmployeeResponse }>(`${this._apiUserUrl}`).pipe(
+ filter(response => !!response?.data),
+ map(({ data }) => mapResponseToEmployee(data))
+ );
+ }
+
private get _selectedOrganizationNumber(): string | null {
return localStorage.getItem(SELECTED_ORGANIZATION_NUMBER_KEY);
}
diff --git a/apps/mina-sidor-fa/src/app/shared/services/role.service.ts b/apps/mina-sidor-fa/src/app/shared/services/role.service.ts
index 6ed77a3..f0ad6a7 100644
--- a/apps/mina-sidor-fa/src/app/shared/services/role.service.ts
+++ b/apps/mina-sidor-fa/src/app/shared/services/role.service.ts
@@ -1,11 +1,13 @@
import { Injectable } from '@angular/core';
import { RoleEnum } from '@msfa-enums/role.enum';
+import { environment } from '@msfa-environment';
import { mapResponseToRoles, Role } from '@msfa-models/role.model';
@Injectable({
providedIn: 'root',
})
export class RoleService {
+ private readonly _apiBaseUrl = `${environment.api.url}/auth/userinfo`;
public get allRoles(): Role[] {
return mapResponseToRoles(Object.keys(RoleEnum) as RoleEnum[]);
}