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: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,5 @@
"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',
path: 'cla/project/:projectId/user/:userId',
pathMatch: 'full',
component: ClaDashboardComponent
},
Expand Down
1 change: 0 additions & 1 deletion src/app/config/app-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
32 changes: 0 additions & 32 deletions src/app/core/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -63,4 +32,3 @@ export class UpdateUserModel {
username: string;
version: string;
}

13 changes: 4 additions & 9 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, 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';
Expand Down Expand Up @@ -55,14 +55,9 @@ export class ClaContributorService {
}


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);
getUser(userId: string): Observable<UserModel> {
const url = this.getV2Endpoint('/v2/user/' + userId);
return this.httpClient.get<UserModel>(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)" (setUserIdEmitter)="setUserId($event)"
<app-project-title [projectId]="projectId" [userId]="userId" (successEmitter)="onAPILoad($event)"
(errorEmitter)="hasErrorPresent($event)"></app-project-title>

<div class="container-fluid dashboard-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
107 changes: 45 additions & 62 deletions src/app/shared/components/project-title/project-title.component.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
// 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',
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 UserFromTokenModel();
userFromSession = new UserFromSessionModel();
user = new UserModel();

constructor(
private alertService: AlertService,
private storageService: StorageService,
private claContributorService: ClaContributorService,
private modalService: NgbModal
) { }

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