diff --git a/src/app/core/models/user.ts b/src/app/core/models/user.ts index cfe62b4d..71cb4c09 100644 --- a/src/app/core/models/user.ts +++ b/src/app/core/models/user.ts @@ -19,6 +19,27 @@ export class UserModel { version: string; } +export class UserFromTokenModel { + userID: string; + userExternalID?: string; + username?: string; + dateCreated?: string | Date; + dateModified?: string | Date; + lfEmail?: string; + lfUsername?: string; + companyID?: string; + githubID?: string; + githubUsername?: string; + gitlabID?: string; + gitlabUsername?: string; + admin?: boolean; + version?: string; + note?: string; + emails?: string[]; + userCompanyID?: string; + isSanctioned?: boolean; +} + export class UpdateUserModel { companyID: string; dateCreated: Date; diff --git a/src/app/core/services/cla-contributor.service.ts b/src/app/core/services/cla-contributor.service.ts index 6f345d37..8bb5b5d2 100644 --- a/src/app/core/services/cla-contributor.service.ts +++ b/src/app/core/services/cla-contributor.service.ts @@ -5,7 +5,7 @@ import {Injectable, isDevMode} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Observable, Subject} from 'rxjs'; import {Project, ProjectModel} from '../models/project'; -import {UpdateUserModel, UserModel} from '../models/user'; +import {UpdateUserModel, UserModel, UserFromTokenModel} from '../models/user'; import {AlertService} from 'src/app/shared/services/alert.service'; import {ActiveSignatureModel} from '../models/active-signature'; import {IndividualRequestSignatureModel} from '../models/individual-request-signature'; @@ -60,6 +60,11 @@ export class ClaContributorService { return this.httpClient.get(url); } + getUserFromToken(): Observable { + const url = this.getV4Endpoint('/v4/user-from-token'); + return this.httpClient.get(url); + } + updateUser(data: any): Observable { const url = this.getV3Endpoint('/v3/users'); return this.httpClient.put(url, data); diff --git a/src/app/shared/components/project-title/project-title.component.ts b/src/app/shared/components/project-title/project-title.component.ts index b94f9a55..61130dc4 100644 --- a/src/app/shared/components/project-title/project-title.component.ts +++ b/src/app/shared/components/project-title/project-title.component.ts @@ -5,7 +5,7 @@ import { Component, EventEmitter, Output, AfterViewInit } from '@angular/core'; import { AlertService } from '../../services/alert.service'; import { ClaContributorService } from 'src/app/core/services/cla-contributor.service'; import { ProjectModel } from 'src/app/core/models/project'; -import { UserModel } from 'src/app/core/models/user'; +import { UserModel, UserFromTokenModel } from 'src/app/core/models/user'; import { StorageService } from '../../services/storage.service'; import { AppSettings } from 'src/app/config/app-settings'; @@ -20,6 +20,7 @@ export class ProjectTitleComponent implements AfterViewInit { project = new ProjectModel(); user = new UserModel(); + userFromToken = new UserFromTokenModel(); constructor( private alertService: AlertService, @@ -64,6 +65,21 @@ export class ProjectTitleComponent implements AfterViewInit { } } + getUserFromToken() { + this.claContributorService.getUserFromToken().subscribe( + (response) => { + this.userFromToken = response; + this.storageService.setItem(AppSettings.USER_ID, this.userFromToken.userID); + // If we need to store all details in USER then add a helper method to + // copy data from UserFromTokenModel to UserModel + // this.storageService.setItem(AppSettings.USER, convertToUserModel(this.userFromToken)); + }, + (exception) => { + this.errorEmitter.emit(true); + this.claContributorService.handleError(exception); + } + ); + } getUser() { const userId = JSON.parse(this.storageService.getItem(AppSettings.USER_ID)); @@ -84,4 +100,4 @@ export class ProjectTitleComponent implements AfterViewInit { this.alertService.error('There is an invalid user ID in the URL'); } } -} \ No newline at end of file +}