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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,6 @@
"xmlhttprequest-ssl": "^1.6.3",
"@babel/traverse": "^7.23.2",
"postcss": "^8.4.31"
}
},
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
}
2 changes: 1 addition & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const routes: Routes = [
component: AuthComponent
},
{
path: 'cla/project/:projectId/user/:userId',
path: 'cla/project/:projectId',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not remove the old route which is our default route for almost all flows.
You should add a new route (without uuid) instead and for that route you should call /v2/user-from-session API and when you get user UUID from that API - redirect back to "old" route with that user UUID just returned from api, so:

On cla/project/:projectId call /v2/user-from-session to get user. Get this user's UUID and route to cla/project/:projectId/user/:userId. cc @thakurveerendras @amolsontakke3576 @mlehotskylf

pathMatch: 'full',
component: ClaDashboardComponent
},
Expand Down
3 changes: 0 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -15,8 +14,6 @@ export class AppComponent {
hasExpanded: boolean;
links: any[];

constructor(private lfxHeaderService: LfxHeaderService) {}

onToggled() {
this.hasExpanded = !this.hasExpanded;
}
Expand Down
1 change: 1 addition & 0 deletions src/app/config/app-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
30 changes: 30 additions & 0 deletions src/app/core/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions 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, 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';
Expand Down Expand Up @@ -55,9 +55,14 @@ export class ClaContributorService {
}


getUser(userId: string): Observable<UserModel> {
const url = this.getV2Endpoint('/v2/user/' + userId);
return this.httpClient.get<UserModel>(url);
getUserFromToken(): Observable<UserFromTokenModel> {
const url = this.getV4Endpoint('/v4/user-from-token');
return this.httpClient.get<UserFromTokenModel>(url);
}

getUserFromSession(): Observable<any> {
const url = this.getV2Endpoint('/v2/user-from-session');
return this.httpClient.get<any>(url);
}

updateUser(data: any): Observable<UpdateUserModel> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Copyright The Linux Foundation and each contributor to CommunityBridge.
SPDX-License-Identifier: MIT -->

<app-project-title [projectId]="projectId" [userId]="userId" (successEmitter)="onAPILoad($event)"
<app-project-title [projectId]="projectId" [userId]="userId" (successEmitter)="onAPILoad($event)" (setUserIdEmitter)="setUserId($event)"
(errorEmitter)="hasErrorPresent($event)"></app-project-title>

<div class="container-fluid dashboard-container">
Expand Down Expand Up @@ -55,15 +55,15 @@
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<ng-container>
<app-dashboard-contributor-buttons [type]="corporateContributor"
[hasEnabled]="project.project_ccla_enabled"
[hasEnabled]="project.project_ccla_enabled && !hasError"
(proceedBtnEmitter)="onClickCorporateProceed()">
</app-dashboard-contributor-buttons>
</ng-container>
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
<ng-container>
<app-dashboard-contributor-buttons [type]="individualContributor"
[hasEnabled]="project.project_icla_enabled"
[hasEnabled]="project.project_icla_enabled && !hasError"
(proceedBtnEmitter)="onClickIndividualProceed()">
</app-dashboard-contributor-buttons>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}

Expand All @@ -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));
Expand Down
107 changes: 60 additions & 47 deletions src/app/shared/components/project-title/project-title.component.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
// 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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar here - I think you need to add two new models but don't remove the already exiting one...

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',
templateUrl: './project-title.component.html',
styleUrls: ['./project-title.component.scss']
})
export class ProjectTitleComponent implements OnInit {
@ViewChild('warningModal') warningModal: TemplateRef<any>;

@Input() projectId: string;
@Input() userId: string;
@Output() errorEmitter: EventEmitter<any> = new EventEmitter<any>();
@Output() successEmitter: EventEmitter<any> = new EventEmitter<any>();
@Output() setUserIdEmitter: EventEmitter<any> = new EventEmitter<any>();

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 {
Expand All @@ -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);
}
);
}
}
Loading