From dfad3f3fada3a75d3315ac2fb808e17e9fc8e88a Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Mon, 18 Mar 2024 21:03:37 +0100 Subject: [PATCH] [DURACOM-191] Fix issue with admin workflow page --- ...dmin-notify-message-search-result.model.ts | 2 - ...t-admin-workflow-list-element.component.ts | 16 +++++-- ...t-admin-workflow-list-element.component.ts | 12 +++--- src/app/app-routes.ts | 3 +- .../claimed-task-search-result.model.ts | 2 - .../shared/collection-search-result.model.ts | 2 - .../shared/community-search-result.model.ts | 2 - .../shared/item-search-result.model.ts | 2 - .../shared/pool-task-search-result.model.ts | 2 - .../workflow-item-search-result.model.ts | 2 - .../workspace-item-search-result.model.ts | 2 - .../search/search-result-element-decorator.ts | 42 ++++++++++++------- 12 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/app/admin/admin-notify-dashboard/models/admin-notify-message-search-result.model.ts b/src/app/admin/admin-notify-dashboard/models/admin-notify-message-search-result.model.ts index 51151189936..c4df75ef3ee 100644 --- a/src/app/admin/admin-notify-dashboard/models/admin-notify-message-search-result.model.ts +++ b/src/app/admin/admin-notify-dashboard/models/admin-notify-message-search-result.model.ts @@ -1,7 +1,5 @@ import { SearchResult } from '../../../shared/search/models/search-result.model'; -import { searchResultFor } from '../../../shared/search/search-result-element-decorator'; import { AdminNotifyMessage } from './admin-notify-message.model'; -@searchResultFor(AdminNotifyMessage) export class AdminNotifySearchResult extends SearchResult { } diff --git a/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-list-element/workflow-item/workflow-item-search-result-admin-workflow-list-element.component.ts b/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-list-element/workflow-item/workflow-item-search-result-admin-workflow-list-element.component.ts index 2bb6dbb32a3..60740fb34b8 100644 --- a/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-list-element/workflow-item/workflow-item-search-result-admin-workflow-list-element.component.ts +++ b/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-list-element/workflow-item/workflow-item-search-result-admin-workflow-list-element.component.ts @@ -8,7 +8,10 @@ import { OnInit, } from '@angular/core'; import { TranslateModule } from '@ngx-translate/core'; -import { Observable } from 'rxjs'; +import { + BehaviorSubject, + Observable, +} from 'rxjs'; import { APP_CONFIG, @@ -20,7 +23,7 @@ import { RemoteData } from '../../../../../core/data/remote-data'; import { Context } from '../../../../../core/shared/context.model'; import { Item } from '../../../../../core/shared/item.model'; import { - getAllSucceededRemoteData, + getFirstCompletedRemoteData, getRemoteDataPayload, } from '../../../../../core/shared/operators'; import { ViewMode } from '../../../../../core/shared/view-mode.model'; @@ -49,7 +52,7 @@ export class WorkflowItemSearchResultAdminWorkflowListElementComponent extends S /** * The item linked to the workflow item */ - public item$: Observable; + public item$: BehaviorSubject = new BehaviorSubject(undefined); constructor(private linkService: LinkService, protected truncatableService: TruncatableService, @@ -65,6 +68,11 @@ export class WorkflowItemSearchResultAdminWorkflowListElementComponent extends S ngOnInit(): void { super.ngOnInit(); this.dso = this.linkService.resolveLink(this.dso, followLink('item')); - this.item$ = (this.dso.item as Observable>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload()); + (this.dso.item as Observable>).pipe( + getFirstCompletedRemoteData(), + getRemoteDataPayload()) + .subscribe((item: Item) => { + this.item$.next(item); + }); } } diff --git a/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-list-element/workspace-item/workspace-item-search-result-admin-workflow-list-element.component.ts b/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-list-element/workspace-item/workspace-item-search-result-admin-workflow-list-element.component.ts index 3fce9ebdab4..7cf63a603b1 100644 --- a/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-list-element/workspace-item/workspace-item-search-result-admin-workflow-list-element.component.ts +++ b/src/app/admin/admin-workflow-page/admin-workflow-search-results/admin-workflow-search-result-list-element/workspace-item/workspace-item-search-result-admin-workflow-list-element.component.ts @@ -31,7 +31,6 @@ import { Context } from '../../../../../core/shared/context.model'; import { DSpaceObject } from '../../../../../core/shared/dspace-object.model'; import { Item } from '../../../../../core/shared/item.model'; import { - getAllSucceededRemoteData, getFirstCompletedRemoteData, getRemoteDataPayload, } from '../../../../../core/shared/operators'; @@ -63,7 +62,7 @@ export class WorkspaceItemSearchResultAdminWorkflowListElementComponent extends /** * The item linked to the workflow item */ - public item$: Observable; + public item$: BehaviorSubject = new BehaviorSubject(undefined); /** * The id of the item linked to the workflow item @@ -90,11 +89,14 @@ export class WorkspaceItemSearchResultAdminWorkflowListElementComponent extends ngOnInit(): void { super.ngOnInit(); this.dso = this.linkService.resolveLink(this.dso, followLink('item')); - this.item$ = (this.dso.item as Observable>).pipe(getAllSucceededRemoteData(), getRemoteDataPayload()); + const item$ = (this.dso.item as Observable>).pipe(getFirstCompletedRemoteData(), getRemoteDataPayload()); - this.item$.pipe( + item$.pipe( take(1), - tap((item: Item) => this.itemId = item.id), + tap((item: Item) => { + this.item$.next(item); + this.itemId = item.id; + }), mergeMap((item: Item) => this.retrieveSupervisorOrders(item.id)), ).subscribe((supervisionOrderList: SupervisionOrder[]) => { this.supervisionOrder$.next(supervisionOrderList); diff --git a/src/app/app-routes.ts b/src/app/app-routes.ts index ba322eef457..794d532176b 100644 --- a/src/app/app-routes.ts +++ b/src/app/app-routes.ts @@ -26,6 +26,7 @@ import { COMMUNITY_MODULE_PATH } from './community-page/community-page-routing-p import { AuthBlockingGuard } from './core/auth/auth-blocking.guard'; import { AuthenticatedGuard } from './core/auth/authenticated.guard'; import { GroupAdministratorGuard } from './core/data/feature-authorization/feature-authorization-guard/group-administrator.guard'; +import { SiteAdministratorGuard } from './core/data/feature-authorization/feature-authorization-guard/site-administrator.guard'; import { SiteRegisterGuard } from './core/data/feature-authorization/feature-authorization-guard/site-register.guard'; import { EndUserAgreementCurrentUserGuard } from './core/end-user-agreement/end-user-agreement-current-user.guard'; import { ReloadGuard } from './core/reload/reload.guard'; @@ -155,7 +156,7 @@ export const APP_ROUTES: Route[] = [ path: ADMIN_MODULE_PATH, loadChildren: () => import('./admin/admin-routes') .then((m) => m.ROUTES), - canActivate: [EndUserAgreementCurrentUserGuard], + canActivate: [SiteAdministratorGuard, EndUserAgreementCurrentUserGuard], }, { path: NOTIFICATIONS_MODULE_PATH, diff --git a/src/app/shared/object-collection/shared/claimed-task-search-result.model.ts b/src/app/shared/object-collection/shared/claimed-task-search-result.model.ts index f8d07522457..8f580f19243 100644 --- a/src/app/shared/object-collection/shared/claimed-task-search-result.model.ts +++ b/src/app/shared/object-collection/shared/claimed-task-search-result.model.ts @@ -1,10 +1,8 @@ import { ClaimedTask } from '../../../core/tasks/models/claimed-task-object.model'; import { SearchResult } from '../../search/models/search-result.model'; -import { searchResultFor } from '../../search/search-result-element-decorator'; /** * Represents a search result object of a ClaimedTask object */ -@searchResultFor(ClaimedTask) export class ClaimedTaskSearchResult extends SearchResult { } diff --git a/src/app/shared/object-collection/shared/collection-search-result.model.ts b/src/app/shared/object-collection/shared/collection-search-result.model.ts index bd2f5478088..cff44c0ba20 100644 --- a/src/app/shared/object-collection/shared/collection-search-result.model.ts +++ b/src/app/shared/object-collection/shared/collection-search-result.model.ts @@ -1,7 +1,5 @@ import { Collection } from '../../../core/shared/collection.model'; import { SearchResult } from '../../search/models/search-result.model'; -import { searchResultFor } from '../../search/search-result-element-decorator'; -@searchResultFor(Collection) export class CollectionSearchResult extends SearchResult { } diff --git a/src/app/shared/object-collection/shared/community-search-result.model.ts b/src/app/shared/object-collection/shared/community-search-result.model.ts index e80dfdaecf7..08127671753 100644 --- a/src/app/shared/object-collection/shared/community-search-result.model.ts +++ b/src/app/shared/object-collection/shared/community-search-result.model.ts @@ -1,7 +1,5 @@ import { Community } from '../../../core/shared/community.model'; import { SearchResult } from '../../search/models/search-result.model'; -import { searchResultFor } from '../../search/search-result-element-decorator'; -@searchResultFor(Community) export class CommunitySearchResult extends SearchResult { } diff --git a/src/app/shared/object-collection/shared/item-search-result.model.ts b/src/app/shared/object-collection/shared/item-search-result.model.ts index 5409bdbec7d..4704a9ffe68 100644 --- a/src/app/shared/object-collection/shared/item-search-result.model.ts +++ b/src/app/shared/object-collection/shared/item-search-result.model.ts @@ -2,10 +2,8 @@ import { GenericConstructor } from '../../../core/shared/generic-constructor'; import { Item } from '../../../core/shared/item.model'; import { inheritEquatable } from '../../../core/utilities/equals.decorators'; import { SearchResult } from '../../search/models/search-result.model'; -import { searchResultFor } from '../../search/search-result-element-decorator'; import { ListableObject } from './listable-object.model'; -@searchResultFor(Item) @inheritEquatable(SearchResult) export class ItemSearchResult extends SearchResult { diff --git a/src/app/shared/object-collection/shared/pool-task-search-result.model.ts b/src/app/shared/object-collection/shared/pool-task-search-result.model.ts index 9ee74bcd4b8..e6d06b4e666 100644 --- a/src/app/shared/object-collection/shared/pool-task-search-result.model.ts +++ b/src/app/shared/object-collection/shared/pool-task-search-result.model.ts @@ -1,10 +1,8 @@ import { PoolTask } from '../../../core/tasks/models/pool-task-object.model'; import { SearchResult } from '../../search/models/search-result.model'; -import { searchResultFor } from '../../search/search-result-element-decorator'; /** * Represents a search result object of a PoolTask object */ -@searchResultFor(PoolTask) export class PoolTaskSearchResult extends SearchResult { } diff --git a/src/app/shared/object-collection/shared/workflow-item-search-result.model.ts b/src/app/shared/object-collection/shared/workflow-item-search-result.model.ts index 8611f8678ac..431974cbcc4 100644 --- a/src/app/shared/object-collection/shared/workflow-item-search-result.model.ts +++ b/src/app/shared/object-collection/shared/workflow-item-search-result.model.ts @@ -1,10 +1,8 @@ import { WorkflowItem } from '../../../core/submission/models/workflowitem.model'; import { SearchResult } from '../../search/models/search-result.model'; -import { searchResultFor } from '../../search/search-result-element-decorator'; /** * Represents a search result object of a WorkflowItem object */ -@searchResultFor(WorkflowItem) export class WorkflowItemSearchResult extends SearchResult { } diff --git a/src/app/shared/object-collection/shared/workspace-item-search-result.model.ts b/src/app/shared/object-collection/shared/workspace-item-search-result.model.ts index 3f57d2f4cda..f0b65c4bd1c 100644 --- a/src/app/shared/object-collection/shared/workspace-item-search-result.model.ts +++ b/src/app/shared/object-collection/shared/workspace-item-search-result.model.ts @@ -1,10 +1,8 @@ import { WorkspaceItem } from '../../../core/submission/models/workspaceitem.model'; import { SearchResult } from '../../search/models/search-result.model'; -import { searchResultFor } from '../../search/search-result-element-decorator'; /** * Represents a search result object of a WorkspaceItem object */ -@searchResultFor(WorkspaceItem) export class WorkspaceItemSearchResult extends SearchResult { } diff --git a/src/app/shared/search/search-result-element-decorator.ts b/src/app/shared/search/search-result-element-decorator.ts index 5241318122e..56d712ce269 100644 --- a/src/app/shared/search/search-result-element-decorator.ts +++ b/src/app/shared/search/search-result-element-decorator.ts @@ -1,24 +1,36 @@ +import { AdminNotifyMessage } from '../../admin/admin-notify-dashboard/models/admin-notify-message.model'; +import { AdminNotifySearchResult } from '../../admin/admin-notify-dashboard/models/admin-notify-message-search-result.model'; +import { Collection } from '../../core/shared/collection.model'; +import { Community } from '../../core/shared/community.model'; import { GenericConstructor } from '../../core/shared/generic-constructor'; +import { Item } from '../../core/shared/item.model'; +import { WorkflowItem } from '../../core/submission/models/workflowitem.model'; +import { WorkspaceItem } from '../../core/submission/models/workspaceitem.model'; +import { ClaimedTask } from '../../core/tasks/models/claimed-task-object.model'; +import { PoolTask } from '../../core/tasks/models/pool-task-object.model'; +import { ClaimedTaskSearchResult } from '../object-collection/shared/claimed-task-search-result.model'; +import { CollectionSearchResult } from '../object-collection/shared/collection-search-result.model'; +import { CommunitySearchResult } from '../object-collection/shared/community-search-result.model'; +import { ItemSearchResult } from '../object-collection/shared/item-search-result.model'; import { ListableObject } from '../object-collection/shared/listable-object.model'; +import { PoolTaskSearchResult } from '../object-collection/shared/pool-task-search-result.model'; +import { WorkflowItemSearchResult } from '../object-collection/shared/workflow-item-search-result.model'; +import { WorkspaceItemSearchResult } from '../object-collection/shared/workspace-item-search-result.model'; /** * Contains the mapping between a search result component and a DSpaceObject */ -const searchResultMap = new Map(); +export const SEARCH_RESULT_MAP = new Map, GenericConstructor>([ + [AdminNotifyMessage, AdminNotifySearchResult], + [ClaimedTask, ClaimedTaskSearchResult], + [PoolTask, PoolTaskSearchResult], + [Collection, CollectionSearchResult], + [Community, CommunitySearchResult], + [Item, ItemSearchResult], + [WorkflowItem, WorkflowItemSearchResult], + [WorkspaceItem, WorkspaceItemSearchResult], +]); -/** - * Used to map Search Result components to their matching DSpaceObject - * @param {GenericConstructor} domainConstructor The constructor of the DSpaceObject - * @returns Decorator function that performs the actual mapping on initialization of the component - */ -export function searchResultFor(domainConstructor: GenericConstructor) { - return function decorator(searchResult: any) { - if (!searchResult) { - return; - } - searchResultMap.set(domainConstructor, searchResult); - }; -} /** * Requests the matching component based on a given DSpaceObject's constructor @@ -26,5 +38,5 @@ export function searchResultFor(domainConstructor: GenericConstructor) { - return searchResultMap.get(domainConstructor); + return SEARCH_RESULT_MAP.get(domainConstructor); }