Skip to content

Commit

Permalink
Avoid checking for expiration on tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Mar 25, 2024
1 parent 34b91c0 commit e884a02
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
4 changes: 2 additions & 2 deletions scilog/src/app/logbook/core/task/task.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe('TaskComponent', () => {
const canUpdateSpy = spyOn(component['isActionAllowed'], 'canUpdate');
const canDeleteSpy = spyOn(component['isActionAllowed'], 'canDelete');
component.isAllowed();
expect(canUpdateSpy).toHaveBeenCalledTimes(1);
expect(canDeleteSpy).toHaveBeenCalledTimes(1);
expect(canUpdateSpy).toHaveBeenCalledOnceWith(false);
expect(canDeleteSpy).toHaveBeenCalledOnceWith(false);
});

});
4 changes: 2 additions & 2 deletions scilog/src/app/logbook/core/task/task.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class TaskComponent implements OnInit {
}

isAllowed() {
this.isActionAllowed.canDelete();
this.isActionAllowed.canUpdate();
this.isActionAllowed.canDelete(false);
this.isActionAllowed.canUpdate(false);
}

}
24 changes: 23 additions & 1 deletion scilog/src/app/overview/is-allowed.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,27 @@ describe('IsAllowedService', () => {
service['cascadeExpiration']('update');
});
});


[
[true, 1],
[false, 0]
].forEach((t, i) => {
it(`should test canDelete ${i}`, () => {
const cascadeExpirationSpy = spyOn<any>(service, 'cascadeExpiration');
service.canDelete(t[0] as boolean);
expect(cascadeExpirationSpy).toHaveBeenCalledTimes(t[1] as number);
});
});

[
[true, 1],
[false, 0]
].forEach((t, i) => {
it(`should test canUpdate ${i}`, () => {
const cascadeExpirationSpy = spyOn<any>(service, 'cascadeExpiration');
service.canUpdate(t[0] as boolean);
expect(cascadeExpirationSpy).toHaveBeenCalledTimes(t[1] as number);
});
});

});
10 changes: 5 additions & 5 deletions scilog/src/app/overview/is-allowed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class IsAllowedService {
private otherEnabledMembers(action: string): string[] {
const aclMembers = (this.snippet?.[`${action}ACL`] ?? []).filter(
(m: string) => m != 'admin').concat('admin');
if (this.userPreferences.userInfo?.roles.some((entry: string) =>
if (this.userPreferences.userInfo?.roles?.some((entry: string) =>
aclMembers?.includes?.(entry)
))
return [];
Expand Down Expand Up @@ -77,8 +77,8 @@ export class IsAllowedService {
return false
}

canUpdate() {
return this.cascadeExpiration('update')
canUpdate(checkExpiration=true) {
return checkExpiration? this.cascadeExpiration('update'): this.isUserAllowed('update')
}

private cascadeExpiration(action: string) {
Expand All @@ -90,7 +90,7 @@ export class IsAllowedService {
return false;
}

canDelete() {
return this.cascadeExpiration('delete')
canDelete(checkExpiration=true) {
return checkExpiration? this.cascadeExpiration('delete'): this.isUserAllowed('delete')
}
}

0 comments on commit e884a02

Please sign in to comment.