Skip to content

Commit

Permalink
Merge pull request #2387 from ORCID/lmendoza/9422-email-domains-inter…
Browse files Browse the repository at this point in the history
…stitial-oauth

Lmendoza/9422 email domains interstitial oauth
leomendoza123 authored Nov 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents a338727 + 0e07c9c commit 7c6c398
Showing 5 changed files with 80 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -86,7 +86,6 @@ export class FormAuthorizeComponent implements OnInit, OnDestroy {
this.loadingTrustedIndividuals = false
this.oauthRequest = userInfo.oauthSession
this.organizationName.emit(this.oauthRequest.clientName)
console.log('this ', this.oauthRequest.clientName)
if (userInfo.loggedIn) {
this.userName = userInfo.displayName
this.orcidUrl = userInfo.effectiveOrcidUrl
28 changes: 25 additions & 3 deletions src/app/authorize/pages/authorize/authorize.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, Inject } from '@angular/core'
import { cloneDeep } from 'lodash'
import { first, take, tap } from 'rxjs/operators'
import { InterstitialsService } from 'src/app/cdk/interstitials/interstitials.service'
import { PlatformInfo, PlatformInfoService } from 'src/app/cdk/platform-info'
import { WINDOW } from 'src/app/cdk/window'
import { UserService } from 'src/app/core'
@@ -24,13 +25,17 @@ export class AuthorizeComponent {
userHasPrivateDomains = false
oauthDomainsInterstitialEnabled: boolean
organizationName: string
domainInterstitialHasBeenViewed: boolean
userIsNotImpersonating: boolean

constructor(
_user: UserService,
private _platformInfo: PlatformInfoService,
private _recordEmails: RecordEmailsService,
private _togglz: TogglzService,
@Inject(WINDOW) private window: Window
private _interstitials: InterstitialsService,
@Inject(WINDOW) private window: Window,
private _userInfo: UserService
) {
_user.getUserSession().subscribe((session) => {
if (session.oauthSession && session.oauthSession.error) {
@@ -45,6 +50,17 @@ export class AuthorizeComponent {
}

ngOnInit() {
this._userInfo.getUserSession().subscribe((userInfo) => {
this.userIsNotImpersonating =
userInfo.userInfo.REAL_USER_ORCID ===
userInfo.userInfo.EFFECTIVE_USER_ORCID
})
this._interstitials
.getInterstitialsViewed('OAUTH_DOMAIN_INTERSTITIAL')
.subscribe((value) => {
return (this.domainInterstitialHasBeenViewed = value)
})

this._togglz
.getStateOf('OAUTH_DOMAINS_INTERSTITIAL')
.pipe(take(1))
@@ -68,14 +84,20 @@ export class AuthorizeComponent {
}

handleRedirect(url: string) {
this.redirectUrl = url

if (
url &&
this.userHasPrivateDomains &&
this.oauthDomainsInterstitialEnabled
this.oauthDomainsInterstitialEnabled &&
!this.domainInterstitialHasBeenViewed &&
this.userIsNotImpersonating
) {
this.redirectUrl = url
this.showAuthorizationComponent = false
this.showInterstital = true
this._interstitials
.setInterstitialsViewed('OAUTH_DOMAIN_INTERSTITIAL')
.subscribe()
} else {
this.finishRedirect()
}
24 changes: 24 additions & 0 deletions src/app/cdk/interstitials/interstitials.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { TestBed } from '@angular/core/testing'

import { InterstitialsService } from './interstitials.service'
import { UserService } from 'src/app/core'

describe('InterstitialsService', () => {
let service: InterstitialsService

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{
provide: UserService,
useValue: {},
},
],
})
service = TestBed.inject(InterstitialsService)
})

it('should be created', () => {
expect(service).toBeTruthy()
})
})
31 changes: 31 additions & 0 deletions src/app/cdk/interstitials/interstitials.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Injectable } from '@angular/core'
import { userInfo } from 'os'
import { map } from 'rxjs/operators'
import { UserService } from 'src/app/core'
type Interstitials = 'OAUTH_DOMAIN_INTERSTITIAL' | 'SIGN_IN_DOMAIN_INTERSTITIAL'

@Injectable({
providedIn: 'root',
})
export class InterstitialsService {
constructor(private _userInfo: UserService) {}

setInterstitialsViewed(interstitial: Interstitials) {
return this._userInfo.getUserSession().pipe(
map((userInfo) => {
const effectiveUser = userInfo.userInfo.EFFECTIVE_USER_ORCID
localStorage.setItem(effectiveUser + '_' + interstitial, 'true')
})
)
}
getInterstitialsViewed(interstitial: Interstitials) {
return this._userInfo.getUserSession().pipe(
map((userInfo) => {
const effectiveUser = userInfo.userInfo.EFFECTIVE_USER_ORCID
return (
localStorage.getItem(effectiveUser + '_' + interstitial) === 'true'
)
})
)
}
}
Original file line number Diff line number Diff line change
@@ -30,7 +30,6 @@ export class ShareEmailsDomainsComponent {
@Output() finish = new EventEmitter<void>()

ngOnInit() {
console.log(this.organizationName)
this.userPrivateDomains = this.getTop3MostRecentPrivateDomains(
this.userEmailsJson
)

0 comments on commit 7c6c398

Please sign in to comment.