71429: FeatureType enum and searchBy override

This commit is contained in:
Kristof De Langhe
2020-06-18 14:47:59 +02:00
parent ec998fce30
commit 8350833b61
5 changed files with 46 additions and 8 deletions

View File

@@ -24,7 +24,7 @@ import { NotificationsService } from '../../../../shared/notifications/notificat
import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model'; import { PaginationComponentOptions } from '../../../../shared/pagination/pagination-component-options.model';
import { AuthService } from '../../../../core/auth/auth.service'; import { AuthService } from '../../../../core/auth/auth.service';
import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service'; import { AuthorizationDataService } from '../../../../core/data/feature-authorization/authorization-data.service';
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject'; import { FeatureType } from '../../../../core/data/feature-authorization/feature-type';
@Component({ @Component({
selector: 'ds-eperson-form', selector: 'ds-eperson-form',
@@ -245,7 +245,7 @@ export class EPersonFormComponent implements OnInit, OnDestroy {
}); });
})); }));
this.canImpersonate$ = this.epersonService.getActiveEPerson().pipe( this.canImpersonate$ = this.epersonService.getActiveEPerson().pipe(
switchMap((eperson) => this.authorizationService.isAuthenticated(eperson.self, undefined, 'loginOnBehalfOf')) switchMap((eperson) => this.authorizationService.isAuthenticated(eperson.self, undefined, FeatureType.LoginOnBehalfOf))
); );
}); });
} }

View File

