From 1d97855f5f7fd42eb0da828c0c1ea725be45e507 Mon Sep 17 00:00:00 2001 From: Amol Sontakke Date: Tue, 24 Jun 2025 13:10:23 +0530 Subject: [PATCH 1/4] feat: added lf login Signed-off-by: Amol Sontakke --- package.json | 3 +- src/app/app-routing.module.ts | 9 +- src/app/app.component.ts | 15 ++ src/app/app.module.ts | 2 +- .../configure-cla-manager-modal.component.ts | 1 - .../cla-request-authorization.component.html | 2 +- .../corporate-dashboard.component.html | 5 - .../auth-dashboard.component.html | 1 + .../auth-dashboard.component.scss | 0 .../auth-dashboard.component.spec.ts | 25 +++ .../auth-dashboard.component.ts | 23 +++ .../cla-dashboard.component.html | 16 +- .../cla-dashboard/cla-dashboard.component.ts | 69 +++++-- src/app/modules/dashboard/dashboard.module.ts | 4 +- .../individual-dashboard.component.html | 2 +- .../components/auth/auth.component.html | 8 - .../components/auth/auth.component.scss | 11 - .../components/auth/auth.component.spec.ts | 28 --- .../shared/components/auth/auth.component.ts | 191 ------------------ .../page-not-found.component.html | 2 +- .../page-not-found.component.ts | 16 +- .../project-title/project-title.component.ts | 51 ++--- src/app/shared/services/auth.service.ts | 57 +----- src/app/shared/shared.module.ts | 2 - 24 files changed, 160 insertions(+), 383 deletions(-) create mode 100644 src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.html create mode 100644 src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.scss create mode 100644 src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts create mode 100644 src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts delete mode 100644 src/app/shared/components/auth/auth.component.html delete mode 100644 src/app/shared/components/auth/auth.component.scss delete mode 100644 src/app/shared/components/auth/auth.component.spec.ts delete mode 100644 src/app/shared/components/auth/auth.component.ts diff --git a/package.json b/package.json index 95d42662..c95601b9 100644 --- a/package.json +++ b/package.json @@ -139,5 +139,6 @@ "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 688448dc..b3ca54cd 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -9,19 +9,14 @@ import { IndividualDashboardComponent } from './modules/individual-contributor/c import { CorporateDashboardComponent } from './modules/corporate-contributor/container/corporate-dashboard/corporate-dashboard.component'; import { ClaRequestAuthorizationComponent } from './modules/corporate-contributor/container/cla-request-authorization/cla-request-authorization.component'; import { GerritDashboardComponent } from './modules/dashboard/container/gerrit-dashboard/gerrit-dashboard.component'; -import { AuthComponent } from './shared/components/auth/auth.component'; +import { AuthDashboardComponent } from './modules/dashboard/container/auth-dashboard/auth-dashboard.component'; const routes: Routes = [ { path: '', pathMatch: 'full', - redirectTo: '/cla' - }, - { - path: 'auth', - pathMatch: 'full', - component: AuthComponent + component: AuthDashboardComponent }, { path: 'cla/project/:projectId/user/:userId', diff --git a/src/app/app.component.ts b/src/app/app.component.ts index b53e76a5..ac164037 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,6 +3,8 @@ import { Component } from '@angular/core'; import { environment } from 'src/environments/environment'; +import { AuthService } from './shared/services/auth.service'; +import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-root', @@ -14,6 +16,8 @@ export class AppComponent { hasExpanded: boolean; links: any[]; + constructor(private auth:AuthService, private route: ActivatedRoute){} + onToggled() { this.hasExpanded = !this.hasExpanded; } @@ -21,6 +25,7 @@ export class AppComponent { ngOnInit() { this.mountHeader(); this.hasExpanded = true; + console.log(this.isIncognito()) } private mountHeader(): void { @@ -29,4 +34,14 @@ export class AppComponent { script.setAttribute('async', 'true'); document.head.appendChild(script); } + + private isIncognito():boolean { + try { + localStorage.setItem('test', 'test'); + localStorage.removeItem('test'); + return false; // If no error, likely not incognito + } catch (e) { + return true; // If an error occurs, likely incognito + } + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6337c554..247cb9cd 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -32,7 +32,7 @@ import { InterceptorService } from './shared/services/interceptor.service'; DashboardModule, IndividualContributorModule, CorporateContributorModule, - FormsModule + FormsModule, ], providers: [ { diff --git a/src/app/modules/corporate-contributor/component/configure-cla-manager-modal/configure-cla-manager-modal.component.ts b/src/app/modules/corporate-contributor/component/configure-cla-manager-modal/configure-cla-manager-modal.component.ts index 54792b15..2621d19d 100644 --- a/src/app/modules/corporate-contributor/component/configure-cla-manager-modal/configure-cla-manager-modal.component.ts +++ b/src/app/modules/corporate-contributor/component/configure-cla-manager-modal/configure-cla-manager-modal.component.ts @@ -282,7 +282,6 @@ export class ConfigureClaManagerModalComponent implements OnInit { this.modalService.dismissAll(); this.loaderService.show(); const corporateUrl = this.claContributorService.getLFXCorporateURL(); - console.log('corporateURL: ', corporateUrl); if (corporateUrl !== '') { this.storageService.removeItem(AppSettings.ACTION_TYPE); window.open(corporateUrl, '_self'); diff --git a/src/app/modules/corporate-contributor/container/cla-request-authorization/cla-request-authorization.component.html b/src/app/modules/corporate-contributor/container/cla-request-authorization/cla-request-authorization.component.html index b0eca13f..5dd54cc9 100644 --- a/src/app/modules/corporate-contributor/container/cla-request-authorization/cla-request-authorization.component.html +++ b/src/app/modules/corporate-contributor/container/cla-request-authorization/cla-request-authorization.component.html @@ -1,7 +1,7 @@ - +
diff --git a/src/app/modules/corporate-contributor/container/corporate-dashboard/corporate-dashboard.component.html b/src/app/modules/corporate-contributor/container/corporate-dashboard/corporate-dashboard.component.html index f3bf7125..2a74f88e 100644 --- a/src/app/modules/corporate-contributor/container/corporate-dashboard/corporate-dashboard.component.html +++ b/src/app/modules/corporate-contributor/container/corporate-dashboard/corporate-dashboard.component.html @@ -1,11 +1,6 @@ - -
diff --git a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.html b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.html new file mode 100644 index 00000000..8d83eefe --- /dev/null +++ b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.html @@ -0,0 +1 @@ +

