no permission content (#2616)

This commit is contained in:
Cilibiu Bogdan
2017-11-07 18:40:19 +02:00
committed by Eugenio Romano
parent cc821542a2
commit 5fff7fcb29
18 changed files with 375 additions and 5 deletions

View File

@@ -30,6 +30,7 @@ import { ContentColumnComponent } from './src/components/content-column/content-
import { ContentNodeSelectorComponent } from './src/components/content-node-selector/content-node-selector.component';
import { DocumentListComponent } from './src/components/document-list.component';
import { EmptyFolderContentDirective } from './src/components/empty-folder/empty-folder-content.directive';
import { NoPermissionContentDirective } from './src/components/no-permission/no-permission-content.directive';
import { DropdownSitesComponent } from './src/components/site-dropdown/sites-dropdown.component';
import { VersionListComponent } from './src/components/version-manager/version-list.component';
import { VersionManagerComponent } from './src/components/version-manager/version-manager.component';
@@ -51,6 +52,7 @@ export * from './src/components/content-action/content-action.component';
export * from './src/components/content-action/content-action-list.component';
export * from './src/components/content-node-selector/content-node-selector.component';
export * from './src/components/empty-folder/empty-folder-content.directive';
export * from './src/components/no-permission/no-permission-content.directive';
export * from './src/components/breadcrumb/breadcrumb.component';
export * from './src/components/site-dropdown/sites-dropdown.component';
@@ -77,6 +79,7 @@ export const DOCUMENT_LIST_DIRECTIVES: any[] = [
ContentActionComponent,
ContentActionListComponent,
EmptyFolderContentDirective,
NoPermissionContentDirective,
BreadcrumbComponent,
DropdownSitesComponent,
DropdownBreadcrumbComponent,

View File

@@ -246,6 +246,7 @@ describe('ContentNodeSelectorComponent', () => {
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.resolve(expectedDefaultFolderNode));
spyOn(documentListService, 'getFolder').and.returnValue(Observable.throw('No results for test'));
spyOn(sitesApiService, 'getSites').and.returnValue(Observable.of([]));
spyOn(component.documentList, 'loadFolderNodesByFolderNodeId').and.returnValue(Promise.resolve());
component.currentFolderId = 'cat-girl-nuku-nuku';
fixture.detectChanges();
});
@@ -347,6 +348,12 @@ describe('ContentNodeSelectorComponent', () => {
}
beforeEach(() => {
const documentListService = TestBed.get(DocumentListService);
const expectedDefaultFolderNode = <MinimalNodeEntryEntity> { path: { elements: [] } };
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.resolve(expectedDefaultFolderNode));
spyOn(component.documentList, 'loadFolderNodesByFolderNodeId').and.returnValue(Promise.resolve());
component.currentFolderId = 'cat-girl-nuku-nuku';
fixture.detectChanges();
});
@@ -458,7 +465,7 @@ describe('ContentNodeSelectorComponent', () => {
fixture.detectChanges();
let documentList = fixture.debugElement.query(By.css('[data-automation-id="content-node-selector-document-list"]'));
expect(documentList).not.toBeNull('Document list should be shown');
expect(documentList.componentInstance.currentFolderId).toBeNull();
expect(documentList.componentInstance.currentFolderId).toBeUndefined();
});
}));

View File

@@ -9,6 +9,7 @@
[rowStyle]="rowStyle"
[rowStyleClass]="rowStyleClass"
[loading]="loading"
[noPermission]="noPermission"
[showHeader]="!isEmpty()"
(showRowContextMenu)="onShowRowContextMenu($event)"
(showRowActionsMenu)="onShowRowActionsMenu($event)"
@@ -34,6 +35,17 @@
</no-content-template>
</div>
<div *ngIf="!isNoPermissionTemplateDefined()">
<no-permission-template>
<ng-template>
<div class="adf-no-permission__template">
<mat-icon>ic_error</mat-icon>
<p class="adf-no-permission__template--text">{{ 'ADF-DOCUMENT-LIST.NO_PERMISSION' | translate }}</p>
</div>
</ng-template>
</no-permission-template>
</div>
<div>
<loading-content-template>
<ng-template>

View File

