forked from hazza/dspace-angular
Invalidate authorization requests cache on REHYDRATE
This commit is contained in:
@@ -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<any>;
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
8
src/app/core/cache/object-cache.effects.ts
vendored
8
src/app/core/cache/object-cache.effects.ts
vendored
@@ -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) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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';
|
||||
|
@@ -51,6 +51,13 @@ export class AuthorizationDataService extends DataService<Authorization> {
|
||||
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.
|
||||
|
Reference in New Issue
Block a user