diff --git a/src/app/core/cache/object-cache.effects.spec.ts b/src/app/core/cache/object-cache.effects.spec.ts index 3a50a5dbc7..cc518c0bf2 100644 --- a/src/app/core/cache/object-cache.effects.spec.ts +++ b/src/app/core/cache/object-cache.effects.spec.ts @@ -5,16 +5,20 @@ import { cold, hot } from 'jasmine-marbles'; import { ObjectCacheEffects } from './object-cache.effects'; import { ResetObjectCacheTimestampsAction } from './object-cache.actions'; import { StoreActionTypes } from '../../store.actions'; +import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service'; describe('ObjectCacheEffects', () => { let cacheEffects: ObjectCacheEffects; let actions: Observable; const timestamp = 10000; + const authorizationService = jasmine.createSpyObj(['invalidateAuthorizationsRequestCache']); + beforeEach(() => { TestBed.configureTestingModule({ providers: [ ObjectCacheEffects, provideMockActions(() => actions), + { provide: AuthorizationDataService, useValue: authorizationService }, // other providers ], }); @@ -33,6 +37,7 @@ describe('ObjectCacheEffects', () => { const expected = cold('--b-', { b: new ResetObjectCacheTimestampsAction(new Date().getTime()) }); expect(cacheEffects.fixTimestampsOnRehydrate).toBeObservable(expected); + expect((cacheEffects as any).authorizationsService.invalidateAuthorizationsRequestCache).toHaveBeenCalled(); }); }); }); diff --git a/src/app/core/cache/object-cache.effects.ts b/src/app/core/cache/object-cache.effects.ts index 2bd8ad0e3c..79b0680406 100644 --- a/src/app/core/cache/object-cache.effects.ts +++ b/src/app/core/cache/object-cache.effects.ts @@ -1,9 +1,10 @@ -import { map } from 'rxjs/operators'; +import { map, tap } from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { Actions, Effect, ofType } from '@ngrx/effects'; import { StoreActionTypes } from '../../store.actions'; import { ResetObjectCacheTimestampsAction } from './object-cache.actions'; +import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service'; @Injectable() export class ObjectCacheEffects { @@ -18,10 +19,11 @@ export class ObjectCacheEffects { */ @Effect() fixTimestampsOnRehydrate = this.actions$ .pipe(ofType(StoreActionTypes.REHYDRATE), - map(() => new ResetObjectCacheTimestampsAction(new Date().getTime())) + map(() => new ResetObjectCacheTimestampsAction(new Date().getTime())), + tap(() => this.authorizationsService.invalidateAuthorizationsRequestCache()) ); - constructor(private actions$: Actions) { + constructor(private actions$: Actions, private authorizationsService: AuthorizationDataService) { } } diff --git a/src/app/core/data/feature-authorization/authorization-data.service.spec.ts b/src/app/core/data/feature-authorization/authorization-data.service.spec.ts index 23457b8409..01bd23d7c7 100644 --- a/src/app/core/data/feature-authorization/authorization-data.service.spec.ts +++ b/src/app/core/data/feature-authorization/authorization-data.service.spec.ts @@ -21,6 +21,10 @@ describe('AuthorizationDataService', () => { let site: Site; let ePerson: EPerson; + const requestService = jasmine.createSpyObj('requestService', { + setStaleByHrefSubstring: jasmine.createSpy('setStaleByHrefSubstring') + }); + function init() { site = Object.assign(new Site(), { id: 'test-site', @@ -39,7 +43,7 @@ describe('AuthorizationDataService', () => { isAuthenticated: () => observableOf(true), getAuthenticatedUserFromStore: () => observableOf(ePerson) } as AuthService; - service = new AuthorizationDataService(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, authService, siteService); + service = new AuthorizationDataService(requestService, undefined, undefined, undefined, undefined, undefined, undefined, undefined, authService, siteService); } beforeEach(() => { @@ -47,6 +51,11 @@ describe('AuthorizationDataService', () => { spyOn(service, 'searchBy').and.returnValue(observableOf(undefined)); }); + it('should call setStaleByHrefSubstring method', () => { + service.invalidateAuthorizationsRequestCache(); + expect((service as any).requestService.setStaleByHrefSubstring).toHaveBeenCalledWith((service as any).linkPath); + }); + describe('searchByObject', () => { const objectUrl = 'fake-object-url'; const ePersonUuid = 'fake-eperson-uuid'; 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 170e82f5f8..b9812cdbb3 100644 --- a/src/app/core/data/feature-authorization/authorization-data.service.ts +++ b/src/app/core/data/feature-authorization/authorization-data.service.ts @@ -51,6 +51,13 @@ export class AuthorizationDataService extends DataService { super(); } + /** + * Set all authorization requests to stale + */ + invalidateAuthorizationsRequestCache() { + this.requestService.setStaleByHrefSubstring(this.linkPath); + } + /** * 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.