mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2077] [Destination picker] User should not be able to copy / mo… (#2978)
* [ADF-20177] [Destination picker] User should not be able to copy / move items into a site outside of the documentLibrary * [ADF-20177] added unit tests for the change * [ADF-2077] refactor code and unit tests after code review * [ADF-2077] more refactoring to make the unit tests messages more clear
This commit is contained in:
committed by
Eugenio Romano
parent
8f471d8beb
commit
d997f14565
@@ -55,6 +55,7 @@ describe('ContentNodeDialogService', () => {
|
||||
let documentListService: DocumentListService;
|
||||
let sitesService: SitesService;
|
||||
let materialDialog: MatDialog;
|
||||
let spyOnDialogOpen: jasmine.Spy;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@@ -76,7 +77,7 @@ describe('ContentNodeDialogService', () => {
|
||||
documentListService = TestBed.get(DocumentListService);
|
||||
materialDialog = TestBed.get(MatDialog);
|
||||
sitesService = TestBed.get(SitesService);
|
||||
spyOn(materialDialog, 'open').and.stub();
|
||||
spyOnDialogOpen = spyOn(materialDialog, 'open').and.stub();
|
||||
spyOn(materialDialog, 'closeAll').and.stub();
|
||||
|
||||
});
|
||||
@@ -87,14 +88,14 @@ describe('ContentNodeDialogService', () => {
|
||||
|
||||
it('should be able to open the dialog when node has permission', () => {
|
||||
service.openCopyMoveDialog('fake-action', fakeNode, '!update');
|
||||
expect(materialDialog.open).toHaveBeenCalled();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should NOT be able to open the dialog when node has NOT permission', () => {
|
||||
service.openCopyMoveDialog('fake-action', fakeNode, 'noperm').subscribe(
|
||||
() => { },
|
||||
(error) => {
|
||||
expect(materialDialog.open).not.toHaveBeenCalled();
|
||||
expect(spyOnDialogOpen).not.toHaveBeenCalled();
|
||||
expect(JSON.parse(error.message).error.statusCode).toBe(403);
|
||||
});
|
||||
});
|
||||
@@ -103,7 +104,7 @@ describe('ContentNodeDialogService', () => {
|
||||
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.resolve(fakeNode));
|
||||
service.openFileBrowseDialogByFolderId('fake-folder-id').subscribe();
|
||||
tick();
|
||||
expect(materialDialog.open).toHaveBeenCalled();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should be able to open the dialog for files using the first user site', fakeAsync(() => {
|
||||
@@ -111,7 +112,7 @@ describe('ContentNodeDialogService', () => {
|
||||
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.resolve(fakeNode));
|
||||
service.openFileBrowseDialogBySite().subscribe();
|
||||
tick();
|
||||
expect(materialDialog.open).toHaveBeenCalled();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should be able to open the dialog for folder using the first user site', fakeAsync(() => {
|
||||
@@ -119,7 +120,7 @@ describe('ContentNodeDialogService', () => {
|
||||
spyOn(documentListService, 'getFolderNode').and.returnValue(Promise.resolve(fakeNode));
|
||||
service.openFolderBrowseDialogBySite().subscribe();
|
||||
tick();
|
||||
expect(materialDialog.open).toHaveBeenCalled();
|
||||
expect(spyOnDialogOpen).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should be able to close the material dialog', () => {
|
||||
@@ -127,4 +128,77 @@ describe('ContentNodeDialogService', () => {
|
||||
expect(materialDialog.closeAll).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('for the copy/move dialog', () => {
|
||||
const siteNode: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> {
|
||||
id: 'site-node-id',
|
||||
nodeType: 'st:site'
|
||||
};
|
||||
const sites: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> {
|
||||
id: 'sites-id',
|
||||
nodeType: 'st:sites'
|
||||
};
|
||||
const site: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> {
|
||||
id: 'site-id',
|
||||
guid: 'any-guid'
|
||||
};
|
||||
const nodeEntryWithRightPermissions: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> {
|
||||
id: 'node-id',
|
||||
allowableOperations: ['create']
|
||||
};
|
||||
const nodeEntryNoPermissions: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> {
|
||||
id: 'node-id',
|
||||
allowableOperations: []
|
||||
};
|
||||
|
||||
const siteFixture = [
|
||||
{
|
||||
node: siteNode,
|
||||
expected: false
|
||||
},
|
||||
{
|
||||
node: sites,
|
||||
expected: false
|
||||
},
|
||||
{
|
||||
node: site,
|
||||
expected: false
|
||||
}
|
||||
];
|
||||
|
||||
const permissionFixture = [
|
||||
{
|
||||
node: nodeEntryWithRightPermissions,
|
||||
expected: true
|
||||
},
|
||||
{
|
||||
node: nodeEntryNoPermissions,
|
||||
expected: false
|
||||
}
|
||||
];
|
||||
|
||||
let testContentNodeSelectorComponentData;
|
||||
|
||||
beforeEach(() => {
|
||||
spyOnDialogOpen.and.callFake((contentNodeSelectorComponent: any, config: any) => {
|
||||
testContentNodeSelectorComponentData = config.data;
|
||||
return {componentInstance: {}};
|
||||
});
|
||||
service.openCopyMoveDialog('fake-action', fakeNode, '!update');
|
||||
});
|
||||
|
||||
it('should NOT allow selection for sites', () => {
|
||||
expect(spyOnDialogOpen.calls.count()).toEqual(1);
|
||||
siteFixture.forEach((testData) => {
|
||||
expect(testContentNodeSelectorComponentData.isSelectionValid(testData.node)).toBe(testData.expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow selection only for nodes with the right permission', () => {
|
||||
expect(spyOnDialogOpen.calls.count()).toEqual(1);
|
||||
permissionFixture.forEach((testData) => {
|
||||
expect(testContentNodeSelectorComponentData.isSelectionValid(testData.node)).toBe(testData.expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -88,7 +88,7 @@ export class ContentNodeDialogService {
|
||||
currentFolderId: contentEntry.parentId,
|
||||
imageResolver: this.imageResolver.bind(this),
|
||||
rowFilter : this.rowFilter.bind(this, contentEntry.id),
|
||||
isSelectionValid: this.hasEntityCreatePermission.bind(this),
|
||||
isSelectionValid: this.isCopyMoveSelectionValid.bind(this),
|
||||
select: select
|
||||
};
|
||||
|
||||
@@ -188,10 +188,18 @@ export class ContentNodeDialogService {
|
||||
return entry.isFolder;
|
||||
}
|
||||
|
||||
private isCopyMoveSelectionValid(entry: MinimalNodeEntryEntity): boolean {
|
||||
return this.hasEntityCreatePermission(entry) && !this.isSite(entry);
|
||||
}
|
||||
|
||||
private hasEntityCreatePermission(entry: MinimalNodeEntryEntity): boolean {
|
||||
return this.contentService.hasPermission(entry, 'create');
|
||||
}
|
||||
|
||||
private isSite(entry) {
|
||||
return !!entry.guid || entry.nodeType === 'st:site' || entry.nodeType === 'st:sites';
|
||||
}
|
||||
|
||||
/** Closes the currently open dialog. */
|
||||
close() {
|
||||
this.dialog.closeAll();
|
||||
|
Reference in New Issue
Block a user