diff --git a/docs/features/info-drawer.md b/docs/features/info-drawer.md index 11d34bd9d7..61653c1785 100644 --- a/docs/features/info-drawer.md +++ b/docs/features/info-drawer.md @@ -21,3 +21,6 @@ For more information, please check also the [Content Metadata Component](https:/ ## Comments tab The Comments tab displays all comments made on the selected node in the respoistory by using the [Comments Component](https://www.alfresco.com/abn/adf/core/comments.component/). Users can post new comments that will be displayed immediately. + +## Versions tab +Versions tab displays all versions of the selected node. diff --git a/docs/features/version-manager.md b/docs/features/version-manager.md index 41fcd904f7..d7125b2999 100644 --- a/docs/features/version-manager.md +++ b/docs/features/version-manager.md @@ -8,12 +8,12 @@ The versions of a file can be viewed and managed by using the [Version Manager C There are 2 ways users can access the Version Manager: -1) From the 'Manage Versions' option of the 'More actions' menu (check [Actions and the Actions Toolbar](/features/document-list-layout#actions-and-the-actions-toolbar)): +1) From the 'Manage Versions' option of the 'More actions' menu (check [Actions and the Actions Toolbar](../features/document-list-layout#actions-and-the-actions-toolbar)): -![Version Manager Menu](../images/version-manager-action.png) +![Version Manager Menu](../images/version-manager-action-toolbar.png) ![Version Manager Dialog](../images/version-manager-dialog.png) -2) From the [Info Drawer](/features/info-drawer) (the Details right panel): +2) From the [Info Drawer](../features/info-drawer) (the Details right panel): ![Version Manager Inline](../images/version-manager-tab.png) @@ -21,23 +21,35 @@ There are 2 ways users can access the Version Manager: A new version for the selected file can be added by using this button. Users can upload a new file version using a file that is does not have the same name, or mime type as the current version, whilst allowing the user to choose the type of version (minor or major) and inputting supporting comments. -Please also check the [UploadVersionButtonComponent](https://www.alfresco.com/abn/adf/content-services/upload-version-button.component/). +Please also check the [UploadVersionButtonComponent](https://github.com/Alfresco/alfresco-ng2-components/blob/develop/docs/content-services/components/upload-version-button.component.md). ## Actions Menu -Each item in the version list has a couple of actions available: Restore, Download and Delete. These are displayed if user has permission to do that specific action. The 'Download' and 'Delete' can be also disabled from the app.config. +Each item in the version list has a couple of actions available: View, Restore, Download and Delete. These are displayed if user has permission to do that specific action. -In the app.config.json file, these are the current settings for the ACA version manager: +Some of these options can be also enabled/disabled in app.config.json file. All configurable options are listed below: + +| Option | Default value | Description | +|--------------------|---------------|---------------------------------------------------------------------| +| allowComments | true | Show version's comment in list of versions if true, hide otherwise. | +| allowDownload | true | Allow to download versions if true, disallow otherwise. | +| allowViewVersions | true | Allow to view versions if true, disallow otherwise. | +| allowVersionDelete | true | Allow to delete versions if true, disallow otherwise. | +| showActions | true | Allow to open actions menu when true, otherwise hides it. | + + +Example of settings in the app.config.json file: ```json { "adf-version-manager": { "allowComments": true, - "allowDownload": true + "allowDownload": true, + "allowViewVersions": true, + "allowVersionDelete": true, + "showActions": true } } ``` -Set the allowComments to false if the version comments should not be displayed on the version list. - -Clicking to delete a version of a file triggers a confirmation dialog. Please see the [Confirm Dialog Component](https://github.com/Alfresco/alfresco-ng2-components/blob/develop/lib/content-services/dialogs/confirm.dialog.ts) for more info. +Clicking to delete a version of a file triggers a confirmation dialog. Please see the [Confirm Dialog Component](https://github.com/Alfresco/alfresco-ng2-components/blob/develop/docs/core/dialogs/confirm.dialog.md) for more info. diff --git a/docs/images/version-manager-action-toolbar.png b/docs/images/version-manager-action-toolbar.png new file mode 100644 index 0000000000..9d52726e59 Binary files /dev/null and b/docs/images/version-manager-action-toolbar.png differ diff --git a/docs/images/version-manager-action.png b/docs/images/version-manager-action.png deleted file mode 100644 index d6ecac70af..0000000000 Binary files a/docs/images/version-manager-action.png and /dev/null differ diff --git a/docs/images/version-manager-dialog.png b/docs/images/version-manager-dialog.png index 9a2f4c5fb2..8a948e9cbb 100644 Binary files a/docs/images/version-manager-dialog.png and b/docs/images/version-manager-dialog.png differ diff --git a/docs/images/version-manager-tab.png b/docs/images/version-manager-tab.png index adbeda4c4f..68057e9eab 100644 Binary files a/docs/images/version-manager-tab.png and b/docs/images/version-manager-tab.png differ diff --git a/projects/aca-content/src/lib/components/info-drawer/versions-tab/versions-tab.component.spec.ts b/projects/aca-content/src/lib/components/info-drawer/versions-tab/versions-tab.component.spec.ts index 8bf30be509..58e121edad 100644 --- a/projects/aca-content/src/lib/components/info-drawer/versions-tab/versions-tab.component.spec.ts +++ b/projects/aca-content/src/lib/components/info-drawer/versions-tab/versions-tab.component.spec.ts @@ -23,9 +23,158 @@ */ import { VersionsTabComponent } from './versions-tab.component'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { AppSettingsService } from '@alfresco/aca-shared'; +import { ContentTestingModule, VersionListDataSource, VersionManagerComponent } from '@alfresco/adf-content-services'; +import { By } from '@angular/platform-browser'; +import { of } from 'rxjs'; describe('VersionsTabComponent', () => { - it('should be defined', () => { - expect(VersionsTabComponent).toBeDefined(); + let component: VersionsTabComponent; + let fixture: ComponentFixture; + let appSettingsService: AppSettingsService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [VersionsTabComponent, ContentTestingModule] + }); + + fixture = TestBed.createComponent(VersionsTabComponent); + component = fixture.componentInstance; + appSettingsService = TestBed.inject(AppSettingsService); + spyOn(VersionListDataSource.prototype, 'connect').and.returnValue(of()); + spyOn(VersionListDataSource.prototype, 'reset'); + }); + + describe('Version manager', () => { + let uploadAllowDownloadSpy: jasmine.SpyAnd<() => boolean>; + let versionManagerAllowViewVersionsSpy: jasmine.SpyAnd<() => boolean>; + let versionManagerShowActionsSpy: jasmine.SpyAnd<() => boolean>; + let versionManagerAllowVersionDeleteSpy: jasmine.SpyAnd<() => boolean>; + let uploadAllowCommentsSpy: jasmine.SpyAnd<() => boolean>; + let versionManagerComponent: VersionManagerComponent; + + beforeEach(() => { + component.node = { + nodeId: 'some id' + } as any; + uploadAllowDownloadSpy = spyOnProperty(appSettingsService, 'uploadAllowDownload').and; + versionManagerAllowViewVersionsSpy = spyOnProperty(appSettingsService, 'versionManagerAllowViewVersions').and; + versionManagerShowActionsSpy = spyOnProperty(appSettingsService, 'versionManagerShowActions').and; + versionManagerAllowVersionDeleteSpy = spyOnProperty(appSettingsService, 'versionManagerAllowVersionDelete').and; + uploadAllowCommentsSpy = spyOnProperty(appSettingsService, 'uploadAllowComments').and; + fixture.detectChanges(); + versionManagerComponent = fixture.debugElement.query(By.directive(VersionManagerComponent)).componentInstance; + }); + + it('should have assigned true to showComments if settings.uploadAllowComments returns true', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + + fixture.detectChanges(); + expect(versionManagerComponent.showComments).toBe(true); + }); + + it('should have assigned false to showComments if settings.uploadAllowComments returns false', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(false); + + fixture.detectChanges(); + expect(versionManagerComponent.showComments).toBe(false); + }); + + it('should have assigned true to allowDownload if settings.uploadAllowDownload returns true', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + + fixture.detectChanges(); + expect(versionManagerComponent.allowDownload).toBe(true); + }); + + it('should have assigned false to allowDownload if settings.uploadAllowDownload returns false', () => { + uploadAllowDownloadSpy.returnValue(false); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + + fixture.detectChanges(); + expect(versionManagerComponent.allowDownload).toBe(false); + }); + + it('should have assigned true to allowViewVersions if settings.versionManagerAllowViewVersions returns true', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + + fixture.detectChanges(); + expect(versionManagerComponent.allowViewVersions).toBe(true); + }); + + it('should have assigned false to allowViewVersions if settings.versionManagerAllowViewVersions returns false', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(false); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + + fixture.detectChanges(); + expect(versionManagerComponent.allowViewVersions).toBe(false); + }); + + it('should have assigned true to allowVersionDelete if settings.versionManagerAllowVersionDelete returns true', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + + fixture.detectChanges(); + expect(versionManagerComponent.allowVersionDelete).toBe(true); + }); + + it('should have assigned false to allowVersionDelete if settings.versionManagerAllowVersionDelete returns false', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(false); + uploadAllowCommentsSpy.returnValue(true); + + fixture.detectChanges(); + expect(versionManagerComponent.allowVersionDelete).toBe(false); + }); + + it('should have assigned true to showActions if settings.versionManagerShowActions returns true', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + + fixture.detectChanges(); + expect(versionManagerComponent.allowVersionDelete).toBe(true); + }); + + it('should have assigned false to showActions if settings.versionManagerShowActions returns false', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(false); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + + fixture.detectChanges(); + expect(versionManagerComponent.showActions).toBe(false); + }); }); }); diff --git a/projects/aca-content/src/lib/components/info-drawer/versions-tab/versions-tab.component.ts b/projects/aca-content/src/lib/components/info-drawer/versions-tab/versions-tab.component.ts index 2c31b99b55..d205f76626 100644 --- a/projects/aca-content/src/lib/components/info-drawer/versions-tab/versions-tab.component.ts +++ b/projects/aca-content/src/lib/components/info-drawer/versions-tab/versions-tab.component.ts @@ -36,7 +36,14 @@ import { AppSettingsService } from '@alfresco/aca-shared'; selector: 'app-versions-tab', template: ` - + diff --git a/projects/aca-content/src/lib/services/content-management.service.spec.ts b/projects/aca-content/src/lib/services/content-management.service.spec.ts index 20d5def6c4..5fc9df8cde 100644 --- a/projects/aca-content/src/lib/services/content-management.service.spec.ts +++ b/projects/aca-content/src/lib/services/content-management.service.spec.ts @@ -49,7 +49,7 @@ import { import { map } from 'rxjs/operators'; import { NodeEffects } from '../store/effects/node.effects'; import { AppTestingModule } from '../testing/app-testing.module'; -import { AppHookService, ContentApiService } from '@alfresco/aca-shared'; +import { AppHookService, AppSettingsService, ContentApiService } from '@alfresco/aca-shared'; import { Store } from '@ngrx/store'; import { ContentManagementService } from './content-management.service'; import { NodeActionsService } from './node-actions.service'; @@ -61,6 +61,7 @@ import { DocumentListService, FileModel, NewVersionUploaderDataAction, + NewVersionUploaderDialogData, NewVersionUploaderService, NodeAspectService, NodesApiService, @@ -81,6 +82,7 @@ describe('ContentManagementService', () => { let nodeAspectService: NodeAspectService; let appHookService: AppHookService; let newVersionUploaderService: NewVersionUploaderService; + let appSettingsService: AppSettingsService; let showErrorSpy: jasmine.Spy; let showInfoSpy: jasmine.Spy; let showWarningSpy: jasmine.Spy; @@ -105,6 +107,7 @@ describe('ContentManagementService', () => { nodeAspectService = TestBed.inject(NodeAspectService); appHookService = TestBed.inject(AppHookService); newVersionUploaderService = TestBed.inject(NewVersionUploaderService); + appSettingsService = TestBed.inject(AppSettingsService); dialog = TestBed.inject(MatDialog); }); @@ -1555,6 +1558,12 @@ describe('ContentManagementService', () => { let fakeNodeIsNotFile; let spyOnOpenUploadNewVersionDialog: jasmine.Spy; let spyOnDispatch: jasmine.Spy; + let uploadAllowCommentsSpy: jasmine.SpyAnd<() => boolean>; + let uploadAllowDownloadSpy: jasmine.SpyAnd<() => boolean>; + let versionManagerAllowViewVersionsSpy: jasmine.SpyAnd<() => boolean>; + let versionManagerShowActionsSpy: jasmine.SpyAnd<() => boolean>; + let versionManagerAllowVersionDeleteSpy: jasmine.SpyAnd<() => boolean>; + let dialogData: NewVersionUploaderDialogData; beforeEach(() => { fakeNodeIsFile = { entry: { id: '1', name: 'name1', isFile: true } }; @@ -1562,6 +1571,21 @@ describe('ContentManagementService', () => { const viewVersionData: ViewVersion = { action: NewVersionUploaderDataAction.view, versionId: '1.0' }; spyOnOpenUploadNewVersionDialog = spyOn(newVersionUploaderService, 'openUploadNewVersionDialog').and.returnValue(of(viewVersionData)); spyOnDispatch = spyOn(store, 'dispatch'); + dialogData = { + node: fakeNodeIsFile.entry, + showVersionsOnly: true, + title: 'VERSION.DIALOG.TITLE', + allowDownload: true, + showComments: true, + allowViewVersions: true, + showActions: true, + allowVersionDelete: true + }; + uploadAllowCommentsSpy = spyOnProperty(appSettingsService, 'uploadAllowComments').and; + uploadAllowDownloadSpy = spyOnProperty(appSettingsService, 'uploadAllowDownload').and; + versionManagerAllowViewVersionsSpy = spyOnProperty(appSettingsService, 'versionManagerAllowViewVersions').and; + versionManagerShowActionsSpy = spyOnProperty(appSettingsService, 'versionManagerShowActions').and; + versionManagerAllowVersionDeleteSpy = spyOnProperty(appSettingsService, 'versionManagerAllowVersionDelete').and; }); it('should call openUploadNewVersionDialog', () => { @@ -1570,17 +1594,78 @@ describe('ContentManagementService', () => { }); it('should call openUploadNewVersionDialog passing dialog data', () => { - const expectedArgument = { - node: fakeNodeIsFile.entry, - showVersionsOnly: true, - title: 'VERSION.DIALOG.TITLE' - }; + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); const elementToFocusSelector = 'some-selector'; + contentManagementService.manageVersions(fakeNodeIsFile, elementToFocusSelector); - expect(spyOnOpenUploadNewVersionDialog['calls'].argsFor(0)[0]).toEqual(expectedArgument); + expect(spyOnOpenUploadNewVersionDialog['calls'].argsFor(0)[0]).toEqual(dialogData); expect(spyOnOpenUploadNewVersionDialog['calls'].argsFor(0)[2]).toEqual(elementToFocusSelector); }); + it('should call openUploadNewVersionDialog with allowDownload assigned to false in passed data', () => { + uploadAllowDownloadSpy.returnValue(false); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + dialogData.allowDownload = false; + + contentManagementService.manageVersions(fakeNodeIsFile); + expect(spyOnOpenUploadNewVersionDialog['calls'].argsFor(0)[0]).toEqual(dialogData); + }); + + it('should call openUploadNewVersionDialog with allowViewVersions assigned to false in passed data', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(false); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + dialogData.allowViewVersions = false; + + contentManagementService.manageVersions(fakeNodeIsFile); + expect(spyOnOpenUploadNewVersionDialog['calls'].argsFor(0)[0]).toEqual(dialogData); + }); + + it('should call openUploadNewVersionDialog with showActions assigned to false in passed data', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(false); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(true); + dialogData.showActions = false; + + contentManagementService.manageVersions(fakeNodeIsFile); + expect(spyOnOpenUploadNewVersionDialog['calls'].argsFor(0)[0]).toEqual(dialogData); + }); + + it('should call openUploadNewVersionDialog with allowVersionDelete assigned to false in passed data', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(false); + uploadAllowCommentsSpy.returnValue(true); + dialogData.allowVersionDelete = false; + + contentManagementService.manageVersions(fakeNodeIsFile); + expect(spyOnOpenUploadNewVersionDialog['calls'].argsFor(0)[0]).toEqual(dialogData); + }); + + it('should call openUploadNewVersionDialog with showComments assigned to false in passed data', () => { + uploadAllowDownloadSpy.returnValue(true); + versionManagerAllowViewVersionsSpy.returnValue(true); + versionManagerShowActionsSpy.returnValue(true); + versionManagerAllowVersionDeleteSpy.returnValue(true); + uploadAllowCommentsSpy.returnValue(false); + dialogData.showComments = false; + + contentManagementService.manageVersions(fakeNodeIsFile); + expect(spyOnOpenUploadNewVersionDialog['calls'].argsFor(0)[0]).toEqual(dialogData); + }); + it('should dispatch RefreshPreviewAction and reload document list if dialog emit refresh action', () => { spyOnOpenUploadNewVersionDialog.and.returnValue(of({ action: NewVersionUploaderDataAction.refresh, node: fakeNodeIsFile })); spyOn(documentListService, 'reload'); diff --git a/projects/aca-content/src/lib/services/content-management.service.ts b/projects/aca-content/src/lib/services/content-management.service.ts index 7a771ca880..1d4142d50d 100644 --- a/projects/aca-content/src/lib/services/content-management.service.ts +++ b/projects/aca-content/src/lib/services/content-management.service.ts @@ -570,7 +570,12 @@ export class ContentManagementService { const newVersionUploaderDialogData: NewVersionUploaderDialogData = { node, showVersionsOnly: true, - title: 'VERSION.DIALOG.TITLE' + title: 'VERSION.DIALOG.TITLE', + allowDownload: this.appSettingsService.uploadAllowDownload, + showComments: this.appSettingsService.uploadAllowComments, + showActions: this.appSettingsService.versionManagerShowActions, + allowViewVersions: this.appSettingsService.versionManagerAllowViewVersions, + allowVersionDelete: this.appSettingsService.versionManagerAllowVersionDelete }; this.newVersionUploaderService .openUploadNewVersionDialog(newVersionUploaderDialogData, { width: '630px', role: 'dialog' }, focusedElementOnCloseSelector) diff --git a/projects/aca-shared/src/lib/services/app-settings.service.ts b/projects/aca-shared/src/lib/services/app-settings.service.ts index 053f4638b3..2e6acde7ff 100644 --- a/projects/aca-shared/src/lib/services/app-settings.service.ts +++ b/projects/aca-shared/src/lib/services/app-settings.service.ts @@ -133,6 +133,27 @@ export class AppSettingsService { return this.appConfig.get('adf-version-manager.allowDownload', true); } + /** + * Allow to view versions if true, disallow otherwise. + */ + get versionManagerAllowViewVersions(): boolean { + return this.appConfig.get('adf-version-manager.allowViewVersions', true); + } + + /** + * Allow to delete versions if true, disallow otherwise. + */ + get versionManagerAllowVersionDelete(): boolean { + return this.appConfig.get('adf-version-manager.allowVersionDelete', true); + } + + /** + * Allow to open actions menu when true, otherwise hides it. + */ + get versionManagerShowActions(): boolean { + return this.appConfig.get('adf-version-manager.showActions', true); + } + /** * Gets the enablement of the file auto tryDownload feature from the app settings. */