@@ -16,6 +16,28 @@
margin-bottom: 20px;
}
.adf-no-permission__template {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
width: 100%;
height: 100%;
min-height: 300px;
mat-icon {
font-size: 52px;
height: 52px;
width: 52px;
direction: rtl;
}
&--text {
color: mat-color($foreground, text);
font-size: 16px;
}
}
.document-list__this-space-is-empty {
height: 32px;
opacity: 0.26;

View File

@@ -741,6 +741,25 @@ describe('DocumentList', () => {
expect(documentList.isEmptyTemplateDefined()).toBeFalsy();
});
it('should require dataTable to check no permission template', () => {
documentList.dataTable = null;
expect(documentList.isNoPermissionTemplateDefined()).toBe(false);
});
it('should return true if custom permission template is provided', () => {
documentList.noPermissionTemplate = <TemplateRef<any>> {};
documentList.dataTable = new DataTableComponent(null, null);
expect(documentList.isNoPermissionTemplateDefined()).toBe(true);
});
it('should return false if no custom permission template is provided', () => {
documentList.noPermissionTemplate = null;
documentList.dataTable = new DataTableComponent(null, null);
expect(documentList.isNoPermissionTemplateDefined()).toBe(false);
});
it('should empty folder NOT show the pagination', () => {
documentList.emptyFolderTemplate = <TemplateRef<any>> {};
documentList.dataTable = new DataTableComponent(null, null);
@@ -824,6 +843,44 @@ describe('DocumentList', () => {
expect(documentList.loadFolderNodesByFolderNodeId).toHaveBeenCalled();
});
it('should emit error when getFolderNode fails', (done) => {
const error = { message: '{ "error": { "statusCode": 501 } }' } ;
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.reject(error));
documentList.error.subscribe(val => {
expect(val).toBe(error);
done();
});
documentList.loadFolderByNodeId('123');
});
it('should emit error when loadFolderNodesByFolderNodeId fails', (done) => {
const error = { message: '{ "error": { "statusCode": 501 } }' } ;
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.resolve(fakeNodeWithCreatePermission));
spyOn(documentList, 'loadFolderNodesByFolderNodeId').and.returnValue(Promise.reject(error));
documentList.error.subscribe(val => {
expect(val).toBe(error);
done();
});
documentList.loadFolderByNodeId('123');
});
it('should set no permision when getFolderNode fails with 403', (done) => {
const error = { message: '{ "error": { "statusCode": 403 } }' } ;
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.reject(error));
documentList.error.subscribe(val => {
expect(val).toBe(error);
expect(documentList.noPermission).toBe(true);
done();
});
documentList.loadFolderByNodeId('123');
});
xit('should load previous page if there are no other elements in multi page table', (done) => {
documentList.currentFolderId = '1d26e465-dea3-42f3-b415-faa8364b9692';
documentList.folderNode = new NodeMinimal();

View File

@@ -116,6 +116,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
supportedPageSizes: number[];
infiniteLoading: boolean = false;
noPermission: boolean = false;
selection = new Array<MinimalNodeEntity>();
skipCount: number = 0;
@@ -161,6 +162,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
errorMessage;
actions: ContentActionModel[] = [];
emptyFolderTemplate: TemplateRef<any>;
noPermissionTemplate: TemplateRef<any>;
contextActionHandler: Subject<any> = new Subject();
data: ShareDataTableAdapter;
@@ -305,6 +307,15 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
return false;
}
isNoPermissionTemplateDefined(): boolean {
if (this.dataTable) {
if (this.noPermissionTemplate) {
return true;
}
}
return false;
}
isMobile(): boolean {
return !!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
@@ -440,14 +451,21 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
this.loadRecent();
} else {
this.documentListService
.getFolderNode(nodeId).then(node => {
.getFolderNode(nodeId)
.then(node => {
this.folderNode = node;
this.currentFolderId = node.id;
this.skipCount = 0;
this.currentNodeAllowableOperations = node['allowableOperations'] ? node['allowableOperations'] : [];
this.loadFolderNodesByFolderNodeId(node.id, this.pageSize, this.skipCount).catch(err => this.error.emit(err));
return this.loadFolderNodesByFolderNodeId(node.id, this.pageSize, this.skipCount);
})
.catch(err => this.error.emit(err));
.catch(err => {
if (JSON.parse(err.message).error.statusCode === 403) {
this.loading = false;
this.noPermission = true;
}
this.error.emit(err);
});
}
}

View File

@@ -0,0 +1,66 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { MatProgressSpinnerModule } from '@angular/material';
import { CoreModule } from 'ng2-alfresco-core';
import { DataTableComponent, DataTableModule } from 'ng2-alfresco-datatable';
import { DocumentListService } from '../../services/document-list.service';
import { DocumentListComponent } from './../document-list.component';
import { NoPermissionContentDirective } from './no-permission-content.directive';
describe('NoPermissionContentDirective', () => {
let noPermissionContent: NoPermissionContentDirective;
let documentList: DocumentListComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
CoreModule,
DataTableModule,
MatProgressSpinnerModule
],
declarations: [
DocumentListComponent
],
providers: [
DocumentListService
]
}).compileComponents();
}));
beforeEach(() => {
documentList = (TestBed.createComponent(DocumentListComponent).componentInstance as DocumentListComponent);
documentList.dataTable = new DataTableComponent(null, null);
noPermissionContent = new NoPermissionContentDirective(documentList);
});
it('should be defined', () => {
expect(noPermissionContent).toBeDefined();
});
it('should set template', () => {
noPermissionContent.template = '<example>';
noPermissionContent.ngAfterContentInit();
expect(noPermissionContent.template).toBe(documentList.noPermissionTemplate);
expect(noPermissionContent.template).toBe(documentList.dataTable.noPermissionTemplate);
});
});

View File

@@ -0,0 +1,36 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AfterContentInit, ContentChild, Directive, TemplateRef } from '@angular/core';
import { DocumentListComponent } from './../document-list.component';
@Directive({
selector: 'no-permission-content'
})
export class NoPermissionContentDirective implements AfterContentInit {
@ContentChild(TemplateRef)
template: any;
constructor(private documentList: DocumentListComponent) {
}
ngAfterContentInit() {
this.documentList.noPermissionTemplate = this.template;
this.documentList.dataTable.noPermissionTemplate = this.template;
}
}

View File

@@ -3,6 +3,7 @@
"EMPTY": {
"HEADER": "This folder is empty"
},
"NO_PERMISSION": "You don't have permission to view this file or folder.",
"LAYOUT": {
"CREATED": "Created",
"THUMBNAIL": "Thumbnail",