mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-09 19:13:08 +00:00
Request-a-copy improv: Changes to bitstream page to support tests
This commit is contained in:
@@ -73,16 +73,16 @@ describe('BitstreamDownloadPageComponent', () => {
|
|||||||
self: { href: 'bitstream-self-link' },
|
self: { href: 'bitstream-self-link' },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
activatedRoute = {
|
activatedRoute = {
|
||||||
data: observableOf({
|
data: observableOf({
|
||||||
bitstream: createSuccessfulRemoteDataObject(
|
bitstream: createSuccessfulRemoteDataObject(bitstream),
|
||||||
bitstream,
|
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
params: observableOf({
|
params: observableOf({
|
||||||
id: 'testid',
|
id: 'testid',
|
||||||
}),
|
}),
|
||||||
|
queryParams: observableOf({
|
||||||
|
accessToken: undefined,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
router = jasmine.createSpyObj('router', ['navigateByUrl']);
|
router = jasmine.createSpyObj('router', ['navigateByUrl']);
|
||||||
|
@@ -11,6 +11,7 @@ import {
|
|||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import {
|
import {
|
||||||
ActivatedRoute,
|
ActivatedRoute,
|
||||||
|
Params,
|
||||||
Router,
|
Router,
|
||||||
} from '@angular/router';
|
} from '@angular/router';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
@@ -83,11 +84,16 @@ export class BitstreamDownloadPageComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
const accessToken$: Observable<string> = this.route.queryParams.pipe(
|
||||||
|
map((queryParams: Params) => queryParams?.accessToken || null),
|
||||||
|
take(1),
|
||||||
|
);
|
||||||
|
|
||||||
this.bitstreamRD$ = this.route.data.pipe(
|
this.bitstreamRD$ = this.route.data.pipe(
|
||||||
map((data) => data.bitstream));
|
map((data) => data.bitstream));
|
||||||
|
|
||||||
this.bitstream$ = this.bitstreamRD$.pipe(
|
this.bitstream$ = this.bitstreamRD$.pipe(
|
||||||
|
// TODO: this redirect was commented out earlier...
|
||||||
redirectOn4xx(this.router, this.auth),
|
redirectOn4xx(this.router, this.auth),
|
||||||
getRemoteDataPayload(),
|
getRemoteDataPayload(),
|
||||||
);
|
);
|
||||||
@@ -95,12 +101,13 @@ export class BitstreamDownloadPageComponent implements OnInit {
|
|||||||
this.bitstream$.pipe(
|
this.bitstream$.pipe(
|
||||||
switchMap((bitstream: Bitstream) => {
|
switchMap((bitstream: Bitstream) => {
|
||||||
const isAuthorized$ = this.authorizationService.isAuthorized(FeatureID.CanDownload, isNotEmpty(bitstream) ? bitstream.self : undefined);
|
const isAuthorized$ = this.authorizationService.isAuthorized(FeatureID.CanDownload, isNotEmpty(bitstream) ? bitstream.self : undefined);
|
||||||
|
// TODO isAuthorizedByToken check here so we already know if this token is going to be valid?
|
||||||
const isLoggedIn$ = this.auth.isAuthenticated();
|
const isLoggedIn$ = this.auth.isAuthenticated();
|
||||||
return observableCombineLatest([isAuthorized$, isLoggedIn$, observableOf(bitstream)]);
|
return observableCombineLatest([isAuthorized$, isLoggedIn$, accessToken$, observableOf(bitstream)]);
|
||||||
}),
|
}),
|
||||||
filter(([isAuthorized, isLoggedIn, bitstream]: [boolean, boolean, Bitstream]) => hasValue(isAuthorized) && hasValue(isLoggedIn)),
|
filter(([isAuthorized, isLoggedIn, accessToken, bitstream]: [boolean, boolean, string, Bitstream]) => (hasValue(isAuthorized) && hasValue(isLoggedIn)) || hasValue(accessToken)),
|
||||||
take(1),
|
take(1),
|
||||||
switchMap(([isAuthorized, isLoggedIn, bitstream]: [boolean, boolean, Bitstream]) => {
|
switchMap(([isAuthorized, isLoggedIn, accessToken, bitstream]: [boolean, boolean, string, Bitstream]) => {
|
||||||
if (isAuthorized && isLoggedIn) {
|
if (isAuthorized && isLoggedIn) {
|
||||||
return this.fileService.retrieveFileDownloadLink(bitstream._links.content.href).pipe(
|
return this.fileService.retrieveFileDownloadLink(bitstream._links.content.href).pipe(
|
||||||
filter((fileLink) => hasValue(fileLink)),
|
filter((fileLink) => hasValue(fileLink)),
|
||||||
@@ -108,21 +115,50 @@ export class BitstreamDownloadPageComponent implements OnInit {
|
|||||||
map((fileLink) => {
|
map((fileLink) => {
|
||||||
return [isAuthorized, isLoggedIn, bitstream, fileLink];
|
return [isAuthorized, isLoggedIn, bitstream, fileLink];
|
||||||
}));
|
}));
|
||||||
|
} else if (hasValue(accessToken)) {
|
||||||
|
// We aren't authorized or logged in, but we might have temp access via the access token
|
||||||
|
console.log('RETRIEVE WITH ACCESS TOKEN');
|
||||||
|
console.log('BUT - we dont want to retrieve the link with access token eh bro');
|
||||||
|
// return this.fileService.retrieveFileDownloadLinkWithAccessToken(bitstream._links.content.href, accessToken).pipe(
|
||||||
|
// filter((fileLink) => hasValue(fileLink)),
|
||||||
|
// take(1),
|
||||||
|
// map((fileLink) => {
|
||||||
|
// return [isAuthorized, isLoggedIn, bitstream, fileLink];
|
||||||
|
// }));
|
||||||
|
return [[isAuthorized, !isLoggedIn, bitstream, '', accessToken]];
|
||||||
} else {
|
} else {
|
||||||
return [[isAuthorized, isLoggedIn, bitstream, '']];
|
return [[isAuthorized, isLoggedIn, bitstream, '']];
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
).subscribe(([isAuthorized, isLoggedIn, bitstream, fileLink]: [boolean, boolean, Bitstream, string]) => {
|
).subscribe(([isAuthorized, isLoggedIn, bitstream, fileLink, accessToken]: [boolean, boolean, Bitstream, string, string]) => {
|
||||||
|
// if (isAuthorized && isLoggedIn && isNotEmpty(fileLink)) {
|
||||||
|
// this.hardRedirectService.redirect(fileLink);
|
||||||
|
// } else if (isAuthorized && !isLoggedIn) {
|
||||||
|
// this.hardRedirectService.redirect(bitstream._links.content.href);
|
||||||
|
// } else if (!isAuthorized && isLoggedIn) {
|
||||||
|
// this.router.navigateByUrl(getForbiddenRoute(), {skipLocationChange: true});
|
||||||
|
// } else if (!isAuthorized && !isLoggedIn) {
|
||||||
|
// this.auth.setRedirectUrl(this.router.url);
|
||||||
|
// this.router.navigateByUrl('login');
|
||||||
|
// }
|
||||||
|
|
||||||
if (isAuthorized && isLoggedIn && isNotEmpty(fileLink)) {
|
if (isAuthorized && isLoggedIn && isNotEmpty(fileLink)) {
|
||||||
this.hardRedirectService.redirect(fileLink);
|
this.hardRedirectService.redirect(fileLink);
|
||||||
} else if (isAuthorized && !isLoggedIn) {
|
} else if (isAuthorized && !isLoggedIn && !hasValue(accessToken)) {
|
||||||
this.hardRedirectService.redirect(bitstream._links.content.href);
|
this.hardRedirectService.redirect(bitstream._links.content.href);
|
||||||
} else if (!isAuthorized && isLoggedIn) {
|
} else if (!isAuthorized) {
|
||||||
|
// Either we have an access token, or we are logged in, or we are not logged in.
|
||||||
|
// For now, the access token does not care if we are logged in or not.
|
||||||
|
if (hasValue(accessToken)) {
|
||||||
|
this.hardRedirectService.redirect(bitstream._links.content.href + '?accessToken=' + accessToken);
|
||||||
|
// this.router.navigateByUrl(getForbiddenRoute(), {skipLocationChange: true});
|
||||||
|
} else if (isLoggedIn) {
|
||||||
this.router.navigateByUrl(getForbiddenRoute(), { skipLocationChange: true });
|
this.router.navigateByUrl(getForbiddenRoute(), { skipLocationChange: true });
|
||||||
} else if (!isAuthorized && !isLoggedIn) {
|
} else if (!isLoggedIn) {
|
||||||
this.auth.setRedirectUrl(this.router.url);
|
this.auth.setRedirectUrl(this.router.url);
|
||||||
this.router.navigateByUrl('login');
|
this.router.navigateByUrl('login');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user