auth-dashboard works!

diff --git a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.scss b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.scss new file mode 100644 index 00000000..e69de29b diff --git a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts new file mode 100644 index 00000000..a4ddb146 --- /dev/null +++ b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AuthDashboardComponent } from './auth-dashboard.component'; + +describe('AuthDashboardComponent', () => { + let component: AuthDashboardComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ AuthDashboardComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(AuthDashboardComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts new file mode 100644 index 00000000..f867fe5b --- /dev/null +++ b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts @@ -0,0 +1,23 @@ +import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { AppSettings } from 'src/app/config/app-settings'; +import { StorageService } from 'src/app/shared/services/storage.service'; + +@Component({ + selector: 'app-auth-dashboard', + templateUrl: './auth-dashboard.component.html', + styleUrls: ['./auth-dashboard.component.scss'] +}) +export class AuthDashboardComponent implements OnInit { + + constructor(private router:Router, private storageService:StorageService) { } + + ngOnInit(): void { + const projectId = JSON.parse(this.storageService.getItem(AppSettings.PROJECT_ID)); + const userId = JSON.parse(this.storageService.getItem(AppSettings.USER_ID)); + const redirectUrl = JSON.parse(this.storageService.getItem(AppSettings.REDIRECT)); + + this.router.navigate([`/cla/project/${projectId}/user/${userId}`], { queryParams: { redirect:redirectUrl, loggedIn: true} }) + } + +} 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 b82713aa..4073c9e3 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,10 +1,8 @@ - -
+
@@ -18,12 +16,12 @@
-
-
@@ -32,7 +30,7 @@
-
@@ -41,7 +39,7 @@
-
@@ -55,7 +53,7 @@
@@ -63,7 +61,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 54cb16ab..bc33d271 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 @@ -8,6 +8,7 @@ import { StorageService } from 'src/app/shared/services/storage.service'; import { AlertService } from 'src/app/shared/services/alert.service'; import { AppSettings } from 'src/app/config/app-settings'; import { ClaContributorService } from 'src/app/core/services/cla-contributor.service'; +import { AuthService } from 'src/app/shared/services/auth.service'; @Component({ selector: 'app-cla-dashboard', @@ -17,8 +18,8 @@ import { ClaContributorService } from 'src/app/core/services/cla-contributor.ser export class ClaDashboardComponent implements OnInit { projectId: string; userId: string; - corporateHightlights: string[]; - individualHightlights: string[]; + corporateHightLights: string[]; + individualHightLights: string[]; corporateContributor = 'Corporate Contributor'; individualContributor = 'Individual Contributor'; exitEasyCLA = 'exitEasyCLA'; @@ -30,29 +31,62 @@ export class ClaDashboardComponent implements OnInit { private router: Router, private storageService: StorageService, private alertService: AlertService, - private claContributorService: ClaContributorService + private claContributorService: ClaContributorService, + private authService:AuthService ) { - this.storageService.removeGerritItems(); - this.storageService.setItem(AppSettings.HAS_GERRIT, false); - this.projectId = this.route.snapshot.paramMap.get('projectId'); - this.userId = this.route.snapshot.paramMap.get('userId'); - const redirect = this.route.snapshot.queryParamMap.get('redirect'); - this.storageService.setItem(AppSettings.REDIRECT, redirect); - this.hasErrorPresent(); - } - ngOnInit(): void { - this.corporateHightlights = [ + this.corporateHightLights = [ 'If you are making a contribution of content owned by your employer, you should proceed as a corporate contributor.', 'The Corporate CLA process requires you to be approved by your organization\'s CLA Manager. A CLA Manager at your organization will receive your request via email immediately after you submit it. To expedite the process, you can follow up with them directly.', 'If your organization has not yet signed a CLA for this project, you will be able to coordinate designating a CLA Manager and having the CLA signed by someone at your organization who is authorized to sign.', 'If your organization is not registered, then you can optionally create a profile for your organization during the CLA authorization process.' ]; - this.individualHightlights = [ + this.individualHightLights = [ 'If you are making a contribution of content that you own, and not content owned by your employer, you should proceed as an individual contributor.', 'If you are in doubt whether your contribution is owned by you or your employer, you should check with your employer or an attorney.' ]; + } + + ngOnInit(): void { + this.storageService.removeItem(AppSettings.PROJECT) + this.storageService.removeGerritItems(); + this.storageService.setItem(AppSettings.HAS_GERRIT, false); + this.projectId = this.route.snapshot.paramMap.get('projectId'); + this.userId = this.route.snapshot.paramMap.get('userId'); + const redirect = this.route.snapshot.queryParamMap.get('redirect'); + const loggedIn = this.route.snapshot.queryParamMap.get('loggedIn'); + + + this.project = JSON.parse(this.storageService.getItem(AppSettings.PROJECT)); + this.storageService.setItem(AppSettings.REDIRECT, redirect); + this.storageService.setItem(AppSettings.PROJECT_ID, this.route.snapshot.paramMap.get('projectId')); + this.storageService.setItem(AppSettings.USER_ID, this.route.snapshot.paramMap.get('userId')); + + this.hasErrorPresent(); + + this.authService.loading$.subscribe((loading) => { + if (!loading) { + this.authService.isAuthenticated$.subscribe((authenticated) => { + console.log(authenticated, loggedIn); + if (!authenticated) { + this.authService.login(); + } + }); + } + }); + } + + public get hasCclaEnabled():boolean{ + return this.project?.project_ccla_enabled && !this.hasError; + } + + public get hasIclaEnabled():boolean{ + return this.project?.project_icla_enabled && !this.hasError; + } + + setProject(project){ + this.project = project; } @@ -82,13 +116,6 @@ export class ClaDashboardComponent implements OnInit { } } - onAPILoad(APIType: string) { - if (APIType === 'Project') { - this.project = JSON.parse(this.storageService.getItem(AppSettings.PROJECT)); - } - } - - onExitEasyCLA() { const redirectUrl = JSON.parse(this.storageService.getItem(AppSettings.REDIRECT)); if (redirectUrl !== null) { diff --git a/src/app/modules/dashboard/dashboard.module.ts b/src/app/modules/dashboard/dashboard.module.ts index 2f0151b8..be6f2c76 100644 --- a/src/app/modules/dashboard/dashboard.module.ts +++ b/src/app/modules/dashboard/dashboard.module.ts @@ -8,12 +8,14 @@ import {DashboardContributorCardComponent} from './component/dashboard-contribut import {SharedModule} from 'src/app/shared/shared.module'; import {DashboardContributorButtonsComponent} from './component/dashboard-contributor-buttons/dashboard-contributor-buttons.component'; import {GerritDashboardComponent} from './container/gerrit-dashboard/gerrit-dashboard.component'; +import { AuthDashboardComponent } from './container/auth-dashboard/auth-dashboard.component'; @NgModule({ declarations: [ClaDashboardComponent, DashboardContributorCardComponent, DashboardContributorButtonsComponent, - GerritDashboardComponent + GerritDashboardComponent, + AuthDashboardComponent ], imports: [ CommonModule, diff --git a/src/app/modules/individual-contributor/container/individual-dashboard/individual-dashboard.component.html b/src/app/modules/individual-contributor/container/individual-dashboard/individual-dashboard.component.html index 55f00fff..05640278 100644 --- a/src/app/modules/individual-contributor/container/individual-dashboard/individual-dashboard.component.html +++ b/src/app/modules/individual-contributor/container/individual-dashboard/individual-dashboard.component.html @@ -1,7 +1,7 @@ - +
diff --git a/src/app/shared/components/auth/auth.component.html b/src/app/shared/components/auth/auth.component.html deleted file mode 100644 index d48c54ba..00000000 --- a/src/app/shared/components/auth/auth.component.html +++ /dev/null @@ -1,8 +0,0 @@ - - -
-
-
{{message}}
-
-
diff --git a/src/app/shared/components/auth/auth.component.scss b/src/app/shared/components/auth/auth.component.scss deleted file mode 100644 index 8134a7f8..00000000 --- a/src/app/shared/components/auth/auth.component.scss +++ /dev/null @@ -1,11 +0,0 @@ -/* Copyright The Linux Foundation and each contributor to CommunityBridge. - SPDX-License-Identifier: MIT -->*/ - .row { - height: calc(100vh - 262px) !important; - .not-found { - font-size: 18px; - text-align: center; - font-weight: bold; - } - } - \ No newline at end of file diff --git a/src/app/shared/components/auth/auth.component.spec.ts b/src/app/shared/components/auth/auth.component.spec.ts deleted file mode 100644 index 6a2bbc81..00000000 --- a/src/app/shared/components/auth/auth.component.spec.ts +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright The Linux Foundation and each contributor to CommunityBridge. -// SPDX-License-Identifier: MIT - -import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; - -import { AuthComponent } from './auth.component'; - -describe('AuthComponent', () => { - let component: AuthComponent; - let fixture: ComponentFixture; - - beforeEach(waitForAsync(() => { - TestBed.configureTestingModule({ - declarations: [ AuthComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(AuthComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/shared/components/auth/auth.component.ts b/src/app/shared/components/auth/auth.component.ts deleted file mode 100644 index dd0fa887..00000000 --- a/src/app/shared/components/auth/auth.component.ts +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright The Linux Foundation and each contributor to CommunityBridge. -// SPDX-License-Identifier: MIT - -import { Component, OnInit } from '@angular/core'; -import { Router } from '@angular/router'; -import { AppSettings } from 'src/app/config/app-settings'; -import { GerritUserModel } from 'src/app/core/models/gerrit'; -import { ProjectModel } from 'src/app/core/models/project'; -import { ClaContributorService } from 'src/app/core/services/cla-contributor.service'; -import { AlertService } from '../../services/alert.service'; -import { AuthService } from '../../services/auth.service'; -import { StorageService } from '../../services/storage.service'; - -@Component({ - selector: 'app-auth', - templateUrl: './auth.component.html', - styleUrls: ['./auth.component.scss'], -}) -export class AuthComponent implements OnInit { - message: string; - contractType: string; - projectId: string; - hasGerrit: string; - userId: string; - actionType: string; - previousURL: string; - - constructor( - private storageService: StorageService, - private router: Router, - private claContributorService: ClaContributorService, - private alertService: AlertService, - private authService: AuthService - ) {} - - ngOnInit(): void { - this.contractType = JSON.parse( - this.storageService.getItem(AppSettings.CONTRACT_TYPE) - ); - this.hasGerrit = JSON.parse( - this.storageService.getItem(AppSettings.HAS_GERRIT) - ); - this.actionType = JSON.parse( - this.storageService.getItem(AppSettings.ACTION_TYPE) - ); - this.projectId = JSON.parse( - this.storageService.getItem(AppSettings.PROJECT_ID) - ); - this.userId = JSON.parse(this.storageService.getItem(AppSettings.USER_ID)); - this.previousURL = decodeURIComponent(window.location.hash.split('=')[1]); - - this.setMessage(); - - this.authService.loading$.subscribe((loading) => { - if (!loading) { - this.authService.isAuthenticated$.subscribe((authenticated) => { - console.log(authenticated); - if (authenticated) { - this.handleRedirection(); - } else { - // this.authService.login(); - } - }); - } - }); - } - - handleRedirection() { - this.performActionAsPerType(); - } - - setMessage() { - if (this.actionType === AppSettings.SIGN_CLA) { - this.message = - 'Wait... You are being redirected to the Configure CLA Manager.'; - return; - } - - if (this.hasGerrit) { - this.message = - 'You are being redirected to the ' + - this.contractType + - ' contributor console.'; - return; - } - - this.message = 'Wait... we are loading the screen'; - } - - performActionAsPerType() { - if (this.actionType === AppSettings.SIGN_CLA) { - const url = '/corporate-dashboard/' + this.projectId + '/' + this.userId; - this.router.navigate([url], { - queryParams: { view: AppSettings.SIGN_CLA }, - }); - return; - } - - if (this.hasGerrit) { - this.getGerritProjectInfo(); - this.getUserInfo(); - return; - } - - if (this.previousURL !== undefined && this.previousURL !== 'undefined') { - this.router.navigateByUrl(this.previousURL); - return; - } else { - // Redirect to landing page. - const redirectUrl = JSON.parse( - this.storageService.getItem(AppSettings.REDIRECT) - ); - this.router.navigate( - ['/cla/project/' + this.projectId + '/user/' + this.userId], - { queryParams: { redirect: redirectUrl } } - ); - } - - // *todo: handle default case - } - - getUserInfo() { - this.claContributorService.getGerritUserInfo().subscribe( - (response: GerritUserModel) => { - this.userId = response.user_id; - this.storageService.setItem(AppSettings.USER_ID, response.user_id); - this.storageService.setItem(AppSettings.USER, response); - this.redirectForGerritFlow(); - }, - (exception) => { - this.message = - 'Failed to redirect on a ' + this.contractType + ' console.'; - this.alertService.error(exception.error); - } - ); - } - - // No need to call update endpoint. - // updateUserInfo() { - // const autData = JSON.parse(this.storageService.getItem(AppSettings.AUTH_DATA)); - // const user: UserModel = JSON.parse(this.storageService.getItem(AppSettings.USER)); - // const data = { - // lfEmail: autData.user_email, - // lfUsername: autData.userid, //LF username is actually userId in the auth service/EasyCLA. - // githubUsername: user.user_github_username, - // githubID: user.user_github_id - // } - // this.claContributorService.updateUser(data).subscribe( - // (response: UpdateUserModel) => { - // // Update new values in local storage. - // user.lf_username = response.lfUsername; - // user.lf_email = response.lfEmail; - // this.storageService.setItem(AppSettings.USER, user); - // this.performActionAsPerType(); - // }, - // (exception) => { - // this.alertService.error(exception.error.Message); - // this.message = 'Error occured during updating user info. Please contact to your administrator.'; - // } - // ); - // } - - getGerritProjectInfo() { - this.claContributorService.getGerritProjectInfo(this.projectId).subscribe( - (response: ProjectModel) => { - this.storageService.setItem( - AppSettings.PROJECT_NAME, - response.project_name - ); - this.storageService.setItem(AppSettings.PROJECT, response); - }, - (exception) => { - this.message = - 'Failed to redirect on a ' + this.contractType + ' console.'; - this.claContributorService.handleError(exception); - } - ); - } - - redirectForGerritFlow() { - if (this.contractType === 'individual') { - const url = '/individual-dashboard/' + this.projectId + '/' + this.userId; - this.router.navigate([url]); - } else if (this.contractType === 'corporate') { - const url = '/corporate-dashboard/' + this.projectId + '/' + this.userId; - this.router.navigate([url]); - } else { - this.message = 'Contract type is invalid.'; - } - } -} diff --git a/src/app/shared/components/page-not-found/page-not-found.component.html b/src/app/shared/components/page-not-found/page-not-found.component.html index 617223e9..95fc168d 100644 --- a/src/app/shared/components/page-not-found/page-not-found.component.html +++ b/src/app/shared/components/page-not-found/page-not-found.component.html @@ -3,7 +3,7 @@
-
{{message}}
+
The page you are looking for was not found.
diff --git a/src/app/shared/components/page-not-found/page-not-found.component.ts b/src/app/shared/components/page-not-found/page-not-found.component.ts index bbfc1cda..23902522 100644 --- a/src/app/shared/components/page-not-found/page-not-found.component.ts +++ b/src/app/shared/components/page-not-found/page-not-found.component.ts @@ -2,6 +2,8 @@ // SPDX-License-Identifier: MIT import { Component, OnInit } from '@angular/core'; +import { StorageService } from '../../services/storage.service'; +import { AppSettings } from 'src/app/config/app-settings'; @Component({ selector: 'app-page-not-found', @@ -10,17 +12,13 @@ import { Component, OnInit } from '@angular/core'; }) export class PageNotFoundComponent implements OnInit { - message: string; - actionType: string; + redirectUrl:string; - constructor( - ) { } + constructor(private storageService:StorageService){ + + } ngOnInit(): void { - this.message = 'Wait... we are validating session'; - // If auth0 response is null then page not exist. - setTimeout(() => { - this.message = 'The page you are looking for was not found.'; - }, 2000); + this.redirectUrl = JSON.parse(this.storageService.getItem(AppSettings.REDIRECT)); } } 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 39e4c02a..b94f9a55 100644 --- a/src/app/shared/components/project-title/project-title.component.ts +++ b/src/app/shared/components/project-title/project-title.component.ts @@ -1,7 +1,7 @@ // Copyright The Linux Foundation and each contributor to CommunityBridge. // SPDX-License-Identifier: MIT -import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core'; +import { Component, EventEmitter, Output, AfterViewInit } 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'; @@ -14,9 +14,7 @@ import { AppSettings } from 'src/app/config/app-settings'; templateUrl: './project-title.component.html', styleUrls: ['./project-title.component.scss'] }) -export class ProjectTitleComponent implements OnInit { - @Input() projectId: string; - @Input() userId: string; +export class ProjectTitleComponent implements AfterViewInit { @Output() errorEmitter: EventEmitter = new EventEmitter(); @Output() successEmitter: EventEmitter = new EventEmitter(); @@ -27,9 +25,10 @@ export class ProjectTitleComponent implements OnInit { private alertService: AlertService, private storageService: StorageService, private claContributorService: ClaContributorService, - ) { } + ) { + } - ngOnInit(): void { + ngAfterViewInit(): void { const hasGerrit = JSON.parse(this.storageService.getItem(AppSettings.HAS_GERRIT)); if (hasGerrit) { this.project.project_name = JSON.parse(this.storageService.getItem(AppSettings.PROJECT_NAME)); @@ -39,34 +38,20 @@ 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) { - 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.getProject(); } getProject() { - if (this.projectId) { - this.claContributorService.getProject(this.projectId).subscribe( + const projectId = JSON.parse(this.storageService.getItem(AppSettings.PROJECT_ID)); + if (projectId) { + this.claContributorService.getProject(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_ID, projectId); this.storageService.setItem(AppSettings.PROJECT, this.project); - this.successEmitter.emit('Project'); + this.successEmitter.emit(response); + this.getUser(); }, (exception) => { this.errorEmitter.emit(true); @@ -75,19 +60,19 @@ export class ProjectTitleComponent implements OnInit { ); } else { this.errorEmitter.emit(true); - this.alertService.error('Invalid project id in URL'); + this.alertService.error('There is an invalid project ID in the URL'); } } getUser() { - if (this.userId) { - this.claContributorService.getUser(this.userId).subscribe( + const userId = JSON.parse(this.storageService.getItem(AppSettings.USER_ID)); + if (userId) { + this.claContributorService.getUser(userId).subscribe( (response) => { this.user = response; - this.storageService.setItem(AppSettings.USER_ID, this.userId); + this.storageService.setItem(AppSettings.USER_ID, userId); this.storageService.setItem(AppSettings.USER, this.user); - this.successEmitter.emit('User'); }, (exception) => { this.errorEmitter.emit(true); @@ -96,7 +81,7 @@ export class ProjectTitleComponent implements OnInit { ); } else { this.errorEmitter.emit(true); - this.alertService.error('Invalid user id in URL'); + this.alertService.error('There is an invalid user ID in the URL'); } } } \ No newline at end of file diff --git a/src/app/shared/services/auth.service.ts b/src/app/shared/services/auth.service.ts index cf07914f..49a637ab 100644 --- a/src/app/shared/services/auth.service.ts +++ b/src/app/shared/services/auth.service.ts @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT import { Injectable } from '@angular/core'; -import { BehaviorSubject, combineLatest, from, Observable, of, throwError } from 'rxjs'; +import { BehaviorSubject, from, Observable, of, throwError } from 'rxjs'; import createAuth0Client from '@auth0/auth0-spa-js'; import Auth0Client from '@auth0/auth0-spa-js/dist/typings/Auth0Client'; import { catchError, concatMap, shareReplay, tap } from 'rxjs/operators'; @@ -79,16 +79,6 @@ export class AuthService { } async initializeApplication() { - // On initial load, check authentication state with authorization server - // Set up local auth streams if user is already authenticated - // const params = this.currentHref; - // console.log(params) - // if (params.includes('code=') && params.includes('state=')) { - // console.log('Auth0 code and state are found.'); - // this.handleAuthCallback(); - // return; - // } - await this.localAuthSetup(); this.handlerReturnToAfterLogout(); } @@ -135,7 +125,7 @@ export class AuthService { if (button) { button.click(); } - }, 1500); + }, 500); } logout() { @@ -154,8 +144,9 @@ export class AuthService { client_id: this.auth0Options.clientId, returnTo: `${window.location.origin}${searchPart}${fragmentPart}`, }; - this.auth0Client$.subscribe((client: Auth0Client) => - client.logout(request) + this.auth0Client$.subscribe((client: Auth0Client) =>{ + client.logout(request); + } ); } @@ -270,44 +261,6 @@ export class AuthService { return pathname || '/'; } - private handleAuthCallback() { - // Call when app reloads after user logs in with Auth0 - const params = this.currentHref; - - if (params.includes('code=') && params.includes('state=')) { - let targetRoute = ''; // Path to redirect to after login processsed - const authComplete$ = this.handleRedirectCallback$.pipe( - // Have client, now call method to handle auth callback redirect - tap((cbRes: any) => { - targetRoute = this.getTargetRouteFromAppState(cbRes.appState); - }), - concatMap(() => combineLatest([this.getUser$(), this.isAuthenticated$])), - catchError((err) => { - console.log('Error occured while getting Auth0 data ', { err }); - this.checkUserSessionByCookie(); - return of('invalid_state'); - }) - ); - // Subscribe to authentication completion observable - // Response will be an array of user and login status - authComplete$.subscribe((message: any) => { - this.loading$.next(false); - if (message === 'invalid_state') { - console.log('triggering login by invali_state '); - this.login(); - return; - } - - if (!targetRoute) { - return this.router.navigateByUrl('/auth'); - } - const url = '/auth?targetRoute=' + (targetRoute || ''); - this.router.navigateByUrl(url); - }); - } - } - - /* Extra method added */ private setSession(authResult): void { const sessionData = { diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index c952477a..a2e19c17 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -15,7 +15,6 @@ import { CheckboxComponent } from './components/checkbox/checkbox.component'; import { AuthService } from './services/auth.service'; import { LfxHeaderService } from './services/lfx-header.service'; import { InterceptorService } from './services/interceptor.service'; -import { AuthComponent } from './components/auth/auth.component'; import { FooterComponent } from './components/footer/footer.component'; import { ConsentComponent } from './components/consent/consent.component'; import { CommonModule } from '@angular/common'; @@ -31,7 +30,6 @@ import { CommonModule } from '@angular/common'; ProjectTitleComponent, TrimCharactersPipe, CheckboxComponent, - AuthComponent, FooterComponent, ConsentComponent ], From 63de69f6331854f42c3476011c30da8ca709d755 Mon Sep 17 00:00:00 2001 From: Amol Sontakke Date: Tue, 24 Jun 2025 19:12:29 +0530 Subject: [PATCH 2/4] fix: login issue for private window Signed-off-by: Amol Sontakke --- package.json | 5 +++-- src/app/app.component.ts | 11 ----------- .../auth-dashboard/auth-dashboard.component.ts | 2 +- .../cla-dashboard/cla-dashboard.component.html | 3 +-- .../cla-dashboard/cla-dashboard.component.ts | 15 +++++++++++---- .../shared/components/alert/alert.component.scss | 1 - .../page-not-found/page-not-found.component.html | 3 ++- src/app/shared/services/auth.service.ts | 10 ---------- yarn.lock | 5 +++++ 9 files changed, 23 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index c95601b9..d4e42dcf 100644 --- a/package.json +++ b/package.json @@ -54,13 +54,14 @@ "@angular/router": "~11.2.14", "@auth0/auth0-angular": "1.5.1", "@fortawesome/fontawesome-free": "^6.4.0", + "@linuxfoundation/lfx-ui-core": "^0.0.12", "@ng-bootstrap/ng-bootstrap": "^6.1.0", "@silvermine/serverless-plugin-cloudfront-lambda-edge": "^2.1.1", - "@linuxfoundation/lfx-ui-core": "^0.0.12", - "aws-sdk": "2.1558.0", "@types/node": "^18.16.0", "auth0-spa-js": "^1.6.5", + "aws-sdk": "2.1558.0", "bootstrap": "^4.4.0", + "detectincognitojs": "^1.5.0", "file-saver": "^2.0.5", "query-string": "^6.13.8", "rxjs": "~6.6.3", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index ac164037..d158a2a2 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -25,7 +25,6 @@ export class AppComponent { ngOnInit() { this.mountHeader(); this.hasExpanded = true; - console.log(this.isIncognito()) } private mountHeader(): void { @@ -34,14 +33,4 @@ export class AppComponent { script.setAttribute('async', 'true'); document.head.appendChild(script); } - - private isIncognito():boolean { - try { - localStorage.setItem('test', 'test'); - localStorage.removeItem('test'); - return false; // If no error, likely not incognito - } catch (e) { - return true; // If an error occurs, likely incognito - } - } } diff --git a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts index f867fe5b..aa2ba4f6 100644 --- a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts +++ b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts @@ -17,7 +17,7 @@ export class AuthDashboardComponent implements OnInit { const userId = JSON.parse(this.storageService.getItem(AppSettings.USER_ID)); const redirectUrl = JSON.parse(this.storageService.getItem(AppSettings.REDIRECT)); - this.router.navigate([`/cla/project/${projectId}/user/${userId}`], { queryParams: { redirect:redirectUrl, loggedIn: true} }) + this.router.navigate([`/cla/project/${projectId}/user/${userId}`], { queryParams: { redirect:redirectUrl} }) } } 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 4073c9e3..b97822e7 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,9 +1,8 @@ +
- -
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 bc33d271..cfb47a37 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 @@ -9,6 +9,7 @@ import { AlertService } from 'src/app/shared/services/alert.service'; import { AppSettings } from 'src/app/config/app-settings'; import { ClaContributorService } from 'src/app/core/services/cla-contributor.service'; import { AuthService } from 'src/app/shared/services/auth.service'; +import detectIncognito from 'detectincognitojs'; @Component({ selector: 'app-cla-dashboard', @@ -24,8 +25,10 @@ export class ClaDashboardComponent implements OnInit { individualContributor = 'Individual Contributor'; exitEasyCLA = 'exitEasyCLA'; hasError: boolean; + hasPrivateWindow: boolean; project = new ProjectModel(); + constructor( private route: ActivatedRoute, private router: Router, @@ -55,8 +58,6 @@ export class ClaDashboardComponent implements OnInit { this.projectId = this.route.snapshot.paramMap.get('projectId'); this.userId = this.route.snapshot.paramMap.get('userId'); const redirect = this.route.snapshot.queryParamMap.get('redirect'); - const loggedIn = this.route.snapshot.queryParamMap.get('loggedIn'); - this.project = JSON.parse(this.storageService.getItem(AppSettings.PROJECT)); this.storageService.setItem(AppSettings.REDIRECT, redirect); @@ -65,11 +66,17 @@ export class ClaDashboardComponent implements OnInit { this.hasErrorPresent(); + detectIncognito().then((result) => { + this.hasPrivateWindow = result.isPrivate; + if(this.hasPrivateWindow){ + this.alertService.error('There are some features that will not work in a private window, as this site requires cookies'); + } + }); + this.authService.loading$.subscribe((loading) => { if (!loading) { this.authService.isAuthenticated$.subscribe((authenticated) => { - console.log(authenticated, loggedIn); - if (!authenticated) { + if (!authenticated && !this.hasPrivateWindow) { this.authService.login(); } }); diff --git a/src/app/shared/components/alert/alert.component.scss b/src/app/shared/components/alert/alert.component.scss index d1f632eb..ba15b9cd 100644 --- a/src/app/shared/components/alert/alert.component.scss +++ b/src/app/shared/components/alert/alert.component.scss @@ -3,7 +3,6 @@ .alert { left: 0; - position: fixed; width: 100%; z-index: 1000; } diff --git a/src/app/shared/components/page-not-found/page-not-found.component.html b/src/app/shared/components/page-not-found/page-not-found.component.html index 95fc168d..40d053d6 100644 --- a/src/app/shared/components/page-not-found/page-not-found.component.html +++ b/src/app/shared/components/page-not-found/page-not-found.component.html @@ -3,7 +3,8 @@
-
The page you are looking for was not found.
+
The page you are looking for was not found. Please click here + to go back on main page or contact the administrator.
diff --git a/src/app/shared/services/auth.service.ts b/src/app/shared/services/auth.service.ts index 49a637ab..2787f816 100644 --- a/src/app/shared/services/auth.service.ts +++ b/src/app/shared/services/auth.service.ts @@ -237,16 +237,6 @@ export class AuthService { return ''; } - private getTargetRouteFromAppState(appState) { - if (!appState) { - return '/'; - } - const { returnTo, target, targetUrl } = appState; - return ( - this.getTargetRouteFromReturnTo(returnTo) || target || targetUrl || '/' - ); - } - private getTargetRouteFromReturnTo(returnTo) { if (!returnTo) { return ''; diff --git a/yarn.lock b/yarn.lock index 46f3b87b..f1140ea4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4214,6 +4214,11 @@ detect-node@^2.0.4: resolved "https://registry.yarnpkg.com/detect-node/-/detect-node-2.1.0.tgz#c9c70775a49c3d03bc2c06d9a73be550f978f8b1" integrity sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g== +detectincognitojs@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/detectincognitojs/-/detectincognitojs-1.5.0.tgz#0f2691d601ed3437a8bfaa0f1fde0dfdab67e2b4" + integrity sha512-O4tgjDp41GnOYZNMVK0XhSeMQN7AGHez2Wz+tVf4VO0Zkn3isAxADjZBwGvL1BRw4ueNEQ6x+1gBHrWElXoBqA== + dezalgo@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/dezalgo/-/dezalgo-1.0.4.tgz#751235260469084c132157dfa857f386d4c33d81" From 59167d0e31b571c15f0bd593c5abb468450b293a Mon Sep 17 00:00:00 2001 From: Amol Sontakke Date: Tue, 24 Jun 2025 21:36:37 +0530 Subject: [PATCH 3/4] fix: remove unwanted file Signed-off-by: Amol Sontakke --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index d4e42dcf..f54ce13c 100644 --- a/package.json +++ b/package.json @@ -140,6 +140,5 @@ "xmlhttprequest-ssl": "^1.6.3", "@babel/traverse": "^7.23.2", "postcss": "^8.4.31" - }, - "packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72" + } } From d63807a8f9da399746b1303ab60109d2122fff21 Mon Sep 17 00:00:00 2001 From: Amol Sontakke Date: Tue, 24 Jun 2025 21:39:52 +0530 Subject: [PATCH 4/4] fix: added missing header Signed-off-by: Amol Sontakke --- .../container/auth-dashboard/auth-dashboard.component.html | 3 ++- .../container/auth-dashboard/auth-dashboard.component.scss | 2 ++ .../container/auth-dashboard/auth-dashboard.component.spec.ts | 3 +++ .../container/auth-dashboard/auth-dashboard.component.ts | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.html b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.html index 8d83eefe..5836313c 100644 --- a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.html +++ b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.html @@ -1 +1,2 @@ -

auth-dashboard works!

+ \ No newline at end of file diff --git a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.scss b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.scss index e69de29b..1be1bdcc 100644 --- a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.scss +++ b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.scss @@ -0,0 +1,2 @@ +/* Copyright The Linux Foundation and each contributor to CommunityBridge. + SPDX-License-Identifier: MIT */ \ No newline at end of file diff --git a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts index a4ddb146..b3551d6d 100644 --- a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts +++ b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.spec.ts @@ -1,3 +1,6 @@ +// Copyright The Linux Foundation and each contributor to CommunityBridge. +// SPDX-License-Identifier: MIT + import { ComponentFixture, TestBed } from '@angular/core/testing'; import { AuthDashboardComponent } from './auth-dashboard.component'; diff --git a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts index aa2ba4f6..ee62333c 100644 --- a/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts +++ b/src/app/modules/dashboard/container/auth-dashboard/auth-dashboard.component.ts @@ -1,3 +1,6 @@ +// Copyright The Linux Foundation and each contributor to CommunityBridge. +// SPDX-License-Identifier: MIT + import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { AppSettings } from 'src/app/config/app-settings';