From ee3114972d310f54d85de4c67ca8c0a5ee0105a2 Mon Sep 17 00:00:00 2001 From: Vincenzo Mecca Date: Mon, 13 Nov 2023 18:13:38 +0100 Subject: [PATCH] [DSC-1184] Fixes visualization of item-version-menu on original item --- .../authorization-data.service.ts | 15 ++++++++++++++- src/app/core/data/version-data.service.ts | 11 +++++++++++ .../item-version/item-version-menu.component.ts | 5 ++--- .../dso-versioning-modal.service.ts | 11 ++++++++++- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/app/core/data/feature-authorization/authorization-data.service.ts b/src/app/core/data/feature-authorization/authorization-data.service.ts index 1002a438499..3071d02c195 100644 --- a/src/app/core/data/feature-authorization/authorization-data.service.ts +++ b/src/app/core/data/feature-authorization/authorization-data.service.ts @@ -10,7 +10,7 @@ import { SiteDataService } from '../site-data.service'; import { followLink, FollowLinkConfig } from '../../../shared/utils/follow-link-config.model'; import { RemoteData } from '../remote-data'; import { PaginatedList } from '../paginated-list.model'; -import { catchError, map, switchMap } from 'rxjs/operators'; +import { catchError, map, switchMap, take } from 'rxjs/operators'; import { hasNoValue, hasValue, isNotEmpty } from '../../../shared/empty.util'; import { RequestParam } from '../../cache/models/request-param.model'; import { AuthorizationSearchParams } from './authorization-search-params'; @@ -52,6 +52,19 @@ export class AuthorizationDataService extends BaseDataService imp this.requestService.setStaleByHrefSubstring(this.linkPath); } + /** + * This method invalidates the cache for a given authorization feature and a given item url. + * + * @param featureID + * @param objectUrl + */ + invalidateAuthorization(featureID?: FeatureID, objectUrl?: string) { + this.searchData.getSearchByHref(this.searchByObjectPath, this.createSearchOptions(objectUrl, {}, null, featureID)) + .pipe( + take(1) + ).subscribe(url => this.requestService.setStaleByHrefSubstring(url)); + } + /** * Checks if an {@link EPerson} (or anonymous) has access to a specific object within a {@link Feature} * @param objectUrl URL to the object to search {@link Authorization}s for. diff --git a/src/app/core/data/version-data.service.ts b/src/app/core/data/version-data.service.ts index 67c249fe0ae..cbad9a3c4a5 100644 --- a/src/app/core/data/version-data.service.ts +++ b/src/app/core/data/version-data.service.ts @@ -18,6 +18,7 @@ import { DefaultChangeAnalyzer } from './default-change-analyzer.service'; import { IdentifiableDataService } from './base/identifiable-data.service'; import { dataService } from './base/data-service.decorator'; import { Operation } from 'fast-json-patch'; +import { Item } from '../shared/item.model'; /** * Service responsible for handling requests related to the Version object @@ -99,4 +100,14 @@ export class VersionDataService extends IdentifiableDataService impleme return this.patchData.createPatchFromCache(object); } + + /** + * Invalidates the cache of the version link for this item. + * + * @param item + */ + invalidateVersionHrefCache(item: Item): void { + this.requestService.setStaleByHrefSubstring(item._links.version.href); + } + } diff --git a/src/app/shared/context-menu/item-version/item-version-menu.component.ts b/src/app/shared/context-menu/item-version/item-version-menu.component.ts index 22e7aa42ddc..d5b91fac1bc 100644 --- a/src/app/shared/context-menu/item-version/item-version-menu.component.ts +++ b/src/app/shared/context-menu/item-version/item-version-menu.component.ts @@ -1,6 +1,6 @@ import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; -import { BehaviorSubject, combineLatest, distinctUntilChanged, map, shareReplay, Subscription } from 'rxjs'; +import { BehaviorSubject, combineLatest, distinctUntilChanged, map, Subscription } from 'rxjs'; import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model'; import { DSpaceObject } from '../../../core/shared/dspace-object.model'; @@ -61,8 +61,7 @@ export class ItemVersionMenuComponent extends ContextMenuEntryComponent implemen this.sub = combineLatest([isAuthorized$, isDisabled$]).pipe( map(([isAuthorized, isDisabled]) => isAuthorized && !isDisabled), - distinctUntilChanged(), - shareReplay(1) + distinctUntilChanged() ).subscribe((canShow) => { this.canShow$.next(canShow); }); diff --git a/src/app/shared/dso-page/dso-versioning-modal-service/dso-versioning-modal.service.ts b/src/app/shared/dso-page/dso-versioning-modal-service/dso-versioning-modal.service.ts index e66a6f5e146..d48ee93380c 100644 --- a/src/app/shared/dso-page/dso-versioning-modal-service/dso-versioning-modal.service.ts +++ b/src/app/shared/dso-page/dso-versioning-modal-service/dso-versioning-modal.service.ts @@ -18,6 +18,8 @@ import { } from '../../../item-page/versions/item-versions-summary-modal/item-versions-summary-modal.component'; import { EditItemDataService } from '../../../core/submission/edititem-data.service'; import { fromPromise } from 'rxjs/internal/observable/innerFrom'; +import { FeatureID } from '../../../core/data/feature-authorization/feature-id'; +import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; /** * Service to take care of all the functionality related to the version creation modal @@ -37,6 +39,7 @@ export class DsoVersioningModalService { protected workspaceItemDataService: WorkspaceitemDataService, protected itemService: ItemDataService, protected editItemService: EditItemDataService, + protected authorizationService: AuthorizationDataService, ) { } @@ -76,7 +79,13 @@ export class DsoVersioningModalService { getFirstSucceededRemoteDataPayload(), map((wsItem: WorkspaceItem) => `workspaceitems/${wsItem?.id}/edit`), switchMap((route: string) => fromPromise(this.router.navigateByUrl(route))), - ).subscribe(() => this.editItemService.invalidateItemCache(item.uuid)); + ).subscribe(() => this.invalidateCacheFor(item)); + } + + private invalidateCacheFor(previousItem: Item) { + this.versionService.invalidateVersionHrefCache(previousItem); + this.authorizationService.invalidateAuthorization(FeatureID.CanCreateVersion, previousItem.self); + this.editItemService.invalidateItemCache(previousItem.uuid); } /**