Skip to content
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

Lmendoza/9422 email domains interstitial oauth #2387

Merged
merged 6 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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'
Expand All @@ -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) {
Expand All @@ -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))
Expand All @@ -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()
}
Expand Down
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
Expand Up @@ -30,7 +30,6 @@ export class ShareEmailsDomainsComponent {
@Output() finish = new EventEmitter<void>()

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