Skip to content

Commit

Permalink
Merged in DSC-1184 (pull request DSpace#1009)
Browse files Browse the repository at this point in the history
DSC-1184

Approved-by: Giuseppe Digilio
  • Loading branch information
vins01-4science authored and atarix83 committed Nov 14, 2023
2 parents e0a9e40 + 87085e1 commit efe0a5e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 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 @@ -19,6 +19,7 @@ describe('DsoVersioningModalService', () => {
let workspaceItemDataService;
let itemService;
let editItemService;
let authorizationService;

const mockItem: Item = Object.assign(new Item(), {
bundles: createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [])),
Expand Down Expand Up @@ -50,6 +51,7 @@ describe('DsoVersioningModalService', () => {
workspaceItemDataService = jasmine.createSpyObj('workspaceItemDataService', ['findByItem']);
itemService = jasmine.createSpyObj('itemService', ['findByHref']);
editItemService = jasmine.createSpyObj('editItemService', ['invalidateItemCache']);
authorizationService = jasmine.createSpyObj('authorizationService', ['invalidateAuthorization']);

service = new DsoVersioningModalService(
modalService,
Expand All @@ -58,8 +60,9 @@ describe('DsoVersioningModalService', () => {
itemVersionShared,
router,
workspaceItemDataService,
itemService,
editItemService,
itemService,
editItemService,
authorizationService,
);
}));
describe('when onCreateNewVersion() is called', () => {
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 efe0a5e

Please sign in to comment.