Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/app/core/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/app/core/services/cla-contributor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -60,6 +60,11 @@ export class ClaContributorService {
return this.httpClient.get<UserModel>(url);
}

getUserFromToken(): Observable<UserFromTokenModel> {
const url = this.getV4Endpoint('/v4/user-from-token');
return this.httpClient.get<UserFromTokenModel>(url);
}

updateUser(data: any): Observable<UpdateUserModel> {
const url = this.getV3Endpoint('/v3/users');
return this.httpClient.put<UpdateUserModel>(url, data);
Expand Down
20 changes: 18 additions & 2 deletions src/app/shared/components/project-title/project-title.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

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

project = new ProjectModel();
user = new UserModel();
userFromToken = new UserFromTokenModel();

constructor(
private alertService: AlertService,
Expand Down Expand Up @@ -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));
Expand All @@ -84,4 +100,4 @@ export class ProjectTitleComponent implements AfterViewInit {
this.alertService.error('There is an invalid user ID in the URL');
}
}
}
}
Loading