diff --git a/package.json b/package.json index c95601b9..95d42662 100644 --- a/package.json +++ b/package.json @@ -139,6 +139,5 @@ "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 f79e77fd..688448dc 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', + path: 'cla/project/:projectId/user/:userId', pathMatch: 'full', component: ClaDashboardComponent }, diff --git a/src/app/config/app-settings.ts b/src/app/config/app-settings.ts index c9c8c84d..7be02d6a 100644 --- a/src/app/config/app-settings.ts +++ b/src/app/config/app-settings.ts @@ -13,7 +13,6 @@ 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 d76e4352..cfe62b4d 100644 --- a/src/app/core/models/user.ts +++ b/src/app/core/models/user.ts @@ -19,37 +19,6 @@ 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; dateCreated: Date; @@ -63,4 +32,3 @@ export class UpdateUserModel { username: string; version: string; } - diff --git a/src/app/core/services/cla-contributor.service.ts b/src/app/core/services/cla-contributor.service.ts index bf9986e2..6e63b725 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, UserFromTokenModel, UserModel} from '../models/user'; +import {UpdateUserModel, 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,14 +55,9 @@ export class ClaContributorService { } - 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); + getUser(userId: string): Observable { + const url = this.getV2Endpoint('/v2/user/' + userId); + 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 43bd5feb..b82713aa 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 @@ -
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 7296f762..54cb16ab 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 @@ -82,10 +82,6 @@ export class ClaDashboardComponent implements OnInit { } } - 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 22ebb427..39e4c02a 100644 --- a/src/app/shared/components/project-title/project-title.component.ts +++ b/src/app/shared/components/project-title/project-title.component.ts @@ -1,14 +1,13 @@ // Copyright The Linux Foundation and each contributor to CommunityBridge. // SPDX-License-Identifier: MIT -import { Component, OnInit, Input, EventEmitter, Output, ViewChild, TemplateRef } from '@angular/core'; +import { Component, OnInit, Input, EventEmitter, Output } 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 { UserFromSessionModel, UserFromTokenModel } from 'src/app/core/models/user'; +import { UserModel } 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', @@ -16,24 +15,18 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; 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 UserFromTokenModel(); - userFromSession = new UserFromSessionModel(); + user = new UserModel(); + constructor( private alertService: AlertService, private storageService: StorageService, private claContributorService: ClaContributorService, - private modalService: NgbModal ) { } ngOnInit(): void { @@ -46,74 +39,64 @@ export class ProjectTitleComponent implements OnInit { } validateGithubFlow() { - if (this.projectId) { + 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) { 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 in URL'); + this.alertService.error('Invalid project id and user id in URL'); } } getProject() { - 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); - } - ); + 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'); + } } getUser() { - this.claContributorService.getUserFromToken().subscribe( + if (this.userId) { + this.claContributorService.getUser(this.userId).subscribe( (response) => { - console.log('getUserFromToken response ==>', response) this.user = response; - this.storageService.setItem(AppSettings.USER_ID, this.user.userID); + this.storageService.setItem(AppSettings.USER_ID, this.userId); this.storageService.setItem(AppSettings.USER, this.user); this.successEmitter.emit('User'); - this.setUserIdEmitter.emit(this.user.userID); }, - () => { - // If user is not found in token, get user from session - this.getUserFromSession(); + (exception) => { + this.errorEmitter.emit(true); + this.claContributorService.handleError(exception); } ); + } 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); - } - ); - } -} +} \ No newline at end of file