rename old hasPermission as allowableOperation and introduce the real hasPermissions (#4294)

This commit is contained in:
Eugenio Romano
2019-02-11 10:44:37 +00:00
committed by GitHub
parent 324e86aaf3
commit 3263659ac2
39 changed files with 256 additions and 178 deletions

View File

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

View File

@@ -20,7 +20,7 @@ import { By } from '@angular/platform-browser';
import { Node } from '@alfresco/js-api';
import { ContentMetadataCardComponent } from './content-metadata-card.component';
import { ContentMetadataComponent } from '../content-metadata/content-metadata.component';
import { setupTestBed, PermissionsEnum } from '@alfresco/adf-core';
import { setupTestBed, AllowableOperationsEnum } from '@alfresco/adf-core';
import { ContentTestingModule } from '../../../testing/content.testing.module';
describe('ContentMetadataCardComponent', () => {
@@ -125,7 +125,7 @@ describe('ContentMetadataCardComponent', () => {
it('should toggle editable by clicking on the button', () => {
component.editable = true;
component.node.allowableOperations = [PermissionsEnum.UPDATE];
component.node.allowableOperations = [AllowableOperationsEnum.UPDATE];
fixture.detectChanges();
const button = fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]'));
@@ -183,7 +183,7 @@ describe('ContentMetadataCardComponent', () => {
it('should show the edit button if node does has `update` permissions', () => {
component.readOnly = false;
component.node.allowableOperations = [PermissionsEnum.UPDATE];
component.node.allowableOperations = [AllowableOperationsEnum.UPDATE];
fixture.detectChanges();
const button = fixture.debugElement.query(By.css('[data-automation-id="meta-data-card-toggle-edit"]'));

View File

@@ -17,7 +17,7 @@
import { Component, Input, ViewEncapsulation } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { ContentService, PermissionsEnum } from '@alfresco/adf-core';
import { ContentService, AllowableOperationsEnum } from '@alfresco/adf-core';
@Component({
selector: 'adf-content-metadata-card',
@@ -89,7 +89,7 @@ export class ContentMetadataCardComponent {
this.expanded = !this.expanded;
}
hasPermission() {
return this.contentService.hasPermission(this.node, PermissionsEnum.UPDATE);
hasAllowableOperations() {
return this.contentService.hasAllowableOperations(this.node, AllowableOperationsEnum.UPDATE);
}
}

View File

@@ -21,7 +21,7 @@ import { ContentService } from '@alfresco/adf-core';
import { Subject, Observable, throwError } from 'rxjs';
import { ShareDataRow } from '../document-list/data/share-data-row.model';
import { Node, NodeEntry, SitePaging } from '@alfresco/js-api';
import { DataColumn, SitesService, TranslationService, PermissionsEnum } from '@alfresco/adf-core';
import { DataColumn, SitesService, TranslationService, AllowableOperationsEnum } from '@alfresco/adf-core';
import { DocumentListService } from '../document-list/services/document-list.service';
import { ContentNodeSelectorComponent } from './content-node-selector.component';
import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface';
@@ -71,7 +71,7 @@ export class ContentNodeDialogService {
public openLockNodeDialog(contentEntry: Node): Subject<string> {
const observable: Subject<string> = new Subject<string>();
if (this.contentService.hasPermission(contentEntry, PermissionsEnum.LOCK)) {
if (this.contentService.hasAllowableOperations(contentEntry, AllowableOperationsEnum.LOCK)) {
this.dialog.open(NodeLockDialogComponent, {
data: {
node: contentEntry,
@@ -129,7 +129,7 @@ export class ContentNodeDialogService {
* @returns Information about files that were copied/moved
*/
openCopyMoveDialog(action: string, contentEntry: Node, permission?: string, excludeSiteContent?: string[]): Observable<Node[]> {
if (this.contentService.hasPermission(contentEntry, permission)) {
if (this.contentService.hasAllowableOperations(contentEntry, permission)) {
const select = new Subject<Node[]>();
select.subscribe({
@@ -185,7 +185,7 @@ export class ContentNodeDialogService {
actionName: action,
currentFolderId: contentEntry.id,
imageResolver: this.imageResolver.bind(this),
isSelectionValid: this.hasPermissionOnNodeFolder.bind(this),
isSelectionValid: this.hasAllowableOperationsOnNodeFolder.bind(this),
where: '(isFolder=true)',
select: select
};
@@ -225,7 +225,7 @@ export class ContentNodeDialogService {
private imageResolver(row: ShareDataRow, col: DataColumn): string | null {
const entry: Node = row.node.entry;
if (!this.contentService.hasPermission(entry, 'create')) {
if (!this.contentService.hasAllowableOperations(entry, 'create')) {
return this.documentListService.getMimeTypeIcon('disable/folder');
}
@@ -236,8 +236,8 @@ export class ContentNodeDialogService {
return entry.isFile;
}
private hasPermissionOnNodeFolder(entry: Node): boolean {
return this.isNodeFolder(entry) && this.contentService.hasPermission(entry, 'create');
private hasAllowableOperationsOnNodeFolder(entry: Node): boolean {
return this.isNodeFolder(entry) && this.contentService.hasAllowableOperations(entry, 'create');
}
private isNodeFolder(entry: Node): boolean {
@@ -249,7 +249,7 @@ export class ContentNodeDialogService {
}
private hasEntityCreatePermission(entry: Node): boolean {
return this.contentService.hasPermission(entry, 'create');
return this.contentService.hasAllowableOperations(entry, 'create');
}
private isSite(entry) {

View File

@@ -782,10 +782,10 @@ describe('ContentNodeSelectorComponent', () => {
const entry: Node = <Node> {};
const nodePage: NodePaging = <NodePaging> { list: {}, pagination: {} };
let hasPermission;
let hasAllowableOperations;
function returnHasPermission(): boolean {
return hasPermission;
return hasAllowableOperations;
}
beforeEach(() => {
@@ -800,7 +800,7 @@ describe('ContentNodeSelectorComponent', () => {
});
it('should NOT be null after selecting node with the necessary permissions', async(() => {
hasPermission = true;
hasAllowableOperations = true;
component.documentList.folderNode = entry;
component.select.subscribe((nodes) => {
@@ -814,7 +814,7 @@ describe('ContentNodeSelectorComponent', () => {
}));
it('should be null after selecting node without the necessary permissions', async(() => {
hasPermission = false;
hasAllowableOperations = false;
component.documentList.folderNode = entry;
component.select.subscribe((nodes) => {
@@ -828,7 +828,7 @@ describe('ContentNodeSelectorComponent', () => {
}));
it('should NOT be null after clicking on a node (with the right permissions) in the list (onNodeSelect)', async(() => {
hasPermission = true;
hasAllowableOperations = true;
component.select.subscribe((nodes) => {
expect(nodes).toBeDefined();
@@ -841,7 +841,7 @@ describe('ContentNodeSelectorComponent', () => {
}));
it('should remain null when clicking on a node (with the WRONG permissions) in the list (onNodeSelect)', async(() => {
hasPermission = false;
hasAllowableOperations = false;
component.select.subscribe((nodes) => {
expect(nodes).toBeDefined();
@@ -856,7 +856,7 @@ describe('ContentNodeSelectorComponent', () => {
it('should become null when clicking on a node (with the WRONG permissions) after previously selecting a right node', async(() => {
component.select.subscribe((nodes) => {
if (hasPermission) {
if (hasAllowableOperations) {
expect(nodes).toBeDefined();
expect(nodes).not.toBeNull();
expect(component.chosenNode).not.toBeNull();
@@ -868,17 +868,17 @@ describe('ContentNodeSelectorComponent', () => {
}
});
hasPermission = true;
hasAllowableOperations = true;
component.onNodeSelect({ detail: { node: { entry } } });
fixture.detectChanges();
hasPermission = false;
hasAllowableOperations = false;
component.onNodeSelect({ detail: { node: { entry } } });
fixture.detectChanges();
}));
it('should be null when the chosenNode is reset', async(() => {
hasPermission = true;
hasAllowableOperations = true;
component.onNodeSelect({ detail: { node: { entry: <Node> {} } } });
fixture.detectChanges();

View File

@@ -123,7 +123,7 @@ export class ShareDialogComponent implements OnInit, OnDestroy {
}
get canUpdate() {
return this.contentService.hasPermission(this.data.node.entry, 'update');
return this.contentService.hasAllowableOperations(this.data.node.entry, 'update');
}
private openConfirmationDialog() {

View File

@@ -19,7 +19,7 @@
import { Directive, ElementRef, Renderer2, HostListener, Input, AfterViewInit } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { PermissionsEnum, ContentService } from '@alfresco/adf-core';
import { AllowableOperationsEnum, ContentService } from '@alfresco/adf-core';
import { ContentNodeDialogService } from '../content-node-selector/content-node-dialog.service';
@Directive({
@@ -45,7 +45,7 @@ export class NodeLockDirective implements AfterViewInit {
) {}
ngAfterViewInit() {
const hasPermission = this.contentService.hasPermission(this.node, PermissionsEnum.LOCK);
this.renderer.setProperty(this.element.nativeElement, 'disabled', !hasPermission);
const hasAllowableOperations = this.contentService.hasAllowableOperations(this.node, AllowableOperationsEnum.LOCK);
this.renderer.setProperty(this.element.nativeElement, 'disabled', !hasAllowableOperations);
}
}

View File

@@ -522,7 +522,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
return action.disabled(node);
}
if (action.permission && action.disableWithNoPermission && !this.contentService.hasPermission(node.entry, action.permission)) {
if (action.permission && action.disableWithNoPermission && !this.contentService.hasAllowableOperations(node.entry, action.permission)) {
return true;
}

View File

@@ -54,7 +54,7 @@ export class ShareDataRow implements DataRow {
if (this.applyPermissionStyleToFolder(nodeEntity.entry, currentPermissionsStyle) || this.applyPermissionStyleToFile(nodeEntity.entry, currentPermissionsStyle)) {
if (this.contentService.hasPermission(nodeEntity.entry, currentPermissionsStyle.permission)) {
if (this.contentService.hasAllowableOperations(nodeEntity.entry, currentPermissionsStyle.permission)) {
permissionsClasses += ` ${currentPermissionsStyle.css}`;
}
}
@@ -73,7 +73,7 @@ export class ShareDataRow implements DataRow {
}
isFolderAndHasPermissionToUpload(nodeEntry: NodeEntry): boolean {
return this.isFolder(nodeEntry) && this.contentService.hasPermission(nodeEntry.entry, 'create');
return this.isFolder(nodeEntry) && this.contentService.hasAllowableOperations(nodeEntry.entry, 'create');
}
isFolder(nodeEntry: NodeEntry): boolean {

View File

@@ -15,15 +15,15 @@
* limitations under the License.
*/
import { PermissionsEnum } from '@alfresco/adf-core';
import { AllowableOperationsEnum } from '@alfresco/adf-core';
export class PermissionStyleModel {
css: string;
permission: PermissionsEnum;
permission: AllowableOperationsEnum;
isFolder: boolean = true;
isFile: boolean = true;
constructor(css: string, permission: PermissionsEnum, isFile: boolean = true, isFolder: boolean = true) {
constructor(css: string, permission: AllowableOperationsEnum, isFile: boolean = true, isFolder: boolean = true) {
this.css = css;
this.permission = permission;
this.isFile = isFile;

View File

@@ -122,7 +122,7 @@ export class DocumentActionsService {
let handlerObservable;
if (this.canExecuteAction(node)) {
if (this.contentService.hasPermission(node.entry, permission)) {
if (this.contentService.hasAllowableOperations(node.entry, permission)) {
handlerObservable = this.documentListService.deleteNode(node.entry.id);
handlerObservable.subscribe(() => {
let message = this.translation.instant('CORE.DELETE_NODE.SINGULAR', { name: node.entry.name });

View File

@@ -118,7 +118,7 @@ export class FolderActionsService {
let handlerObservable: Observable<any>;
if (this.canExecuteAction(node)) {
if (this.contentService.hasPermission(node.entry, permission)) {
if (this.contentService.hasAllowableOperations(node.entry, permission)) {
handlerObservable = this.documentListService.deleteNode(node.entry.id);
handlerObservable.subscribe(() => {
if (target && typeof target.reload === 'function') {

View File

@@ -18,7 +18,7 @@
import { Component, ViewEncapsulation, EventEmitter, Input, Output } from '@angular/core';
import { NodeEntry, Node } from '@alfresco/js-api';
import { NodePermissionService } from '../../services/node-permission.service';
import { NodesApiService, ContentService, PermissionsEnum } from '@alfresco/adf-core';
import { NodesApiService, ContentService, AllowableOperationsEnum } from '@alfresco/adf-core';
@Component({
selector: 'adf-add-permission',
@@ -55,12 +55,12 @@ export class AddPermissionComponent {
}
isAddEnabled(): boolean {
return this.contentService.hasPermission(this.currentNode, PermissionsEnum.UPDATEPERMISSIONS) &&
return this.contentService.hasAllowableOperations(this.currentNode, AllowableOperationsEnum.UPDATEPERMISSIONS) &&
this.selectedItems.length !== 0;
}
applySelection() {
if (this.contentService.hasPermission(this.currentNode, PermissionsEnum.UPDATEPERMISSIONS)) {
if (this.contentService.hasAllowableOperations(this.currentNode, AllowableOperationsEnum.UPDATEPERMISSIONS)) {
this.nodePermissionService.updateNodePermissions(this.nodeId, this.selectedItems)
.subscribe(
(node) => {

View File

@@ -17,7 +17,7 @@
/* tslint:disable:no-input-rename */
import { Directive, Input, Output, EventEmitter } from '@angular/core';
import { NodesApiService, ContentService, PermissionsEnum } from '@alfresco/adf-core';
import { NodesApiService, ContentService, AllowableOperationsEnum } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api';
@Directive({
@@ -47,7 +47,7 @@ export class InheritPermissionDirective {
onInheritPermissionClicked() {
this.nodeService.getNode(this.nodeId).subscribe((node: Node) => {
if (this.contentService.hasPermission(node, PermissionsEnum.UPDATEPERMISSIONS)) {
if (this.contentService.hasAllowableOperations(node, AllowableOperationsEnum.UPDATEPERMISSIONS)) {
const nodeBody = { permissions: { isInheritanceEnabled: !node.permissions.isInheritanceEnabled } };
this.nodeService.updateNode(this.nodeId, nodeBody, { include: ['permissions'] }).subscribe((nodeUpdated: Node) => {
this.updated.emit(nodeUpdated);

View File

@@ -22,7 +22,7 @@ import { AddPermissionDialogComponent } from '../components/add-permission/add-p
import { AddPermissionDialogData } from '../components/add-permission/add-permission-dialog-data.interface';
import { NodeEntry, Node } from '@alfresco/js-api';
import { NodePermissionService } from './node-permission.service';
import { ContentService, PermissionsEnum } from '@alfresco/adf-core';
import { ContentService, AllowableOperationsEnum } from '@alfresco/adf-core';
import { switchMap } from 'rxjs/operators';
@Injectable({
@@ -42,7 +42,7 @@ export class NodePermissionDialogService {
* @returns Node with updated permissions
*/
openAddPermissionDialog(node: Node, title?: string): Observable<NodeEntry[]> {
if (this.contentService.hasPermission(node, PermissionsEnum.UPDATEPERMISSIONS)) {
if (this.contentService.hasAllowableOperations(node, AllowableOperationsEnum.UPDATEPERMISSIONS)) {
const confirm = new Subject<NodeEntry[]>();
confirm.subscribe({

View File

@@ -17,7 +17,7 @@
import {
ContentService, EXTENDIBLE_COMPONENT, FileUtils,
LogService, NodePermissionSubject, TranslationService, UploadService, PermissionsEnum
LogService, NodeAllowableOperationSubject, TranslationService, UploadService, AllowableOperationsEnum
} from '@alfresco/adf-core';
import {
Component, EventEmitter, forwardRef, Input,
@@ -37,7 +37,7 @@ import { UploadBase } from './base-upload/upload-base';
],
encapsulation: ViewEncapsulation.None
})
export class UploadButtonComponent extends UploadBase implements OnInit, OnChanges, NodePermissionSubject {
export class UploadButtonComponent extends UploadBase implements OnInit, OnChanges, NodeAllowableOperationSubject {
/** Allows/disallows upload folders (only for Chrome). */
@Input()
@@ -59,7 +59,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
@Output()
permissionEvent: EventEmitter<PermissionModel> = new EventEmitter<PermissionModel>();
private hasPermission: boolean = false;
private hasAllowableOperations: boolean = false;
protected permissionValue: Subject<boolean> = new Subject<boolean>();
@@ -73,7 +73,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
ngOnInit() {
this.permissionValue.subscribe((permission: boolean) => {
this.hasPermission = permission;
this.hasAllowableOperations = permission;
});
}
@@ -91,7 +91,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
onFilesAdded($event: any): void {
let files: File[] = FileUtils.toFileArray($event.currentTarget.files);
if (this.hasPermission) {
if (this.hasAllowableOperations) {
this.uploadFiles(files);
} else {
this.permissionEvent.emit(new PermissionModel({ type: 'content', action: 'upload', permission: 'create' }));
@@ -101,7 +101,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
}
onDirectoryAdded($event: any): void {
if (this.hasPermission) {
if (this.hasAllowableOperations) {
let files: File[] = FileUtils.toFileArray($event.currentTarget.files);
this.uploadFiles(files);
} else {
@@ -119,13 +119,13 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
};
this.contentService.getNode(this.rootFolderId, opts).subscribe(
(res) => this.permissionValue.next(this.nodeHasPermission(res.entry, PermissionsEnum.CREATE)),
(res) => this.permissionValue.next(this.nodeHasPermission(res.entry, AllowableOperationsEnum.CREATE)),
(error) => this.error.emit(error)
);
}
}
nodeHasPermission(node: Node, permission: PermissionsEnum | string): boolean {
return this.contentService.hasPermission(node, permission);
nodeHasPermission(node: Node, permission: AllowableOperationsEnum | string): boolean {
return this.contentService.hasAllowableOperations(node, permission);
}
}

View File

@@ -16,8 +16,8 @@
*/
import {
EXTENDIBLE_COMPONENT, FileInfo, FileModel, FileUtils, NodePermissionSubject,
NotificationService, TranslationService, UploadService, ContentService, PermissionsEnum
EXTENDIBLE_COMPONENT, FileInfo, FileModel, FileUtils, NodeAllowableOperationSubject,
NotificationService, TranslationService, UploadService, ContentService, AllowableOperationsEnum
} from '@alfresco/adf-core';
import { Component, forwardRef, ViewEncapsulation, NgZone } from '@angular/core';
import { UploadBase } from './base-upload/upload-base';
@@ -32,7 +32,7 @@ import { UploadBase } from './base-upload/upload-base';
],
encapsulation: ViewEncapsulation.None
})
export class UploadDragAreaComponent extends UploadBase implements NodePermissionSubject {
export class UploadDragAreaComponent extends UploadBase implements NodeAllowableOperationSubject {
constructor(protected uploadService: UploadService,
protected translationService: TranslationService,
@@ -94,7 +94,7 @@ export class UploadDragAreaComponent extends UploadBase implements NodePermissio
onUploadFiles(event: CustomEvent) {
event.stopPropagation();
event.preventDefault();
let isAllowed: boolean = this.contentService.hasPermission(event.detail.data.obj.entry, PermissionsEnum.CREATE);
let isAllowed: boolean = this.contentService.hasAllowableOperations(event.detail.data.obj.entry, AllowableOperationsEnum.CREATE);
if (isAllowed) {
let fileInfo: FileInfo[] = event.detail.files;
if (this.isTargetNodeFolder(event)) {

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { PermissionsEnum } from '@alfresco/adf-core';
import { AllowableOperationsEnum } from '@alfresco/adf-core';
import { Component, forwardRef, Input, OnChanges, ViewEncapsulation, OnInit } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { UploadButtonComponent } from './upload-button.component';
@@ -53,6 +53,6 @@ export class UploadVersionButtonComponent extends UploadButtonComponent implemen
}
checkPermission() {
this.permissionValue.next(this.nodeHasPermission(this.node, PermissionsEnum.UPDATE));
this.permissionValue.next(this.nodeHasPermission(this.node, AllowableOperationsEnum.UPDATE));
}
}

View File

@@ -71,11 +71,11 @@ export class VersionListComponent implements OnChanges {
}
canUpdate(): boolean {
return this.contentService.hasPermission(this.node, 'update') && this.versions.length > 1;
return this.contentService.hasAllowableOperations(this.node, 'update') && this.versions.length > 1;
}
canDelete(): boolean {
return this.contentService.hasPermission(this.node, 'delete') && this.versions.length > 1;
return this.contentService.hasAllowableOperations(this.node, 'delete') && this.versions.length > 1;
}
restore(versionId) {

View File

@@ -100,6 +100,6 @@ export class VersionManagerComponent {
}
canUpdate(): boolean {
return this.contentService.hasPermission(this.node, 'update');
return this.contentService.hasAllowableOperations(this.node, 'update');
}
}

View File

@@ -48,7 +48,7 @@ export class VersionUploadComponent {
}
canUpload(): boolean {
return this.contentService.hasPermission(this.node, 'update');
return this.contentService.hasAllowableOperations(this.node, 'update');
}
isMajorVersion(): boolean {