Merge branch 'w2p-90263_issue-8205_no-embargoed-files-on-google-scholar-meta-tag-7.0' into w2p-90263_issue-8205_no-embargoed-files-on-google-scholar-meta-tag

This commit is contained in:
Marie Verdonck
2022-04-13 15:50:57 +02:00
3 changed files with 81 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
import { Router, UrlTree } from '@angular/router';
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
import { combineLatest as observableCombineLatest, Observable, of as observableOf } from 'rxjs';
import {
debounceTime,
filter,
@@ -27,6 +27,9 @@ import { getForbiddenRoute, getPageNotFoundRoute } from '../../app-routing-paths
import { getEndUserAgreementPath } from '../../info/info-routing-paths';
import { AuthService } from '../auth/auth.service';
import { InjectionToken } from '@angular/core';
import { Bitstream } from './bitstream.model';
import { FeatureID } from '../data/feature-authorization/feature-id';
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
export const DEBOUNCE_TIME_OPERATOR = new InjectionToken<<T>(dueTime: number) => (source: Observable<T>) => Observable<T>>('debounceTime', {
providedIn: 'root',
@@ -355,3 +358,21 @@ export const metadataFieldsToString = () =>
return fieldSchemaArray.map((fieldSchema: { field: MetadataField, schema: MetadataSchema }) => fieldSchema.schema.prefix + '.' + fieldSchema.field.toString());
})
);
/**
* Operator to check if the given bitstream is downloadable
*/
export const getDownloadableBitstream = (authService: AuthorizationDataService) =>
(source: Observable<Bitstream>): Observable<Bitstream | null> =>
source.pipe(
switchMap((bit: Bitstream) => {
if (hasValue(bit)) {
return authService.isAuthorized(FeatureID.CanDownload, bit.self).pipe(
map((canDownload: boolean) => {
return canDownload ? bit : null;
}));
} else {
return observableOf(null);
}
})
);