Skip to content

Commit

Permalink
[MNT-24660] version list action cannot be disabled using app conf (#4182
Browse files Browse the repository at this point in the history
)

* MNT-24660 Fixed config settings for version manager

* MNT-24660 Unit tests

* MNT-24660 Added possibility to hide and show delete version option

* MNT-24660 Property to show or hide version actions

* MNT-24660 Added more tests, updated documentation

* MNT-24660 Additional documentation

* MNT-24660 Additional fixes

* MNT-24660 Reverted not wanted change

* MNT-24660 Reverted not wanted change
  • Loading branch information
AleksanderSklorz authored Oct 21, 2024
1 parent 0744dfc commit dfa155d
Show file tree
Hide file tree
Showing 11 changed files with 303 additions and 21 deletions.
3 changes: 3 additions & 0 deletions docs/features/info-drawer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
32 changes: 22 additions & 10 deletions docs/features/version-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,48 @@ 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)

## Upload new version

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.
Binary file added docs/images/version-manager-action-toolbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/version-manager-action.png
Binary file not shown.
Binary file modified docs/images/version-manager-dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/version-manager-tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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<VersionsTabComponent>;
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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ import { AppSettingsService } from '@alfresco/aca-shared';
selector: 'app-versions-tab',
template: `
<ng-container *ngIf="isFileSelected; else empty">
<adf-version-manager [showComments]="settings.uploadAllowComments" [allowDownload]="settings.uploadAllowDownload" [node]="node">
<adf-version-manager
[showComments]="settings.uploadAllowComments"
[allowDownload]="settings.uploadAllowDownload"
[node]="node"
[allowViewVersions]="settings.versionManagerAllowViewVersions"
[allowVersionDelete]="settings.versionManagerAllowVersionDelete"
[showActions]="settings.versionManagerShowActions"
>
</adf-version-manager>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -61,6 +61,7 @@ import {
DocumentListService,
FileModel,
NewVersionUploaderDataAction,
NewVersionUploaderDialogData,
NewVersionUploaderService,
NodeAspectService,
NodesApiService,
Expand All @@ -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;
Expand All @@ -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);
});
Expand Down Expand Up @@ -1555,13 +1558,34 @@ 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 } };
fakeNodeIsNotFile = { entry: { id: '2', name: 'name1', isFile: false } };
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', () => {
Expand All @@ -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');
Expand Down
Loading

0 comments on commit dfa155d

Please sign in to comment.