From b970caa56d6790830b9c10ab5ae920c61b4c1d13 Mon Sep 17 00:00:00 2001 From: Cilibiu Bogdan <pionnegru@users.noreply.github.com> Date: Wed, 4 Apr 2018 15:30:10 +0300 Subject: [PATCH] update permission (#275) --- .../components/layout/layout.component.html | 2 +- .../layout/layout.component.spec.ts | 34 ++----------------- src/app/components/layout/layout.component.ts | 13 ++----- 3 files changed, 7 insertions(+), 42 deletions(-) diff --git a/src/app/components/layout/layout.component.html b/src/app/components/layout/layout.component.html index 215f4f10a..958362bc2 100644 --- a/src/app/components/layout/layout.component.html +++ b/src/app/components/layout/layout.component.html @@ -1,7 +1,7 @@ <div class="layout"> <adf-upload-drag-area [parentId]="node?.id" - [disabled]="!canCreateContent(node)"> + [disabled]="!permission.check(node, ['create'])"> <adf-sidenav-layout [sidenavMin]="70" diff --git a/src/app/components/layout/layout.component.spec.ts b/src/app/components/layout/layout.component.spec.ts index fc926fdef..166179c45 100644 --- a/src/app/components/layout/layout.component.spec.ts +++ b/src/app/components/layout/layout.component.spec.ts @@ -30,7 +30,7 @@ import { MinimalNodeEntryEntity } from 'alfresco-js-api'; import { TranslateModule } from '@ngx-translate/core'; import { HttpClientModule } from '@angular/common/http'; import { - ContentService, PeopleContentService, AppConfigService, + PeopleContentService, AppConfigService, AuthenticationService, UserPreferencesService, TranslationService, TranslationMock, StorageService, AlfrescoApiService, CookieService, LogService @@ -38,14 +38,13 @@ import { import { Observable } from 'rxjs/Observable'; import { BrowsingFilesService } from '../../common/services/browsing-files.service'; +import { NodePermissionService } from '../../common/services/node-permission.service'; import { LayoutComponent } from './layout.component'; describe('LayoutComponent', () => { let fixture: ComponentFixture<LayoutComponent>; let component: LayoutComponent; let browsingFilesService: BrowsingFilesService; - let contentService: ContentService; - let node; const navItem = { label: 'some-label', route: { @@ -54,8 +53,6 @@ describe('LayoutComponent', () => { }; beforeEach(() => { - node = { id: 'node-id' }; - TestBed.configureTestingModule({ imports: [ HttpClientModule, @@ -73,8 +70,8 @@ describe('LayoutComponent', () => { LogService, UserPreferencesService, AuthenticationService, - ContentService, AppConfigService, + NodePermissionService, BrowsingFilesService, { provide: PeopleContentService, @@ -89,7 +86,6 @@ describe('LayoutComponent', () => { fixture = TestBed.createComponent(LayoutComponent); component = fixture.componentInstance; browsingFilesService = TestBed.get(BrowsingFilesService); - contentService = TestBed.get(ContentService); const appConfig = TestBed.get(AppConfigService); spyOn(appConfig, 'get').and.returnValue([navItem]); @@ -104,28 +100,4 @@ describe('LayoutComponent', () => { 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); - }); - }); }); diff --git a/src/app/components/layout/layout.component.ts b/src/app/components/layout/layout.component.ts index 411ec04f4..07f3fa06e 100644 --- a/src/app/components/layout/layout.component.ts +++ b/src/app/components/layout/layout.component.ts @@ -27,8 +27,8 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; import { Subscription } from 'rxjs/Rx'; import { MinimalNodeEntryEntity } from 'alfresco-js-api'; -import { ContentService } from '@alfresco/adf-core'; import { BrowsingFilesService } from '../../common/services/browsing-files.service'; +import { NodePermissionService } from '../../common/services/node-permission.service'; @Component({ selector: 'app-layout', @@ -43,8 +43,8 @@ export class LayoutComponent implements OnInit, OnDestroy { constructor( private router: Router, - private contentService: ContentService, - private browsingFilesService: BrowsingFilesService) { + private browsingFilesService: BrowsingFilesService, + public permission: NodePermissionService) { this.router.events .filter(event => event instanceof NavigationEnd) .subscribe( (event: any ) => { @@ -61,11 +61,4 @@ export class LayoutComponent implements OnInit, OnDestroy { ngOnDestroy() { this.subscriptions.forEach(s => s.unsubscribe()); } - - canCreateContent(node: MinimalNodeEntryEntity): boolean { - if (node) { - return this.contentService.hasPermission(node, 'create'); - } - return false; - } }