-
Notifications
You must be signed in to change notification settings - Fork 508
Request-a-copy improvements: Support access by secure link #3984
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
Changes from all commits
aea41d7
f3bb732
4281267
0de6481
60bbcf3
0c58a5b
e736bbb
585347b
bff5662
e928eab
c9c2a77
ce93b84
58d0e7f
d1bcb9f
80fafbf
1645180
57b618c
1fff3b5
a1e7d65
d8fb9f1
7671595
58cee5f
f070dee
e9cf183
87624c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { inject } from '@angular/core'; | ||
| import { | ||
| ResolveFn, | ||
| Router, | ||
| } from '@angular/router'; | ||
| import { Observable } from 'rxjs'; | ||
| import { | ||
| map, | ||
| tap, | ||
| } from 'rxjs/operators'; | ||
|
|
||
| import { getForbiddenRoute } from '../../app-routing-paths'; | ||
| import { hasValue } from '../../shared/empty.util'; | ||
| import { ItemRequestDataService } from '../data/item-request-data.service'; | ||
| import { RemoteData } from '../data/remote-data'; | ||
| import { redirectOn4xx } from '../shared/authorized.operators'; | ||
| import { ItemRequest } from '../shared/item-request.model'; | ||
| import { | ||
| getFirstCompletedRemoteData, | ||
| getFirstSucceededRemoteDataPayload, | ||
| } from '../shared/operators'; | ||
| import { AuthService } from './auth.service'; | ||
|
|
||
| /** | ||
| * Resolve an ItemRequest based on the accessToken in the query params | ||
| * Used in item-page-routes.ts to resolve the item request for all Item page components | ||
| * @param route | ||
| * @param state | ||
| * @param router | ||
| * @param authService | ||
| * @param itemRequestDataService | ||
| */ | ||
| export const accessTokenResolver: ResolveFn<ItemRequest> = ( | ||
| route, | ||
| state, | ||
| router: Router = inject(Router), | ||
| authService: AuthService = inject(AuthService), | ||
| itemRequestDataService: ItemRequestDataService = inject(ItemRequestDataService), | ||
| ): Observable<ItemRequest> => { | ||
| const accessToken = route.queryParams.accessToken; | ||
| // Set null object if accesstoken is empty | ||
| if ( !hasValue(accessToken) ) { | ||
| return null; | ||
| } | ||
| // Get the item request from the server | ||
| return itemRequestDataService.getSanitizedRequestByAccessToken(accessToken).pipe( | ||
| getFirstCompletedRemoteData(), | ||
| // Handle authorization errors, not found errors and forbidden errors as normal | ||
| redirectOn4xx(router, authService), | ||
|
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. Right now this means that you'll be shown a login page if you try to follow the access link after it expires. It would be more informative if we could still show the Item page, but with a notice to explain what's going on.
Member
Author
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. notifications now show 2 kinds of errors, depending on if the token is expired, or just was not granted or was revoked. the redirect operator here is still in place, but won't trigger in those scenarios because the backend returns 200 for those cases in the findByAccessToken method (of course, it still throws a hard authorize error in the actual bitstream download check) |
||
| map((rd: RemoteData<ItemRequest>) => rd), | ||
| // Get payload of the item request | ||
| getFirstSucceededRemoteDataPayload(), | ||
| tap(request => { | ||
| if (!hasValue(request)) { | ||
| // If the request is not found, redirect to 403 Forbidden | ||
| router.navigateByUrl(getForbiddenRoute()); | ||
| } | ||
| // Return the resolved item request object | ||
| return request; | ||
| }), | ||
| ); | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.