mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-19 17:14:45 +00:00
update menu permission (#273)
This commit is contained in:
parent
142b179841
commit
d21d7c5fab
@ -21,25 +21,24 @@
|
|||||||
<mat-menu #menu="matMenu" [overlapTrigger]="false">
|
<mat-menu #menu="matMenu" [overlapTrigger]="false">
|
||||||
<button
|
<button
|
||||||
mat-menu-item
|
mat-menu-item
|
||||||
[disabled]="!canCreateContent(node)"
|
[disabled]="!permission.check(node, ['create'])"
|
||||||
[adf-create-folder]="node?.id"
|
[adf-create-folder]="node?.id"
|
||||||
title="{{
|
[title]="
|
||||||
( canCreateContent(node)
|
( permission.check(node, ['create'])
|
||||||
? 'APP.NEW_MENU.TOOLTIPS.CREATE_FOLDER'
|
? 'APP.NEW_MENU.TOOLTIPS.CREATE_FOLDER'
|
||||||
: 'APP.NEW_MENU.TOOLTIPS.CREATE_FOLDER_NOT_ALLOWED'
|
: 'APP.NEW_MENU.TOOLTIPS.CREATE_FOLDER_NOT_ALLOWED'
|
||||||
) | translate
|
) | translate">
|
||||||
}}">
|
|
||||||
<mat-icon>create_new_folder</mat-icon>
|
<mat-icon>create_new_folder</mat-icon>
|
||||||
<span>{{ 'APP.NEW_MENU.MENU_ITEMS.CREATE_FOLDER' | translate }}</span>
|
<span>{{ 'APP.NEW_MENU.MENU_ITEMS.CREATE_FOLDER' | translate }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<adf-upload-button
|
<adf-upload-button
|
||||||
tooltip="{{
|
[tooltip]="
|
||||||
(canCreateContent(node)
|
(permission.check(node, ['create'])
|
||||||
? 'APP.NEW_MENU.TOOLTIPS.UPLOAD_FILES'
|
? 'APP.NEW_MENU.TOOLTIPS.UPLOAD_FILES'
|
||||||
: 'APP.NEW_MENU.TOOLTIPS.UPLOAD_FILES_NOT_ALLOWED'
|
: 'APP.NEW_MENU.TOOLTIPS.UPLOAD_FILES_NOT_ALLOWED'
|
||||||
) | translate }}"
|
) | translate"
|
||||||
[disabled]="!canCreateContent(node)"
|
[disabled]="!permission.check(node, ['create'])"
|
||||||
[rootFolderId]="node?.id"
|
[rootFolderId]="node?.id"
|
||||||
[multipleFiles]="true"
|
[multipleFiles]="true"
|
||||||
[uploadFolders]="false"
|
[uploadFolders]="false"
|
||||||
@ -47,12 +46,12 @@
|
|||||||
</adf-upload-button>
|
</adf-upload-button>
|
||||||
|
|
||||||
<adf-upload-button
|
<adf-upload-button
|
||||||
tooltip="{{
|
[tooltip]="
|
||||||
(canCreateContent(node)
|
(permission.check(node, ['create'])
|
||||||
? 'APP.NEW_MENU.TOOLTIPS.UPLOAD_FOLDERS'
|
? 'APP.NEW_MENU.TOOLTIPS.UPLOAD_FOLDERS'
|
||||||
: 'APP.NEW_MENU.TOOLTIPS.UPLOAD_FOLDERS_NOT_ALLOWED'
|
: 'APP.NEW_MENU.TOOLTIPS.UPLOAD_FOLDERS_NOT_ALLOWED'
|
||||||
) | translate }}"
|
) | translate"
|
||||||
[disabled]="!canCreateContent(node)"
|
[disabled]="!permission.check(node, ['create'])"
|
||||||
[rootFolderId]="node?.id"
|
[rootFolderId]="node?.id"
|
||||||
[multipleFiles]="true"
|
[multipleFiles]="true"
|
||||||
[uploadFolders]="true"
|
[uploadFolders]="true"
|
||||||
|
@ -30,18 +30,18 @@ import { TranslateModule } from '@ngx-translate/core';
|
|||||||
import { MatMenuModule } from '@angular/material';
|
import { MatMenuModule } from '@angular/material';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
import {
|
import {
|
||||||
ContentService, AppConfigService, AuthenticationService,
|
AppConfigService, AuthenticationService,
|
||||||
UserPreferencesService, StorageService, AlfrescoApiService,
|
UserPreferencesService, StorageService, AlfrescoApiService,
|
||||||
CookieService, LogService
|
CookieService, LogService
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { BrowsingFilesService } from '../../common/services/browsing-files.service';
|
import { BrowsingFilesService } from '../../common/services/browsing-files.service';
|
||||||
|
import { NodePermissionService } from '../../common/services/node-permission.service';
|
||||||
|
|
||||||
import { SidenavComponent } from './sidenav.component';
|
import { SidenavComponent } from './sidenav.component';
|
||||||
|
|
||||||
describe('SidenavComponent', () => {
|
describe('SidenavComponent', () => {
|
||||||
let fixture;
|
let fixture;
|
||||||
let component: SidenavComponent;
|
let component: SidenavComponent;
|
||||||
let contentService: ContentService;
|
|
||||||
let browsingService: BrowsingFilesService;
|
let browsingService: BrowsingFilesService;
|
||||||
let appConfig: AppConfigService;
|
let appConfig: AppConfigService;
|
||||||
let appConfigSpy;
|
let appConfigSpy;
|
||||||
@ -71,7 +71,7 @@ describe('SidenavComponent', () => {
|
|||||||
StorageService,
|
StorageService,
|
||||||
UserPreferencesService,
|
UserPreferencesService,
|
||||||
AuthenticationService,
|
AuthenticationService,
|
||||||
ContentService,
|
NodePermissionService,
|
||||||
AppConfigService,
|
AppConfigService,
|
||||||
BrowsingFilesService
|
BrowsingFilesService
|
||||||
],
|
],
|
||||||
@ -79,7 +79,6 @@ describe('SidenavComponent', () => {
|
|||||||
})
|
})
|
||||||
.compileComponents()
|
.compileComponents()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
contentService = TestBed.get(ContentService);
|
|
||||||
browsingService = TestBed.get(BrowsingFilesService);
|
browsingService = TestBed.get(BrowsingFilesService);
|
||||||
appConfig = TestBed.get(AppConfigService);
|
appConfig = TestBed.get(AppConfigService);
|
||||||
|
|
||||||
@ -99,32 +98,6 @@ describe('SidenavComponent', () => {
|
|||||||
expect(component.node).toBe(node);
|
expect(component.node).toBe(node);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have permission to create content', () => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
spyOn(contentService, 'hasPermission').and.returnValue(true);
|
|
||||||
const node: any = {};
|
|
||||||
|
|
||||||
expect(component.canCreateContent(node)).toBe(true);
|
|
||||||
expect(contentService.hasPermission).toHaveBeenCalledWith(node, 'create');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not have permission to create content for missing node', () => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
spyOn(contentService, 'hasPermission').and.returnValue(true);
|
|
||||||
|
|
||||||
expect(component.canCreateContent(null)).toBe(false);
|
|
||||||
expect(contentService.hasPermission).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not have permission to create content based on node permission', () => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
spyOn(contentService, 'hasPermission').and.returnValue(false);
|
|
||||||
const node: any = {};
|
|
||||||
|
|
||||||
expect(component.canCreateContent(node)).toBe(false);
|
|
||||||
expect(contentService.hasPermission).toHaveBeenCalledWith(node, 'create');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('menu', () => {
|
describe('menu', () => {
|
||||||
it('should build menu from array', () => {
|
it('should build menu from array', () => {
|
||||||
appConfigSpy.and.returnValue([navItem, navItem]);
|
appConfigSpy.and.returnValue([navItem, navItem]);
|
||||||
|
@ -26,9 +26,10 @@
|
|||||||
import { Subscription } from 'rxjs/Rx';
|
import { Subscription } from 'rxjs/Rx';
|
||||||
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
|
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||||
import { ContentService, AppConfigService } from '@alfresco/adf-core';
|
import { AppConfigService } from '@alfresco/adf-core';
|
||||||
|
|
||||||
import { BrowsingFilesService } from '../../common/services/browsing-files.service';
|
import { BrowsingFilesService } from '../../common/services/browsing-files.service';
|
||||||
|
import { NodePermissionService } from '../../common/services/node-permission.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-sidenav',
|
selector: 'app-sidenav',
|
||||||
@ -45,8 +46,8 @@ export class SidenavComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private browsingFilesService: BrowsingFilesService,
|
private browsingFilesService: BrowsingFilesService,
|
||||||
private contentService: ContentService,
|
private appConfig: AppConfigService,
|
||||||
private appConfig: AppConfigService
|
public permission: NodePermissionService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -62,13 +63,6 @@ export class SidenavComponent implements OnInit, OnDestroy {
|
|||||||
this.subscriptions.forEach(s => s.unsubscribe());
|
this.subscriptions.forEach(s => s.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
canCreateContent(parentNode: MinimalNodeEntryEntity): boolean {
|
|
||||||
if (parentNode) {
|
|
||||||
return this.contentService.hasPermission(parentNode, 'create');
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private buildMenu() {
|
private buildMenu() {
|
||||||
const schema = this.appConfig.get('navigation');
|
const schema = this.appConfig.get('navigation');
|
||||||
const data = Array.isArray(schema) ? { main: schema } : schema;
|
const data = Array.isArray(schema) ? { main: schema } : schema;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user