mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[CST-5738] Fix retrieving of embed from auth status model
This commit is contained in:
@@ -12,6 +12,7 @@ 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
|
||||
@@ -26,16 +27,18 @@ export abstract class AuthRequestService {
|
||||
) {
|
||||
}
|
||||
|
||||
protected fetchRequest(request: RestRequest): Observable<RemoteData<AuthStatus>> {
|
||||
return this.rdbService.buildFromRequestUUID<AuthStatus>(request.uuid).pipe(
|
||||
protected fetchRequest(request: RestRequest, ...linksToFollow: FollowLinkConfig<AuthStatus>[]): Observable<RemoteData<AuthStatus>> {
|
||||
return this.rdbService.buildFromRequestUUID<AuthStatus>(request.uuid, ...linksToFollow).pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
);
|
||||
}
|
||||
|
||||
protected getEndpointByMethod(endpoint: string, method: string, embed = false): string {
|
||||
protected getEndpointByMethod(endpoint: string, method: string, ...linksToFollow: FollowLinkConfig<AuthStatus>[]): string {
|
||||
let url = isNotEmpty(method) ? `${endpoint}/${method}` : `${endpoint}`;
|
||||
if (embed) {
|
||||
url += '?embed=specialGroups';
|
||||
if (linksToFollow && linksToFollow.length > 0) {
|
||||
linksToFollow.forEach((link: FollowLinkConfig<AuthStatus>, index: number) => {
|
||||
url += ((index === 0) ? '?' : '&') + `embed=${link.name}`;
|
||||
});
|
||||
}
|
||||
|
||||
return url;
|
||||
@@ -52,14 +55,14 @@ export abstract class AuthRequestService {
|
||||
distinctUntilChanged());
|
||||
}
|
||||
|
||||
public getRequest(method: string, options?: HttpOptions, embed = false): Observable<RemoteData<AuthStatus>> {
|
||||
public getRequest(method: string, options?: HttpOptions, ...linksToFollow: FollowLinkConfig<any>[]): Observable<RemoteData<AuthStatus>> {
|
||||
return 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(this.requestService.generateRequestId(), endpointURL, undefined, options)),
|
||||
tap((request: GetRequest) => this.requestService.send(request)),
|
||||
mergeMap((request: GetRequest) => this.fetchRequest(request)),
|
||||
mergeMap((request: GetRequest) => this.fetchRequest(request, ...linksToFollow)),
|
||||
distinctUntilChanged());
|
||||
}
|
||||
|
||||
|
@@ -55,6 +55,7 @@ import { buildPaginatedList, PaginatedList } from '../data/paginated-list.model'
|
||||
import { Group } from '../eperson/models/group.model';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||
import { PageInfo } from '../shared/page-info.model';
|
||||
import { followLink } from '../../shared/utils/follow-link-config.model';
|
||||
|
||||
export const LOGIN_ROUTE = '/login';
|
||||
export const LOGOUT_ROUTE = '/logout';
|
||||
@@ -219,7 +220,7 @@ export class AuthService {
|
||||
* Return the special groups list embedded in the AuthStatus model
|
||||
*/
|
||||
public getSpecialGroupsFromAuthStatus(): Observable<RemoteData<PaginatedList<Group>>> {
|
||||
return this.authRequestService.getRequest('status', null, true).pipe(
|
||||
return this.authRequestService.getRequest('status', null, followLink('specialGroups')).pipe(
|
||||
getFirstCompletedRemoteData(),
|
||||
switchMap((status: RemoteData<AuthStatus>) => {
|
||||
if (status.hasSucceeded) {
|
||||
|
Reference in New Issue
Block a user