diff --git a/package.json b/package.json index 95d42662..c95601b9 100644 --- a/package.json +++ b/package.json @@ -139,5 +139,6 @@ "xmlhttprequest-ssl": "^1.6.3", "@babel/traverse": "^7.23.2", "postcss": "^8.4.31" - } + }, + "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72" } diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 688448dc..f79e77fd 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -24,7 +24,7 @@ const routes: Routes = [ component: AuthComponent }, { - path: 'cla/project/:projectId/user/:userId', + path: 'cla/project/:projectId', pathMatch: 'full', component: ClaDashboardComponent }, diff --git a/src/app/app.component.ts b/src/app/app.component.ts index e486c5ed..b53e76a5 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: MIT import { Component } from '@angular/core'; -import { LfxHeaderService } from './shared/services/lfx-header.service'; import { environment } from 'src/environments/environment'; @Component({ @@ -15,8 +14,6 @@ export class AppComponent { hasExpanded: boolean; links: any[]; - constructor(private lfxHeaderService: LfxHeaderService) {} - onToggled() { this.hasExpanded = !this.hasExpanded; } diff --git a/src/app/config/app-settings.ts b/src/app/config/app-settings.ts index 7be02d6a..c9c8c84d 100644 --- a/src/app/config/app-settings.ts +++ b/src/app/config/app-settings.ts @@ -13,6 +13,7 @@ export class AppSettings { public static HAS_GERRIT = 'hasGerrit'; public static PROJECT_NAME = 'projectName'; public static USER = 'user'; + public static USER_FROM_SESSION = 'userFromSession'; public static PROJECT = 'project'; public static USER_ID = 'userId'; public static CONTRACT_TYPE = 'contractType'; diff --git a/src/app/core/models/user.ts b/src/app/core/models/user.ts index 2de97de7..d76e4352 100644 --- a/src/app/core/models/user.ts +++ b/src/app/core/models/user.ts @@ -19,6 +19,36 @@ export class UserModel { version: string; } +export class UserFromTokenModel { + dateCreated: string + dateModified: string + emails: any + lfEmail: string + lfUsername: string + userID: string + username: string + version: string + } + + export class UserFromSessionModel { + date_created: string + date_modified: string + lf_email: any + lf_sub: any + lf_username: any + note: any + user_company_id: any + user_emails: string[] + user_external_id: any + user_github_id: string + user_github_username: string + user_gitlab_id: any + user_gitlab_username: any + user_id: string + user_ldap_id: any + user_name: string + version: string + } export class UpdateUserModel { companyID: string; diff --git a/src/app/core/services/cla-contributor.service.ts b/src/app/core/services/cla-contributor.service.ts index 6e63b725..bf9986e2 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, UserFromTokenModel, UserModel} 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'; @@ -55,9 +55,14 @@ export class ClaContributorService { } - getUser(userId: string): Observable { - const url = this.getV2Endpoint('/v2/user/' + userId); - return this.httpClient.get(url); + getUserFromToken(): Observable { + const url = this.getV4Endpoint('/v4/user-from-token'); + return this.httpClient.get(url); + } + + getUserFromSession(): Observable { + const url = this.getV2Endpoint('/v2/user-from-session'); + return this.httpClient.get(url); } updateUser(data: any): Observable { diff --git a/src/app/modules/dashboard/container/cla-dashboard/cla-dashboard.component.html b/src/app/modules/dashboard/container/cla-dashboard/cla-dashboard.component.html index 3f13cb41..43bd5feb 100644 --- a/src/app/modules/dashboard/container/cla-dashboard/cla-dashboard.component.html +++ b/src/app/modules/dashboard/container/cla-dashboard/cla-dashboard.component.html @@ -1,7 +1,7 @@ -
@@ -55,7 +55,7 @@
@@ -63,7 +63,7 @@
diff --git a/src/app/modules/dashboard/container/cla-dashboard/cla-dashboard.component.ts b/src/app/modules/dashboard/container/cla-dashboard/cla-dashboard.component.ts index 7d296093..7296f762 100644 --- a/src/app/modules/dashboard/container/cla-dashboard/cla-dashboard.component.ts +++ b/src/app/modules/dashboard/container/cla-dashboard/cla-dashboard.component.ts @@ -61,9 +61,11 @@ export class ClaDashboardComponent implements OnInit { this.alertService.error('The Corporate CLA option is not enabled for this project. Please contact to your administrator to enable the Corporate CLA option for this project.'); return false; } - if (!this.hasError) { + if (!this.hasError && this.userId) { const url = '/corporate-dashboard/' + this.projectId + '/' + this.userId; this.router.navigate([url]); + }else { + this.alertService.error('Unable to fetch user ID.'); } } @@ -72,12 +74,18 @@ export class ClaDashboardComponent implements OnInit { this.alertService.error('The Individual CLA option is not enabled for this project. Please to your administrator to enable the Individual CLA option for this project.'); return false; } - if (!this.hasError) { + if (!this.hasError && this.userId) { const url = '/individual-dashboard/' + this.projectId + '/' + this.userId; this.router.navigate([url]); + }else { + this.alertService.error('Unable to fetch user ID.'); } } + setUserId(userId: string) { + this.userId = userId; + } + onAPILoad(APIType: string) { if (APIType === 'Project') { this.project = JSON.parse(this.storageService.getItem(AppSettings.PROJECT)); 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 79cb1d1e..22ebb427 100644 --- a/src/app/shared/components/project-title/project-title.component.ts +++ b/src/app/shared/components/project-title/project-title.component.ts @@ -1,13 +1,14 @@ // Copyright The Linux Foundation and each contributor to CommunityBridge. // SPDX-License-Identifier: MIT -import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core'; +import { Component, OnInit, Input, EventEmitter, Output, ViewChild, TemplateRef } 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 { UserFromSessionModel, UserFromTokenModel } from 'src/app/core/models/user'; import { StorageService } from '../../services/storage.service'; import { AppSettings } from 'src/app/config/app-settings'; +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'app-project-title', @@ -15,18 +16,24 @@ import { AppSettings } from 'src/app/config/app-settings'; styleUrls: ['./project-title.component.scss'] }) export class ProjectTitleComponent implements OnInit { + @ViewChild('warningModal') warningModal: TemplateRef; + @Input() projectId: string; @Input() userId: string; @Output() errorEmitter: EventEmitter = new EventEmitter(); @Output() successEmitter: EventEmitter = new EventEmitter(); + @Output() setUserIdEmitter: EventEmitter = new EventEmitter(); + message: string; + redirectUrl: string; project = new ProjectModel(); - user = new UserModel(); - + user = new UserFromTokenModel(); + userFromSession = new UserFromSessionModel(); constructor( private alertService: AlertService, private storageService: StorageService, private claContributorService: ClaContributorService, + private modalService: NgbModal ) { } ngOnInit(): void { @@ -39,68 +46,74 @@ export class ProjectTitleComponent implements OnInit { } validateGithubFlow() { - if (this.projectId && this.userId) { - const localProjectId = JSON.parse(this.storageService.getItem(AppSettings.PROJECT_ID)); - const localUserId = JSON.parse(this.storageService.getItem(AppSettings.USER_ID)); - if (localProjectId !== this.projectId) { + if (this.projectId) { this.getProject(); - } else { - this.successEmitter.emit('Project'); - this.project.project_name = JSON.parse(this.storageService.getItem(AppSettings.PROJECT_NAME)); - } - - if (localUserId !== this.userId) { this.getUser(); - } } else { this.errorEmitter.emit(true); - this.alertService.error('Invalid project id and user id in URL'); + this.alertService.error('Invalid project id in URL'); } } getProject() { - if (this.projectId) { - this.claContributorService.getProject(this.projectId).subscribe( - (response) => { - this.project = response; - this.storageService.setItem(AppSettings.PROJECT_NAME, this.project.project_name); - this.storageService.setItem(AppSettings.PROJECT_ID, this.projectId); - this.storageService.setItem(AppSettings.PROJECT, this.project); - this.successEmitter.emit('Project'); - }, - (exception) => { - this.errorEmitter.emit(true); - this.claContributorService.handleError(exception); - } - ); - } else { - this.errorEmitter.emit(true); - this.alertService.error('Invalid project id in URL'); - } + console.log(this.projectId) + this.claContributorService.getProject(this.projectId).subscribe( + (response) => { + this.project = response; + this.storageService.setItem(AppSettings.PROJECT_NAME, this.project.project_name); + this.storageService.setItem(AppSettings.PROJECT_ID, this.projectId); + this.storageService.setItem(AppSettings.PROJECT, this.project); + this.successEmitter.emit('Project'); + }, + (exception) => { + this.errorEmitter.emit(true); + this.claContributorService.handleError(exception); + } + ); } getUser() { - if (this.userId) { - this.claContributorService.getUser(this.userId).subscribe( + this.claContributorService.getUserFromToken().subscribe( (response) => { + console.log('getUserFromToken response ==>', response) this.user = response; - this.storageService.setItem(AppSettings.USER_ID, this.userId); + this.storageService.setItem(AppSettings.USER_ID, this.user.userID); this.storageService.setItem(AppSettings.USER, this.user); this.successEmitter.emit('User'); + this.setUserIdEmitter.emit(this.user.userID); }, - (exception) => { - this.errorEmitter.emit(true); - this.claContributorService.handleError(exception); + () => { + // If user is not found in token, get user from session + this.getUserFromSession(); } ); - } else { - this.errorEmitter.emit(true); - this.alertService.error('Invalid user id in URL'); - } } - - - + getUserFromSession() { + this.claContributorService.getUserFromSession().subscribe( + (response: any) => { + console.log('getUserFromSession response ==>', response) + this.userFromSession = response; + this.storageService.setItem(AppSettings.USER_ID, this.userFromSession.user_id); + this.storageService.setItem(AppSettings.USER, { + dateCreated: this.userFromSession.date_created, + dateModified: this.userFromSession.date_modified, + emails: this.userFromSession.user_emails, + lfEmail: this.userFromSession.lf_email, + lfUsername: this.userFromSession.lf_username, + userID: this.userFromSession.user_id, + username: this.userFromSession.user_name, + version: this.userFromSession.version + }); + this.successEmitter.emit('User'); + }, + (exception) => { + console.log('getUserFromSession exception ==>', exception) + this.errorEmitter.emit(true); + this.alertService.error('An error occurred while retrieving the GitHub user from the session.'); + this.claContributorService.handleError(exception); + } + ); + } }