-
Notifications
You must be signed in to change notification settings - Fork 9
GitHub Login test #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
GitHub Login test #444
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,5 +139,6 @@ | |
| "xmlhttprequest-ssl": "^1.6.3", | ||
| "@babel/traverse": "^7.23.2", | ||
| "postcss": "^8.4.31" | ||
| } | ||
| }, | ||
| "packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
|
@@ -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); | ||
| } | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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-sessionAPI 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/:projectIdcall/v2/user-from-sessionto get user. Get this user's UUID and route tocla/project/:projectId/user/:userId. cc @thakurveerendras @amolsontakke3576 @mlehotskylf