Skip to content

Commit

Permalink
Merge pull request #376 from MauroDataMapper/feature/gh-375-use-sdeUs…
Browse files Browse the repository at this point in the history
…erDetails

gh-375 - return the sde user details rather than the mdm user details.
  • Loading branch information
NigelPalmer authored Mar 14, 2024
2 parents 3b3b895 + 2c5dc4a commit 675d63f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
19 changes: 4 additions & 15 deletions src/app/secure-data-environment/configuration/sde-security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,14 @@ limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/
import { Injectable } from '@angular/core';
import { ISdeSecurity, SignedInUserDetails } from '@maurodatamapper/sde-resources';
import { ISdeSecurity, SdeUserDetails } from '@maurodatamapper/sde-resources';
import { UserDetailsService } from 'src/app/security/user-details.service';

@Injectable({ providedIn: 'root' })
export class SdeSecurity implements ISdeSecurity {
constructor(private userDetails: UserDetailsService) {}
constructor(private userDetails: UserDetailsService) { }

getSignedInUser() {
const securityDetails = this.userDetails.get();
if (securityDetails) {
return {
id: securityDetails.id,
firstName: securityDetails.firstName,
lastName: securityDetails.lastName,
email: securityDetails.email,
role: securityDetails.role,
token: securityDetails.sdeAuthToken,
} as SignedInUserDetails;
}
return null;
getSignedInUser(): SdeUserDetails | null {
return this.userDetails.getSdeResearchUser();
}
}
18 changes: 16 additions & 2 deletions src/app/security/user-details.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SPDX-License-Identifier: Apache-2.0
*/
import { Injectable } from '@angular/core';
import { FolderDetail } from '@maurodatamapper/mdm-resources';
import { ResearchUser } from '@maurodatamapper/sde-resources';
import { ResearchUser, SdeUserDetails } from '@maurodatamapper/sde-resources';

/**
* Represents the common details of a signed in user.
Expand All @@ -44,7 +44,7 @@ export interface UserDetails {
providedIn: 'root',
})
export class UserDetailsService {
constructor() {}
constructor() { }

/**
* Gets the current user in use, or null if there is no current user.
Expand Down Expand Up @@ -107,6 +107,20 @@ export class UserDetailsService {
localStorage.removeItem('sdeAuthToken');
}

getSdeResearchUser(): SdeUserDetails | null {
if (!this.hasSdeResearchUser()) {
return null;
}

return {
id: localStorage.getItem('sdeUserId') ?? '',
email: localStorage.getItem('sdeEmail') ?? '',
firstName: localStorage.getItem('firstName') ?? '',
lastName: localStorage.getItem('lastName') ?? '',
role: localStorage.getItem('role') ?? '',
} as SdeUserDetails;
}

setSdeResearchUser(user: ResearchUser) {
localStorage.setItem('sdeUserId', user.id);
localStorage.setItem('sdeEmail', user.email);
Expand Down

0 comments on commit 675d63f

Please sign in to comment.