Skip to content

Commit 8792bc7

Browse files
reverted old flow
Signed-off-by: Amol Sontakke <[email protected]>
1 parent 12a7380 commit 8792bc7

File tree

5 files changed

+104
-17
lines changed

5 files changed

+104
-17
lines changed

edge/security-headers.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ function generateCSP(env, isDevServer) {
4343
'https://api.lfcla.dev.platform.linuxfoundation.org/',
4444
'https://easycla.dev.communitybridge.org/',
4545
'https://easycla.lfx.linuxfoundation.org/',
46-
'https://contributor.easycla.lfx.linuxfoundation.org/'
46+
'https://contributor.easycla.lfx.linuxfoundation.org/',
47+
'https://github.com/'
4748
];
4849
let scriptSources = [SELF, UNSAFE_EVAL, UNSAFE_INLINE,
4950
'https://cdn.dev.platform.linuxfoundation.org/lfx-header-v2.js',
@@ -105,7 +106,8 @@ function generateCSP(env, isDevServer) {
105106
'https://linuxfoundation-dev.auth0.com',
106107
'https://linuxfoundation-staging.auth0.com',
107108
'https://linuxfoundation.auth0.com',
108-
'https://sso.linuxfoundation.org/'
109+
'https://sso.linuxfoundation.org/',
110+
'https://github.com/'
109111
],
110112
'child-src': [],
111113
'media-src': [],

src/app/app-routing.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ const routes: Routes = [
2323
pathMatch: 'full',
2424
component: AuthComponent
2525
},
26+
{
27+
path: 'cla/project/:projectId',
28+
pathMatch: 'full',
29+
component: ClaDashboardComponent
30+
},
2631
{
2732
path: 'cla/project/:projectId/user/:userId',
2833
pathMatch: 'full',

src/app/core/models/user.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,33 @@ export class UpdateUserModel {
3434
version: string;
3535
}
3636

37+
export class UserFromTokenModel {
38+
dateCreated: string
39+
dateModified: string
40+
emails: any
41+
lfEmail: string
42+
lfUsername: string
43+
userID: string
44+
username: string
45+
version: string
46+
}
47+
48+
export class UserFromSessionModel {
49+
date_created: string
50+
date_modified: string
51+
lf_email: any
52+
lf_sub: any
53+
lf_username: any
54+
note: any
55+
user_company_id: any
56+
user_emails: string[]
57+
user_external_id: any
58+
user_github_id: string
59+
user_github_username: string
60+
user_gitlab_id: any
61+
user_gitlab_username: any
62+
user_id: string
63+
user_ldap_id: any
64+
user_name: string
65+
version: string
66+
}

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

Lines changed: 11 additions & 1 deletion
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';
@@ -70,6 +70,16 @@ export class ClaContributorService {
7070
return this.httpClient.get<ProjectModel>(url);
7171
}
7272

73+
getUserFromToken(): Observable<UserFromTokenModel> {
74+
const url = this.getV4Endpoint('/v4/user-from-token');
75+
return this.httpClient.get<UserFromTokenModel>(url);
76+
}
77+
78+
getUserFromSession(): Observable<string> {
79+
const url = this.getV2Endpoint('/v2/user-from-session');
80+
return this.httpClient.get<string>(url);
81+
}
82+
7383
getUserActiveSignature(userId: string): Observable<ActiveSignatureModel> {
7484
const url = this.getV2Endpoint('/v2/user/' + userId + '/active-signature');
7585
return this.httpClient.get<ActiveSignatureModel>(url);

src/app/shared/components/project-title/project-title.component.ts

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Component, OnInit, Input, EventEmitter, Output } 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, UserModel } from 'src/app/core/models/user';
99
import { StorageService } from '../../services/storage.service';
1010
import { AppSettings } from 'src/app/config/app-settings';
1111

@@ -19,10 +19,12 @@ export class ProjectTitleComponent implements OnInit {
1919
@Input() userId: string;
2020
@Output() errorEmitter: EventEmitter<any> = new EventEmitter<any>();
2121
@Output() successEmitter: EventEmitter<any> = new EventEmitter<any>();
22+
@Output() setUserIdEmitter: EventEmitter<any> = new EventEmitter<any>();
2223

2324
project = new ProjectModel();
25+
userFromToken = new UserFromTokenModel();
2426
user = new UserModel();
25-
27+
userFromSession = new UserFromSessionModel();
2628
constructor(
2729
private alertService: AlertService,
2830
private storageService: StorageService,
@@ -39,18 +41,12 @@ export class ProjectTitleComponent implements OnInit {
3941
}
4042

4143
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) {
46-
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) {
44+
if (this.projectId ) {
45+
this.getProject();
46+
if (this.userId) {
5347
this.getUser();
48+
} else {
49+
this.getUserFromToken();
5450
}
5551
} else {
5652
this.errorEmitter.emit(true);
@@ -79,7 +75,6 @@ export class ProjectTitleComponent implements OnInit {
7975
}
8076
}
8177

82-
8378
getUser() {
8479
if (this.userId) {
8580
this.claContributorService.getUser(this.userId).subscribe(
@@ -101,6 +96,51 @@ export class ProjectTitleComponent implements OnInit {
10196
}
10297

10398

99+
getUserFromToken() {
100+
this.claContributorService.getUserFromToken().subscribe(
101+
(response) => {
102+
console.log('getUserFromToken response ==>', response)
103+
this.userFromToken = response;
104+
this.storageService.setItem(AppSettings.USER_ID, this.userFromToken.userID);
105+
this.storageService.setItem(AppSettings.USER, this.userFromToken);
106+
this.successEmitter.emit('User');
107+
this.setUserIdEmitter.emit(this.userFromToken.userID);
108+
},
109+
() => {
110+
// If user is not found in token, get user from session
111+
this.getUserFromSession();
112+
}
113+
);
114+
}
115+
116+
getUserFromSession() {
117+
this.claContributorService.getUserFromSession().subscribe(
118+
(response: any) => {
119+
console.log('getUserFromSession response ==>', response)
120+
this.userFromSession = response;
121+
this.storageService.setItem(AppSettings.USER_ID, this.userFromSession.user_id);
122+
this.storageService.setItem(AppSettings.USER, {
123+
dateCreated: this.userFromSession.date_created,
124+
dateModified: this.userFromSession.date_modified,
125+
emails: this.userFromSession.user_emails,
126+
lfEmail: this.userFromSession.lf_email,
127+
lfUsername: this.userFromSession.lf_username,
128+
userID: this.userFromSession.user_id,
129+
username: this.userFromSession.user_name,
130+
version: this.userFromSession.version
131+
});
132+
this.successEmitter.emit('User');
133+
},
134+
(exception) => {
135+
console.log('getUserFromSession exception ==>', exception)
136+
this.errorEmitter.emit(true);
137+
this.alertService.error('An error occurred while retrieving the GitHub user from the session.');
138+
this.claContributorService.handleError(exception);
139+
}
140+
);
141+
}
142+
143+
104144

105145

106146
}

0 commit comments

Comments
 (0)