[ADF-2601] added permission check to info editing button (#3177)

* [ADF-2601] added permission check to info editing button

* [ADF-2601] added test for node permission check on the content metadata card

* [ADF-2601] used enum instead of string for test
This commit is contained in:
Vito 2018-04-17 20:34:14 +01:00 committed by Eugenio Romano
parent ee9393caf0
commit fabb6f4450
4 changed files with 33 additions and 9 deletions

View File

@ -11,7 +11,7 @@
</mat-card-content>
<mat-card-footer class="adf-content-metadata-card-footer" fxLayout="row" fxLayoutAlign="space-between stretch">
<div>
<button *ngIf="!readOnly"
<button *ngIf="!readOnly && hasPermission()"
mat-icon-button
(click)="toggleEdit()"
[attr.title]="'CORE.METADATA.ACTIONS.EDIT' | translate"

View File

@ -28,6 +28,7 @@ import { BasicPropertiesService } from '../../services/basic-properties.service'
import { PropertyGroupTranslatorService } from '../../services/property-groups-translator.service';
import { PropertyDescriptorsService } from '../../services/property-descriptors.service';
import { ContentMetadataConfigFactory } from '../../services/config/content-metadata-config.factory';
import { ContentService, PermissionsEnum } from '@alfresco/adf-core';
describe('ContentMetadataCardComponent', () => {
@ -53,7 +54,8 @@ describe('ContentMetadataCardComponent', () => {
BasicPropertiesService,
PropertyGroupTranslatorService,
ContentMetadataConfigFactory,
PropertyDescriptorsService
PropertyDescriptorsService,
ContentService
]
}).compileComponents();
}));
@ -139,6 +141,7 @@ describe('ContentMetadataCardComponent', () => {
it('should toggle editable by clicking on the button', () => {
component.editable = true;
component.node.allowableOperations = [PermissionsEnum.UPDATE];
fixture.detectChanges();
const button = fixture.debugElement.query(By.css('[data-automation-id="mata-data-card-toggle-edit"]'));
@ -177,16 +180,29 @@ describe('ContentMetadataCardComponent', () => {
expect(buttonLabel.nativeElement.innerText.trim()).toBe('ADF_VIEWER.SIDEBAR.METADATA.LESS_INFORMATION');
});
it('should show the edit button by default', () => {
const button = fixture.debugElement.query(By.css('[data-automation-id="mata-data-card-toggle-edit"]'));
expect(button).not.toBeNull();
});
it('should hode the edit button in readOnly is true', () => {
it('should hide the edit button in readOnly is true', () => {
component.readOnly = true;
fixture.detectChanges();
const button = fixture.debugElement.query(By.css('[data-automation-id="mata-data-card-toggle-edit"]'));
expect(button).toBeNull();
});
it('should hide the edit button if node does not have `update` permissions', () => {
component.readOnly = false;
component.node.allowableOperations = null;
fixture.detectChanges();
const button = fixture.debugElement.query(By.css('[data-automation-id="mata-data-card-toggle-edit"]'));
expect(button).toBeNull();
});
it('should show the edit button if node does has `update` permissions', () => {
component.readOnly = false;
component.node.allowableOperations = [PermissionsEnum.UPDATE];
fixture.detectChanges();
const button = fixture.debugElement.query(By.css('[data-automation-id="mata-data-card-toggle-edit"]'));
expect(button).not.toBeNull();
});
});

View File

@ -17,6 +17,7 @@
import { Component, Input, ViewEncapsulation } from '@angular/core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { ContentService, PermissionsEnum } from '@alfresco/adf-core';
@Component({
selector: 'adf-content-metadata-card',
@ -44,6 +45,9 @@ export class ContentMetadataCardComponent {
editable: boolean = false;
expanded: boolean = false;
constructor(private contentService: ContentService) {
}
toggleEdit(): void {
this.editable = !this.editable;
}
@ -51,4 +55,8 @@ export class ContentMetadataCardComponent {
toggleExpanded(): void {
this.expanded = !this.expanded;
}
hasPermission() {
return this.contentService.hasPermission(this.node, PermissionsEnum.UPDATE);
}
}

View File

@ -374,7 +374,7 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
toggleSidebar() {
this.showSidebar = !this.showSidebar;
if (this.showSidebar && this.fileNodeId) {
this.apiService.getInstance().nodes.getNodeInfo(this.fileNodeId)
this.apiService.getInstance().nodes.getNodeInfo(this.fileNodeId, {include: ['allowableOperations']})
.then((data: MinimalNodeEntryEntity) => {
this.sidebarTemplateContext.node = data;
});