Skip to content

Commit a2b1561

Browse files
Merge pull request #444 from communitybridge/feature/github-login
GitHub Login test
2 parents 864b085 + 1fd97c1 commit a2b1561

File tree

9 files changed

+116
-61
lines changed

9 files changed

+116
-61
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,6 @@
139139
"xmlhttprequest-ssl": "^1.6.3",
140140
"@babel/traverse": "^7.23.2",
141141
"postcss": "^8.4.31"
142-
}
142+
},
143+
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
143144
}

src/app/app-routing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const routes: Routes = [
2424
component: AuthComponent
2525
},
2626
{
27-
path: 'cla/project/:projectId/user/:userId',
27+
path: 'cla/project/:projectId',
2828
pathMatch: 'full',
2929
component: ClaDashboardComponent
3030
},

src/app/app.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: MIT
33

44
import { Component } from '@angular/core';
5-
import { LfxHeaderService } from './shared/services/lfx-header.service';
65
import { environment } from 'src/environments/environment';
76

87
@Component({
@@ -15,8 +14,6 @@ export class AppComponent {
1514
hasExpanded: boolean;
1615
links: any[];
1716

18-
constructor(private lfxHeaderService: LfxHeaderService) {}
19-
2017
onToggled() {
2118
this.hasExpanded = !this.hasExpanded;
2219
}

src/app/config/app-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class AppSettings {
1313
public static HAS_GERRIT = 'hasGerrit';
1414
public static PROJECT_NAME = 'projectName';
1515
public static USER = 'user';
16+
public static USER_FROM_SESSION = 'userFromSession';
1617
public static PROJECT = 'project';
1718
public static USER_ID = 'userId';
1819
public static CONTRACT_TYPE = 'contractType';

src/app/core/models/user.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,36 @@ export class UserModel {
1919
version: string;
2020
}
2121

22+
export class UserFromTokenModel {
23+
dateCreated: string
24+
dateModified: string
25+
emails: any
26+
lfEmail: string
27+
lfUsername: string
28+
userID: string
29+
username: string
30+
version: string
31+
}
32+
33+
export class UserFromSessionModel {
34+
date_created: string
35+
date_modified: string
36+
lf_email: any
37+
lf_sub: any
38+
lf_username: any
39+
note: any
40+
user_company_id: any
41+
user_emails: string[]
42+
user_external_id: any
43+
user_github_id: string
44+
user_github_username: string
45+
user_gitlab_id: any
46+
user_gitlab_username: any
47+
user_id: string
48+
user_ldap_id: any
49+
user_name: string
50+
version: string
51+
}
2252

2353
export class UpdateUserModel {
2454
companyID: string;

src/app/core/services/cla-contributor.service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Injectable, isDevMode} from '@angular/core';
55
import {HttpClient} from '@angular/common/http';
66
import {Observable, Subject} from 'rxjs';
77
import {Project, ProjectModel} from '../models/project';
8-
import {UpdateUserModel, UserModel} from '../models/user';
8+
import {UpdateUserModel, UserFromTokenModel, UserModel} from '../models/user';
99
import {AlertService} from 'src/app/shared/services/alert.service';
1010
import {ActiveSignatureModel} from '../models/active-signature';
1111
import {IndividualRequestSignatureModel} from '../models/individual-request-signature';
@@ -55,9 +55,14 @@ export class ClaContributorService {
5555
}
5656

5757

58-
getUser(userId: string): Observable<UserModel> {
59-
const url = this.getV2Endpoint('/v2/user/' + userId);
60-
return this.httpClient.get<UserModel>(url);
58+
getUserFromToken(): Observable<UserFromTokenModel> {
59+
const url = this.getV4Endpoint('/v4/user-from-token');
60+
return this.httpClient.get<UserFromTokenModel>(url);
61+
}
62+
63+
getUserFromSession(): Observable<any> {
64+
const url = this.getV2Endpoint('/v2/user-from-session');
65+
return this.httpClient.get<any>(url);
6166
}
6267

6368
updateUser(data: any): Observable<UpdateUserModel> {

src/app/modules/dashboard/container/cla-dashboard/cla-dashboard.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!-- Copyright The Linux Foundation and each contributor to CommunityBridge.
22
SPDX-License-Identifier: MIT -->
33

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

77
<div class="container-fluid dashboard-container">
@@ -55,15 +55,15 @@
5555
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
5656
<ng-container>
5757
<app-dashboard-contributor-buttons [type]="corporateContributor"
58-
[hasEnabled]="project.project_ccla_enabled"
58+
[hasEnabled]="project.project_ccla_enabled && !hasError"
5959
(proceedBtnEmitter)="onClickCorporateProceed()">
6060
</app-dashboard-contributor-buttons>
6161
</ng-container>
6262
</div>
6363
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
6464
<ng-container>
6565
<app-dashboard-contributor-buttons [type]="individualContributor"
66-
[hasEnabled]="project.project_icla_enabled"
66+
[hasEnabled]="project.project_icla_enabled && !hasError"
6767
(proceedBtnEmitter)="onClickIndividualProceed()">
6868
</app-dashboard-contributor-buttons>
6969
</ng-container>

src/app/modules/dashboard/container/cla-dashboard/cla-dashboard.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ export class ClaDashboardComponent implements OnInit {
6161
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.');
6262
return false;
6363
}
64-
if (!this.hasError) {
64+
if (!this.hasError && this.userId) {
6565
const url = '/corporate-dashboard/' + this.projectId + '/' + this.userId;
6666
this.router.navigate([url]);
67+
}else {
68+
this.alertService.error('Unable to fetch user ID.');
6769
}
6870
}
6971

@@ -72,12 +74,18 @@ export class ClaDashboardComponent implements OnInit {
7274
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.');
7375
return false;
7476
}
75-
if (!this.hasError) {
77+
if (!this.hasError && this.userId) {
7678
const url = '/individual-dashboard/' + this.projectId + '/' + this.userId;
7779
this.router.navigate([url]);
80+
}else {
81+
this.alertService.error('Unable to fetch user ID.');
7882
}
7983
}
8084

85+
setUserId(userId: string) {
86+
this.userId = userId;
87+
}
88+
8189
onAPILoad(APIType: string) {
8290
if (APIType === 'Project') {
8391
this.project = JSON.parse(this.storageService.getItem(AppSettings.PROJECT));
Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
11
// Copyright The Linux Foundation and each contributor to CommunityBridge.
22
// SPDX-License-Identifier: MIT
33

4-
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
4+
import { Component, OnInit, Input, EventEmitter, Output, ViewChild, TemplateRef } from '@angular/core';
55
import { AlertService } from '../../services/alert.service';
66
import { ClaContributorService } from 'src/app/core/services/cla-contributor.service';
77
import { ProjectModel } from 'src/app/core/models/project';
8-
import { UserModel } from 'src/app/core/models/user';
8+
import { UserFromSessionModel, UserFromTokenModel } from 'src/app/core/models/user';
99
import { StorageService } from '../../services/storage.service';
1010
import { AppSettings } from 'src/app/config/app-settings';
11+
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
1112

1213
@Component({
1314
selector: 'app-project-title',
1415
templateUrl: './project-title.component.html',
1516
styleUrls: ['./project-title.component.scss']
1617
})
1718
export class ProjectTitleComponent implements OnInit {
19+
@ViewChild('warningModal') warningModal: TemplateRef<any>;
20+
1821
@Input() projectId: string;
1922
@Input() userId: string;
2023
@Output() errorEmitter: EventEmitter<any> = new EventEmitter<any>();
2124
@Output() successEmitter: EventEmitter<any> = new EventEmitter<any>();
25+
@Output() setUserIdEmitter: EventEmitter<any> = new EventEmitter<any>();
2226

27+
message: string;
28+
redirectUrl: string;
2329
project = new ProjectModel();
24-
user = new UserModel();
25-
30+
user = new UserFromTokenModel();
31+
userFromSession = new UserFromSessionModel();
2632
constructor(
2733
private alertService: AlertService,
2834
private storageService: StorageService,
2935
private claContributorService: ClaContributorService,
36+
private modalService: NgbModal
3037
) { }
3138

3239
ngOnInit(): void {
@@ -39,68 +46,74 @@ export class ProjectTitleComponent implements OnInit {
3946
}
4047

4148
validateGithubFlow() {
42-
if (this.projectId && this.userId) {
43-
const localProjectId = JSON.parse(this.storageService.getItem(AppSettings.PROJECT_ID));
44-
const localUserId = JSON.parse(this.storageService.getItem(AppSettings.USER_ID));
45-
if (localProjectId !== this.projectId) {
49+
if (this.projectId) {
4650
this.getProject();
47-
} else {
48-
this.successEmitter.emit('Project');
49-
this.project.project_name = JSON.parse(this.storageService.getItem(AppSettings.PROJECT_NAME));
50-
}
51-
52-
if (localUserId !== this.userId) {
5351
this.getUser();
54-
}
5552
} else {
5653
this.errorEmitter.emit(true);
57-
this.alertService.error('Invalid project id and user id in URL');
54+
this.alertService.error('Invalid project id in URL');
5855
}
5956
}
6057

6158
getProject() {
62-
if (this.projectId) {
63-
this.claContributorService.getProject(this.projectId).subscribe(
64-
(response) => {
65-
this.project = response;
66-
this.storageService.setItem(AppSettings.PROJECT_NAME, this.project.project_name);
67-
this.storageService.setItem(AppSettings.PROJECT_ID, this.projectId);
68-
this.storageService.setItem(AppSettings.PROJECT, this.project);
69-
this.successEmitter.emit('Project');
70-
},
71-
(exception) => {
72-
this.errorEmitter.emit(true);
73-
this.claContributorService.handleError(exception);
74-
}
75-
);
76-
} else {
77-
this.errorEmitter.emit(true);
78-
this.alertService.error('Invalid project id in URL');
79-
}
59+
console.log(this.projectId)
60+
this.claContributorService.getProject(this.projectId).subscribe(
61+
(response) => {
62+
this.project = response;
63+
this.storageService.setItem(AppSettings.PROJECT_NAME, this.project.project_name);
64+
this.storageService.setItem(AppSettings.PROJECT_ID, this.projectId);
65+
this.storageService.setItem(AppSettings.PROJECT, this.project);
66+
this.successEmitter.emit('Project');
67+
},
68+
(exception) => {
69+
this.errorEmitter.emit(true);
70+
this.claContributorService.handleError(exception);
71+
}
72+
);
8073
}
8174

8275

8376
getUser() {
84-
if (this.userId) {
85-
this.claContributorService.getUser(this.userId).subscribe(
77+
this.claContributorService.getUserFromToken().subscribe(
8678
(response) => {
79+
console.log('getUserFromToken response ==>', response)
8780
this.user = response;
88-
this.storageService.setItem(AppSettings.USER_ID, this.userId);
81+
this.storageService.setItem(AppSettings.USER_ID, this.user.userID);
8982
this.storageService.setItem(AppSettings.USER, this.user);
9083
this.successEmitter.emit('User');
84+
this.setUserIdEmitter.emit(this.user.userID);
9185
},
92-
(exception) => {
93-
this.errorEmitter.emit(true);
94-
this.claContributorService.handleError(exception);
86+
() => {
87+
// If user is not found in token, get user from session
88+
this.getUserFromSession();
9589
}
9690
);
97-
} else {
98-
this.errorEmitter.emit(true);
99-
this.alertService.error('Invalid user id in URL');
100-
}
10191
}
10292

103-
104-
105-
93+
getUserFromSession() {
94+
this.claContributorService.getUserFromSession().subscribe(
95+
(response: any) => {
96+
console.log('getUserFromSession response ==>', response)
97+
this.userFromSession = response;
98+
this.storageService.setItem(AppSettings.USER_ID, this.userFromSession.user_id);
99+
this.storageService.setItem(AppSettings.USER, {
100+
dateCreated: this.userFromSession.date_created,
101+
dateModified: this.userFromSession.date_modified,
102+
emails: this.userFromSession.user_emails,
103+
lfEmail: this.userFromSession.lf_email,
104+
lfUsername: this.userFromSession.lf_username,
105+
userID: this.userFromSession.user_id,
106+
username: this.userFromSession.user_name,
107+
version: this.userFromSession.version
108+
});
109+
this.successEmitter.emit('User');
110+
},
111+
(exception) => {
112+
console.log('getUserFromSession exception ==>', exception)
113+
this.errorEmitter.emit(true);
114+
this.alertService.error('An error occurred while retrieving the GitHub user from the session.');
115+
this.claContributorService.handleError(exception);
116+
}
117+
);
118+
}
106119
}

0 commit comments

Comments
 (0)