mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-12 17:04:46 +00:00
update permission (#275)
This commit is contained in:
parent
9840e29531
commit
b970caa56d
@ -1,7 +1,7 @@
|
|||||||
<div class="layout">
|
<div class="layout">
|
||||||
<adf-upload-drag-area
|
<adf-upload-drag-area
|
||||||
[parentId]="node?.id"
|
[parentId]="node?.id"
|
||||||
[disabled]="!canCreateContent(node)">
|
[disabled]="!permission.check(node, ['create'])">
|
||||||
|
|
||||||
<adf-sidenav-layout
|
<adf-sidenav-layout
|
||||||
[sidenavMin]="70"
|
[sidenavMin]="70"
|
||||||
|
@ -30,7 +30,7 @@ import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
|||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { HttpClientModule } from '@angular/common/http';
|
import { HttpClientModule } from '@angular/common/http';
|
||||||
import {
|
import {
|
||||||
ContentService, PeopleContentService, AppConfigService,
|
PeopleContentService, AppConfigService,
|
||||||
AuthenticationService, UserPreferencesService, TranslationService,
|
AuthenticationService, UserPreferencesService, TranslationService,
|
||||||
TranslationMock, StorageService, AlfrescoApiService, CookieService,
|
TranslationMock, StorageService, AlfrescoApiService, CookieService,
|
||||||
LogService
|
LogService
|
||||||
@ -38,14 +38,13 @@ import {
|
|||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
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 { LayoutComponent } from './layout.component';
|
import { LayoutComponent } from './layout.component';
|
||||||
|
|
||||||
describe('LayoutComponent', () => {
|
describe('LayoutComponent', () => {
|
||||||
let fixture: ComponentFixture<LayoutComponent>;
|
let fixture: ComponentFixture<LayoutComponent>;
|
||||||
let component: LayoutComponent;
|
let component: LayoutComponent;
|
||||||
let browsingFilesService: BrowsingFilesService;
|
let browsingFilesService: BrowsingFilesService;
|
||||||
let contentService: ContentService;
|
|
||||||
let node;
|
|
||||||
const navItem = {
|
const navItem = {
|
||||||
label: 'some-label',
|
label: 'some-label',
|
||||||
route: {
|
route: {
|
||||||
@ -54,8 +53,6 @@ describe('LayoutComponent', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
node = { id: 'node-id' };
|
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
@ -73,8 +70,8 @@ describe('LayoutComponent', () => {
|
|||||||
LogService,
|
LogService,
|
||||||
UserPreferencesService,
|
UserPreferencesService,
|
||||||
AuthenticationService,
|
AuthenticationService,
|
||||||
ContentService,
|
|
||||||
AppConfigService,
|
AppConfigService,
|
||||||
|
NodePermissionService,
|
||||||
BrowsingFilesService,
|
BrowsingFilesService,
|
||||||
{
|
{
|
||||||
provide: PeopleContentService,
|
provide: PeopleContentService,
|
||||||
@ -89,7 +86,6 @@ describe('LayoutComponent', () => {
|
|||||||
fixture = TestBed.createComponent(LayoutComponent);
|
fixture = TestBed.createComponent(LayoutComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
browsingFilesService = TestBed.get(BrowsingFilesService);
|
browsingFilesService = TestBed.get(BrowsingFilesService);
|
||||||
contentService = TestBed.get(ContentService);
|
|
||||||
|
|
||||||
const appConfig = TestBed.get(AppConfigService);
|
const appConfig = TestBed.get(AppConfigService);
|
||||||
spyOn(appConfig, 'get').and.returnValue([navItem]);
|
spyOn(appConfig, 'get').and.returnValue([navItem]);
|
||||||
@ -104,28 +100,4 @@ describe('LayoutComponent', () => {
|
|||||||
|
|
||||||
expect(component.node).toEqual(currentNode);
|
expect(component.node).toEqual(currentNode);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('canCreateContent()', () => {
|
|
||||||
it('returns true if node has permission', () => {
|
|
||||||
spyOn(contentService, 'hasPermission').and.returnValue(true);
|
|
||||||
|
|
||||||
const permission = component.canCreateContent(<any>{});
|
|
||||||
|
|
||||||
expect(permission).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns false if node does not have permission', () => {
|
|
||||||
spyOn(contentService, 'hasPermission').and.returnValue(false);
|
|
||||||
|
|
||||||
const permission = component.canCreateContent(<any>{});
|
|
||||||
|
|
||||||
expect(permission).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns false if node is null', () => {
|
|
||||||
const permission = component.canCreateContent(null);
|
|
||||||
|
|
||||||
expect(permission).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -27,8 +27,8 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
|
|||||||
import { Router, NavigationEnd } from '@angular/router';
|
import { Router, NavigationEnd } from '@angular/router';
|
||||||
import { Subscription } from 'rxjs/Rx';
|
import { Subscription } from 'rxjs/Rx';
|
||||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||||
import { ContentService } 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-layout',
|
selector: 'app-layout',
|
||||||
@ -43,8 +43,8 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private contentService: ContentService,
|
private browsingFilesService: BrowsingFilesService,
|
||||||
private browsingFilesService: BrowsingFilesService) {
|
public permission: NodePermissionService) {
|
||||||
this.router.events
|
this.router.events
|
||||||
.filter(event => event instanceof NavigationEnd)
|
.filter(event => event instanceof NavigationEnd)
|
||||||
.subscribe( (event: any ) => {
|
.subscribe( (event: any ) => {
|
||||||
@ -61,11 +61,4 @@ export class LayoutComponent implements OnInit, OnDestroy {
|
|||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.subscriptions.forEach(s => s.unsubscribe());
|
this.subscriptions.forEach(s => s.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
canCreateContent(node: MinimalNodeEntryEntity): boolean {
|
|
||||||
if (node) {
|
|
||||||
return this.contentService.hasPermission(node, 'create');
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user