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 { ObjectCacheEffects } from './object-cache.effects';
|
||||||
import { ResetObjectCacheTimestampsAction } from './object-cache.actions';
|
import { ResetObjectCacheTimestampsAction } from './object-cache.actions';
|
||||||
import { StoreActionTypes } from '../../store.actions';
|
import { StoreActionTypes } from '../../store.actions';
|
||||||
|
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
|
||||||
|
|
||||||
describe('ObjectCacheEffects', () => {
|
describe('ObjectCacheEffects', () => {
|
||||||
let cacheEffects: ObjectCacheEffects;
|
let cacheEffects: ObjectCacheEffects;
|
||||||
let actions: Observable<any>;
|
let actions: Observable<any>;
|
||||||
const timestamp = 10000;
|
const timestamp = 10000;
|
||||||
|
const authorizationService = jasmine.createSpyObj(['invalidateAuthorizationsRequestCache']);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
ObjectCacheEffects,
|
ObjectCacheEffects,
|
||||||
provideMockActions(() => actions),
|
provideMockActions(() => actions),
|
||||||
|
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||||
// other providers
|
// other providers
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -33,6 +37,7 @@ describe('ObjectCacheEffects', () => {
|
|||||||
const expected = cold('--b-', { b: new ResetObjectCacheTimestampsAction(new Date().getTime()) });
|
const expected = cold('--b-', { b: new ResetObjectCacheTimestampsAction(new Date().getTime()) });
|
||||||
|
|
||||||
expect(cacheEffects.fixTimestampsOnRehydrate).toBeObservable(expected);
|
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 { Injectable } from '@angular/core';
|
||||||
import { Actions, Effect, ofType } from '@ngrx/effects';
|
import { Actions, Effect, ofType } from '@ngrx/effects';
|
||||||
|
|
||||||
import { StoreActionTypes } from '../../store.actions';
|
import { StoreActionTypes } from '../../store.actions';
|
||||||
import { ResetObjectCacheTimestampsAction } from './object-cache.actions';
|
import { ResetObjectCacheTimestampsAction } from './object-cache.actions';
|
||||||
|
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ObjectCacheEffects {
|
export class ObjectCacheEffects {
|
||||||
@@ -18,10 +19,11 @@ export class ObjectCacheEffects {
|
|||||||
*/
|
*/
|
||||||
@Effect() fixTimestampsOnRehydrate = this.actions$
|
@Effect() fixTimestampsOnRehydrate = this.actions$
|
||||||
.pipe(ofType(StoreActionTypes.REHYDRATE),
|
.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 site: Site;
|
||||||
let ePerson: EPerson;
|
let ePerson: EPerson;
|
||||||
|
|
||||||
|
const requestService = jasmine.createSpyObj('requestService', {
|
||||||
|
setStaleByHrefSubstring: jasmine.createSpy('setStaleByHrefSubstring')
|
||||||
|
});
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
site = Object.assign(new Site(), {
|
site = Object.assign(new Site(), {
|
||||||
id: 'test-site',
|
id: 'test-site',
|
||||||
@@ -39,7 +43,7 @@ describe('AuthorizationDataService', () => {
|
|||||||
isAuthenticated: () => observableOf(true),
|
isAuthenticated: () => observableOf(true),
|
||||||
getAuthenticatedUserFromStore: () => observableOf(ePerson)
|
getAuthenticatedUserFromStore: () => observableOf(ePerson)
|
||||||
} as AuthService;
|
} 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(() => {
|
beforeEach(() => {
|
||||||
@@ -47,6 +51,11 @@ describe('AuthorizationDataService', () => {
|
|||||||
spyOn(service, 'searchBy').and.returnValue(observableOf(undefined));
|
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', () => {
|
describe('searchByObject', () => {
|
||||||
const objectUrl = 'fake-object-url';
|
const objectUrl = 'fake-object-url';
|
||||||
const ePersonUuid = 'fake-eperson-uuid';
|
const ePersonUuid = 'fake-eperson-uuid';
|
||||||
|
@@ -51,6 +51,13 @@ export class AuthorizationDataService extends DataService<Authorization> {
|
|||||||
super();
|
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}
|
* 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.
|
* @param objectUrl URL to the object to search {@link Authorization}s for.
|
||||||
|
Reference in New Issue
Block a user