diff --git a/src/app/authorize/components/form-authorize/form-authorize.component.ts b/src/app/authorize/components/form-authorize/form-authorize.component.ts index fb6c91e50..e64cc57cd 100644 --- a/src/app/authorize/components/form-authorize/form-authorize.component.ts +++ b/src/app/authorize/components/form-authorize/form-authorize.component.ts @@ -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 diff --git a/src/app/authorize/pages/authorize/authorize.component.ts b/src/app/authorize/pages/authorize/authorize.component.ts index 77cd7ada3..c127b6a0a 100644 --- a/src/app/authorize/pages/authorize/authorize.component.ts +++ b/src/app/authorize/pages/authorize/authorize.component.ts @@ -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() } diff --git a/src/app/cdk/interstitials/interstitials.service.spec.ts b/src/app/cdk/interstitials/interstitials.service.spec.ts new file mode 100644 index 000000000..a626b60b8 --- /dev/null +++ b/src/app/cdk/interstitials/interstitials.service.spec.ts @@ -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() + }) +}) diff --git a/src/app/cdk/interstitials/interstitials.service.ts b/src/app/cdk/interstitials/interstitials.service.ts new file mode 100644 index 000000000..831f4ff16 --- /dev/null +++ b/src/app/cdk/interstitials/interstitials.service.ts @@ -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' + ) + }) + ) + } +} diff --git a/src/app/cdk/interstitials/share-emails-domains/share-emails-domains.component.ts b/src/app/cdk/interstitials/share-emails-domains/share-emails-domains.component.ts index 6678b9712..5f8245ec1 100644 --- a/src/app/cdk/interstitials/share-emails-domains/share-emails-domains.component.ts +++ b/src/app/cdk/interstitials/share-emails-domains/share-emails-domains.component.ts @@ -30,7 +30,6 @@ export class ShareEmailsDomainsComponent { @Output() finish = new EventEmitter() ngOnInit() { - console.log(this.organizationName) this.userPrivateDomains = this.getTop3MostRecentPrivateDomains( this.userEmailsJson )