Skip to content

Commit

Permalink
[DSC-1184] Fixes visualization of item-version-menu on original item
Browse files Browse the repository at this point in the history
  • Loading branch information
vins01-4science committed Nov 13, 2023
1 parent 6e05504 commit ee31149
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -52,6 +52,19 @@ export class AuthorizationDataService extends BaseDataService<Authorization> 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.
Expand Down
11 changes: 11 additions & 0 deletions src/app/core/data/version-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,4 +100,14 @@ export class VersionDataService extends IdentifiableDataService<Version> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +39,7 @@ export class DsoVersioningModalService {
protected workspaceItemDataService: WorkspaceitemDataService,
protected itemService: ItemDataService,
protected editItemService: EditItemDataService,
protected authorizationService: AuthorizationDataService,
) {
}

Expand Down Expand Up @@ -76,7 +79,13 @@ export class DsoVersioningModalService {
getFirstSucceededRemoteDataPayload<WorkspaceItem>(),
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);
}

/**
Expand Down

0 comments on commit ee31149

Please sign in to comment.