mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-11 03:53:02 +00:00
Merge remote-tracking branch 'atmire/w2p-93219_Consolidate-all-initialization-in-a-single-Service_PR' into w2p-92900_Admin_options_dont_appear_after_Shibboleth_authentication_PR
This commit is contained in:
@@ -3,7 +3,7 @@ import { distinctUntilChanged, filter, map, mergeMap, switchMap, tap, take } fro
|
||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||
import { RequestService } from '../data/request.service';
|
||||
import { isNotEmpty } from '../../shared/empty.util';
|
||||
import { GetRequest, PostRequest, RestRequest, } from '../data/request.models';
|
||||
import { GetRequest, PostRequest, } from '../data/request.models';
|
||||
import { HttpOptions } from '../dspace-rest/dspace-rest.service';
|
||||
import { getFirstCompletedRemoteData } from '../shared/operators';
|
||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||
@@ -11,13 +11,14 @@ import { RemoteData } from '../data/remote-data';
|
||||
import { AuthStatus } from './models/auth-status.model';
|
||||
import { ShortLivedToken } from './models/short-lived-token.model';
|
||||
import { URLCombiner } from '../url-combiner/url-combiner';
|
||||
import { RestRequest } from '../data/rest-request.model';
|
||||
import { FollowLinkConfig } from '../../shared/utils/follow-link-config.model';
|
||||
|
||||
/**
|
||||
* Abstract service to send authentication requests
|
||||
*/
|
||||
export abstract class AuthRequestService {
|
||||
protected linkName = 'authn';
|
||||
protected browseEndpoint = '';
|
||||
protected shortlivedtokensEndpoint = 'shortlivedtokens';
|
||||
|
||||
constructor(protected halService: HALEndpointService,
|
||||
@@ -31,14 +32,21 @@ export abstract class AuthRequestService {
|
||||
* @param requestId the UUID of the request for which to retrieve the response
|
||||
* @protected
|
||||
*/
|
||||
protected fetchRequest(requestId: string): Observable<RemoteData<AuthStatus>> {
|
||||
return this.rdbService.buildFromRequestUUID<AuthStatus>(requestId).pipe(
|
||||
protected fetchRequest(requestId: string, ...linksToFollow: FollowLinkConfig<AuthStatus>[]): Observable<RemoteData<AuthStatus>> {
|
||||
return this.rdbService.buildFromRequestUUID<AuthStatus>(requestId, ...linksToFollow).pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
);
|
||||
}
|
||||
|
||||
protected getEndpointByMethod(endpoint: string, method: string): string {
|
||||
return isNotEmpty(method) ? `${endpoint}/${method}` : `${endpoint}`;
|
||||
protected getEndpointByMethod(endpoint: string, method: string, ...linksToFollow: FollowLinkConfig<AuthStatus>[]): string {
|
||||
let url = isNotEmpty(method) ? `${endpoint}/${method}` : `${endpoint}`;
|
||||
if (linksToFollow?.length > 0) {
|
||||
linksToFollow.forEach((link: FollowLinkConfig<AuthStatus>, index: number) => {
|
||||
url += ((index === 0) ? '?' : '&') + `embed=${link.name}`;
|
||||
});
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,12 +76,12 @@ export abstract class AuthRequestService {
|
||||
* @param method the method to send to (e.g. 'status')
|
||||
* @param options the HTTP options for the request
|
||||
*/
|
||||
public getRequest(method: string, options?: HttpOptions): Observable<RemoteData<AuthStatus>> {
|
||||
public getRequest(method: string, options?: HttpOptions, ...linksToFollow: FollowLinkConfig<any>[]): Observable<RemoteData<AuthStatus>> {
|
||||
const requestId = this.requestService.generateRequestId();
|
||||
|
||||
this.halService.getEndpoint(this.linkName).pipe(
|
||||
filter((href: string) => isNotEmpty(href)),
|
||||
map((endpointURL) => this.getEndpointByMethod(endpointURL, method)),
|
||||
map((endpointURL) => this.getEndpointByMethod(endpointURL, method, ...linksToFollow)),
|
||||
distinctUntilChanged(),
|
||||
map((endpointURL: string) => new GetRequest(requestId, endpointURL, undefined, options)),
|
||||
take(1)
|
||||
@@ -81,7 +89,7 @@ export abstract class AuthRequestService {
|
||||
this.requestService.send(request);
|
||||
});
|
||||
|
||||
return this.fetchRequest(requestId);
|
||||
return this.fetchRequest(requestId, ...linksToFollow);
|
||||
}
|
||||
/**
|
||||
* Factory function to create the request object to send. This needs to be a POST client side and
|
||||
|
Reference in New Issue
Block a user