Skip to content

Commit 8a0f6bc

Browse files
Merge pull request #452 from communitybridge/unicron-add-user-from-token-endpoint
Add support for /v4/user-from-token in FE - to be connected where needed later
2 parents c9d98d8 + b710378 commit 8a0f6bc

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

src/app/core/models/user.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,27 @@ export class UserModel {
1919
version: string;
2020
}
2121

22+
export class UserFromTokenModel {
23+
userID: string;
24+
userExternalID?: string;
25+
username?: string;
26+
dateCreated?: string | Date;
27+
dateModified?: string | Date;
28+
lfEmail?: string;
29+
lfUsername?: string;
30+
companyID?: string;
31+
githubID?: string;
32+
githubUsername?: string;
33+
gitlabID?: string;
34+
gitlabUsername?: string;
35+
admin?: boolean;
36+
version?: string;
37+
note?: string;
38+
emails?: string[];
39+
userCompanyID?: string;
40+
isSanctioned?: boolean;
41+
}
42+
2243
export class UpdateUserModel {
2344
companyID: string;
2445
dateCreated: Date;

src/app/core/services/cla-contributor.service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Injectable, isDevMode} from '@angular/core';
55
import {HttpClient} from '@angular/common/http';
66
import {Observable, Subject} from 'rxjs';
77
import {Project, ProjectModel} from '../models/project';
8-
import {UpdateUserModel, UserModel} from '../models/user';
8+
import {UpdateUserModel, UserModel, UserFromTokenModel} from '../models/user';
99
import {AlertService} from 'src/app/shared/services/alert.service';
1010
import {ActiveSignatureModel} from '../models/active-signature';
1111
import {IndividualRequestSignatureModel} from '../models/individual-request-signature';
@@ -60,6 +60,11 @@ export class ClaContributorService {
6060
return this.httpClient.get<UserModel>(url);
6161
}
6262

63+
getUserFromToken(): Observable<UserFromTokenModel> {
64+
const url = this.getV4Endpoint('/v4/user-from-token');
65+
return this.httpClient.get<UserFromTokenModel>(url);
66+
}
67+
6368
updateUser(data: any): Observable<UpdateUserModel> {
6469
const url = this.getV3Endpoint('/v3/users');
6570
return this.httpClient.put<UpdateUserModel>(url, data);

src/app/shared/components/project-title/project-title.component.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Component, EventEmitter, Output, AfterViewInit } from '@angular/core';
55
import { AlertService } from '../../services/alert.service';
66
import { ClaContributorService } from 'src/app/core/services/cla-contributor.service';
77
import { ProjectModel } from 'src/app/core/models/project';
8-
import { UserModel } from 'src/app/core/models/user';
8+
import { UserModel, UserFromTokenModel } from 'src/app/core/models/user';
99
import { StorageService } from '../../services/storage.service';
1010
import { AppSettings } from 'src/app/config/app-settings';
1111

@@ -20,6 +20,7 @@ export class ProjectTitleComponent implements AfterViewInit {
2020

2121
project = new ProjectModel();
2222
user = new UserModel();
23+
userFromToken = new UserFromTokenModel();
2324

2425
constructor(
2526
private alertService: AlertService,
@@ -64,6 +65,21 @@ export class ProjectTitleComponent implements AfterViewInit {
6465
}
6566
}
6667

68+
getUserFromToken() {
69+
this.claContributorService.getUserFromToken().subscribe(
70+
(response) => {
71+
this.userFromToken = response;
72+
this.storageService.setItem(AppSettings.USER_ID, this.userFromToken.userID);
73+
// If we need to store all details in USER then add a helper method to
74+
// copy data from UserFromTokenModel to UserModel
75+
// this.storageService.setItem(AppSettings.USER, convertToUserModel(this.userFromToken));
76+
},
77+
(exception) => {
78+
this.errorEmitter.emit(true);
79+
this.claContributorService.handleError(exception);
80+
}
81+
);
82+
}
6783

6884
getUser() {
6985
const userId = JSON.parse(this.storageService.getItem(AppSettings.USER_ID));
@@ -84,4 +100,4 @@ export class ProjectTitleComponent implements AfterViewInit {
84100
this.alertService.error('There is an invalid user ID in the URL');
85101
}
86102
}
87-
}
103+
}

0 commit comments

Comments
 (0)