mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[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:
parent
ee9393caf0
commit
fabb6f4450
@ -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"
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user