diff --git a/scilog/src/app/logbook/core/snippet/snippet.component.html b/scilog/src/app/logbook/core/snippet/snippet.component.html index d0c3f27a..4109e959 100644 --- a/scilog/src/app/logbook/core/snippet/snippet.component.html +++ b/scilog/src/app/logbook/core/snippet/snippet.component.html @@ -16,11 +16,11 @@ info Info - - @@ -33,7 +33,7 @@ Reply - - - - - diff --git a/scilog/src/app/overview/logbook-cover/logbook-cover.component.spec.ts b/scilog/src/app/overview/logbook-cover/logbook-cover.component.spec.ts index 0294bfcc..966eafbc 100644 --- a/scilog/src/app/overview/logbook-cover/logbook-cover.component.spec.ts +++ b/scilog/src/app/overview/logbook-cover/logbook-cover.component.spec.ts @@ -73,24 +73,10 @@ describe('LogbookWidgetComponent', () => { }); - [ - {input: ['roles'], output: ['updateRole']}, - {input: ['updateRole'], output: []}, - {input: ['admin'], output: []} - ].forEach((t, i) => { - it(`should test enable members ${i}`, () => { - component['userPreferences'].userInfo.roles = t.input; - const groups = component['enabledMembers']('update'); - expect(groups).toEqual(t.output); - if (t.output.length > 0) - expect(component.tooltips.update).toEqual(`Enabled for members of '${t.output.concat('admin')}'`); - }); - }); - it('should test enableActions', () => { + const isAnyEditAllowedSpy = spyOn(component['isActionAllowed'], 'isAnyEditAllowed'); component['enableActions'](); - expect(component.tooltips.update).toEqual(`Enabled for members of 'updateRole,admin'`); - expect(component.tooltips.delete).toEqual(`Enabled for members of 'deleteRole,admin'`); - expect(component.tooltips.edit).toEqual(`Enabled for members of 'updateRole,deleteRole,admin'`); + expect(isAnyEditAllowedSpy).toHaveBeenCalledTimes(1); }); + }); diff --git a/scilog/src/app/overview/logbook-cover/logbook-cover.component.ts b/scilog/src/app/overview/logbook-cover/logbook-cover.component.ts index 7ed603a5..8cbd5037 100644 --- a/scilog/src/app/overview/logbook-cover/logbook-cover.component.ts +++ b/scilog/src/app/overview/logbook-cover/logbook-cover.component.ts @@ -1,13 +1,14 @@ import { Component, OnInit, EventEmitter, Output, Input, ViewChild, ElementRef } from '@angular/core'; -import { UserPreferencesService } from '@shared/user-preferences.service'; import { Logbooks } from '@model/logbooks'; import { LogbookInfoService } from '@shared/logbook-info.service'; import { LogbookItemDataService } from '@shared/remote-data.service'; +import { IsAllowedService } from '../is-allowed.service'; @Component({ selector: 'app-logbook-cover', templateUrl: './logbook-cover.component.html', - styleUrls: ['./logbook-cover.component.css'] + styleUrls: ['./logbook-cover.component.css'], + providers: [IsAllowedService] }) export class LogbookWidgetComponent implements OnInit { @@ -22,12 +23,11 @@ export class LogbookWidgetComponent implements OnInit { imageToShow: any; isImageLoading: boolean; - tooltips: {edit?: string, update?: string, delete?: string} = {}; constructor( private logbookItemDataService: LogbookItemDataService, - private userPreferences: UserPreferencesService, - private logbookInfo: LogbookInfoService) { } + private logbookInfo: LogbookInfoService, + protected isActionAllowed: IsAllowedService) { } ngOnInit(): void { if (this.logbook?.thumbnail) { @@ -36,23 +36,9 @@ export class LogbookWidgetComponent implements OnInit { this.enableActions(); } - private enabledMembers(action: string): string[] { - const aclMembers = this.logbook?.[`${action}ACL`]; - if (this.userPreferences.userInfo?.roles.some((entry: string) => - aclMembers?.includes?.(entry) || entry === 'admin' - )) - return []; - this.tooltips[action] = `Enabled for members of '${aclMembers.filter((m: string) => m != 'admin').concat('admin')}'`; - return aclMembers; - } - private enableActions() { - const groups = ['update', 'delete'].reduce((previousValue, currentValue) => - previousValue.concat(this.enabledMembers(currentValue)), - [] - ) - if (groups.length > 0) - this.tooltips.edit = `Enabled for members of '${[...new Set(groups.concat('admin'))]}'`; + this.isActionAllowed.snippet = this.logbook; + this.isActionAllowed.isAnyEditAllowed(); } ngAfterViewInit() {