@@ -25,6 +25,7 @@ import { hasValue, isNotEmpty } from '../../../shared/empty.util';
import { RequestParam } from '../../cache/models/request-param.model'; import { RequestParam } from '../../cache/models/request-param.model';
import { AuthorizationSearchParams } from './authorization-search-params'; import { AuthorizationSearchParams } from './authorization-search-params';
import { addAuthenticatedUserUuidIfEmpty, addSiteObjectUrlIfEmpty } from './authorization-utils'; import { addAuthenticatedUserUuidIfEmpty, addSiteObjectUrlIfEmpty } from './authorization-utils';
import { FeatureType } from './feature-type';
/** /**
* A service to retrieve {@link Authorization}s from the REST API * A service to retrieve {@link Authorization}s from the REST API
@@ -58,7 +59,7 @@ export class AuthorizationDataService extends DataService<Authorization> {
* If not provided, the UUID of the currently authenticated {@link EPerson} will be used. * If not provided, the UUID of the currently authenticated {@link EPerson} will be used.
* @param featureId ID of the {@link Feature} to check {@link Authorization} for * @param featureId ID of the {@link Feature} to check {@link Authorization} for
*/ */
isAuthenticated(objectUrl?: string, ePersonUuid?: string, featureId?: string): Observable<boolean> { isAuthenticated(objectUrl?: string, ePersonUuid?: string, featureId?: FeatureType): Observable<boolean> {
return this.searchByObject(objectUrl, ePersonUuid, featureId).pipe( return this.searchByObject(objectUrl, ePersonUuid, featureId).pipe(
map((authorizationRD) => (authorizationRD.statusCode !== 401 && hasValue(authorizationRD.payload) && isNotEmpty(authorizationRD.payload.page))) map((authorizationRD) => (authorizationRD.statusCode !== 401 && hasValue(authorizationRD.payload) && isNotEmpty(authorizationRD.payload.page)))
); );
@@ -75,7 +76,7 @@ export class AuthorizationDataService extends DataService<Authorization> {
* @param options {@link FindListOptions} to provide pagination and/or additional arguments * @param options {@link FindListOptions} to provide pagination and/or additional arguments
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved * @param linksToFollow List of {@link FollowLinkConfig} that indicate which {@link HALLink}s should be automatically resolved
*/ */
searchByObject(objectUrl?: string, ePersonUuid?: string, featureId?: string, options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<Authorization>>): Observable<RemoteData<PaginatedList<Authorization>>> { searchByObject(objectUrl?: string, ePersonUuid?: string, featureId?: FeatureType, options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<Authorization>>): Observable<RemoteData<PaginatedList<Authorization>>> {
return observableOf(new AuthorizationSearchParams(objectUrl, ePersonUuid, featureId)).pipe( return observableOf(new AuthorizationSearchParams(objectUrl, ePersonUuid, featureId)).pipe(
addSiteObjectUrlIfEmpty(this.siteService), addSiteObjectUrlIfEmpty(this.siteService),
addAuthenticatedUserUuidIfEmpty(this.authService), addAuthenticatedUserUuidIfEmpty(this.authService),
@@ -121,7 +122,7 @@ export class AuthorizationDataService extends DataService<Authorization> {
* @param ePersonUuid Optional parameter value to add to {@link RequestParam} "eperson" * @param ePersonUuid Optional parameter value to add to {@link RequestParam} "eperson"
* @param featureId Optional parameter value to add to {@link RequestParam} "feature" * @param featureId Optional parameter value to add to {@link RequestParam} "feature"
*/ */
private createSearchOptions(objectUrl: string, options: FindListOptions = {}, ePersonUuid?: string, featureId?: string): FindListOptions { private createSearchOptions(objectUrl: string, options: FindListOptions = {}, ePersonUuid?: string, featureId?: FeatureType): FindListOptions {
let params = []; let params = [];
if (isNotEmpty(options.searchParams)) { if (isNotEmpty(options.searchParams)) {
params = [...options.searchParams]; params = [...options.searchParams];

View File

@@ -1,9 +1,11 @@
import { FeatureType } from './feature-type';
export class AuthorizationSearchParams { export class AuthorizationSearchParams {
objectUrl: string; objectUrl: string;
ePersonUuid: string; ePersonUuid: string;
featureId: string; featureId: FeatureType;
constructor(objectUrl?: string, ePersonUuid?: string, featureId?: string) { constructor(objectUrl?: string, ePersonUuid?: string, featureId?: FeatureType) {
this.objectUrl = objectUrl; this.objectUrl = objectUrl;
this.ePersonUuid = ePersonUuid; this.ePersonUuid = ePersonUuid;
this.featureId = featureId; this.featureId = featureId;

View File

@@ -0,0 +1,6 @@
/**
* Enum object for all possible {@link Feature} types
*/
export enum FeatureType {
LoginOnBehalfOf = 'loginOnBehalfOf'
}

View File

@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import { createSelector, select, Store } from '@ngrx/store'; import { createSelector, select, Store } from '@ngrx/store';
import { Operation } from 'fast-json-patch/lib/core'; import { Operation } from 'fast-json-patch/lib/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { filter, map, take } from 'rxjs/operators'; import { filter, find, map, skipWhile, switchMap, take, tap } from 'rxjs/operators';
import { import {
EPeopleRegistryCancelEPersonAction, EPeopleRegistryCancelEPersonAction,
EPeopleRegistryEditEPersonAction EPeopleRegistryEditEPersonAction
@@ -249,4 +249,33 @@ export class EPersonDataService extends DataService<EPerson> {
return '/admin/access-control/epeople'; return '/admin/access-control/epeople';
} }
/**
* Make a new FindListRequest with given search method
*
* @param searchMethod The search method for the object
* @param options The [[FindListOptions]] object
* @param linksToFollow The array of [[FollowLinkConfig]]
* @return {Observable<RemoteData<PaginatedList<EPerson>>}
* Return an observable that emits response from the server
*/
searchBy(searchMethod: string, options: FindListOptions = {}, ...linksToFollow: Array<FollowLinkConfig<EPerson>>): Observable<RemoteData<PaginatedList<EPerson>>> {
const hrefObs = this.getSearchByHref(searchMethod, options, ...linksToFollow);
return hrefObs.pipe(
find((href: string) => hasValue(href)),
tap((href: string) => {
this.requestService.removeByHrefSubstring(href);
const request = new FindListRequest(this.requestService.generateRequestId(), href, options);
this.requestService.configure(request);
}
),
switchMap((href) => this.requestService.getByHref(href)),
skipWhile((requestEntry) => hasValue(requestEntry) && requestEntry.completed),
switchMap((href) =>
this.rdbService.buildList<EPerson>(hrefObs, ...linksToFollow) as Observable<RemoteData<PaginatedList<EPerson>>>
)
);
}
} }