forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
115279: Replaced EndUserAgreeMent guards with functional guards
- Loading branch information
1 parent
ffe3062
commit 553bada
Showing
8 changed files
with
152 additions
and
147 deletions.
There are no files selected for viewing
This file contains 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
45 changes: 0 additions & 45 deletions
45
src/app/core/end-user-agreement/abstract-end-user-agreement.guard.ts
This file was deleted.
Oops, something went wrong.
This file contains 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
38 changes: 14 additions & 24 deletions
38
src/app/core/end-user-agreement/end-user-agreement-cookie.guard.ts
This file contains 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,29 +1,19 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { | ||
Observable, | ||
of as observableOf, | ||
} from 'rxjs'; | ||
import { inject } from '@angular/core'; | ||
import { CanActivateFn } from '@angular/router'; | ||
import { of as observableOf } from 'rxjs'; | ||
|
||
import { AbstractEndUserAgreementGuard } from './abstract-end-user-agreement.guard'; | ||
import { endUserAgreementGuard } from './end-user-agreement.guard'; | ||
import { EndUserAgreementService } from './end-user-agreement.service'; | ||
|
||
|
||
/** | ||
* A guard redirecting users to the end agreement page when the user agreement cookie hasn't been accepted | ||
* Guard for preventing unauthorized access to certain pages | ||
* requiring the end user agreement to have been accepted in a cookie | ||
*/ | ||
@Injectable({ providedIn: 'root' }) | ||
export class EndUserAgreementCookieGuard extends AbstractEndUserAgreementGuard { | ||
|
||
constructor(protected endUserAgreementService: EndUserAgreementService, | ||
protected router: Router) { | ||
super(router); | ||
} | ||
|
||
/** | ||
* True when the user agreement cookie has been accepted | ||
*/ | ||
hasAccepted(): Observable<boolean> { | ||
return observableOf(this.endUserAgreementService.isCookieAccepted()); | ||
} | ||
|
||
} | ||
export const endUserAgreementCookieGuard: CanActivateFn = | ||
endUserAgreementGuard( | ||
() => { | ||
const endUserAgreementService = inject(EndUserAgreementService); | ||
return observableOf(endUserAgreementService.isCookieAccepted()); | ||
}, | ||
); |
Oops, something went wrong.