[ACS-9083][ADW] Comment creation is available after document is retained (declared as record) (#4359)

This commit is contained in:
dominikiwanekhyland
2025-01-30 10:32:04 +01:00
committed by GitHub
parent 2c1e2c63d6
commit 75f25e9741
4 changed files with 71 additions and 4 deletions

View File

@@ -29,17 +29,22 @@ import { NodePermissionService } from '@alfresco/aca-shared';
import { Node } from '@alfresco/js-api';
import { of } from 'rxjs';
import { AuthenticationService } from '@alfresco/adf-core';
import { ExternalNodePermissionCommentsTabService } from '@alfresco/aca-content';
describe('CommentsTabComponent', () => {
let component: CommentsTabComponent;
let fixture: ComponentFixture<CommentsTabComponent>;
let nodePermissionService: NodePermissionService;
let checked: string[];
let canAddComment = true;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, CommentsTabComponent],
providers: [{ provide: AuthenticationService, useValue: { onLogout: of({}) } }]
providers: [
{ provide: ExternalNodePermissionCommentsTabService, useValue: { canAddComments: () => canAddComment } },
{ provide: AuthenticationService, useValue: { onLogout: of({}) } }
]
});
nodePermissionService = TestBed.inject(NodePermissionService);
@@ -48,6 +53,7 @@ describe('CommentsTabComponent', () => {
component = fixture.componentInstance;
checked = null;
canAddComment = true;
spyOn(nodePermissionService, 'check').and.callFake((_source, permissions) => {
checked = permissions;
return true;
@@ -107,4 +113,28 @@ describe('CommentsTabComponent', () => {
expect(checked).toContain('update');
});
});
it('should return false if node permissions are correct and external service is not allowing it', async () => {
canAddComment = false;
component.node = {
id: 'test-node-id',
isFile: true,
isFolder: false
} as Node;
fixture.detectChanges();
await fixture.whenStable();
expect(component.canUpdateNode).toBe(false);
});
it('should return true if node permissions are correct and external service is allowing it', async () => {
canAddComment = true;
component.node = {
id: 'test-node-id',
isFile: true,
isFolder: false
} as Node;
fixture.detectChanges();
await fixture.whenStable();
expect(component.canUpdateNode).toBe(true);
});
});

View File

@@ -22,11 +22,12 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core';
import { Component, Input, OnInit, Optional, ViewEncapsulation } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { NodePermissionService, isLocked } from '@alfresco/aca-shared';
import { isLocked, NodePermissionService } from '@alfresco/aca-shared';
import { MatCardModule } from '@angular/material/card';
import { NodeCommentsModule } from '@alfresco/adf-content-services';
import { ExternalNodePermissionCommentsTabService } from './external-node-permission-comments-tab.service';
@Component({
standalone: true,
@@ -45,7 +46,10 @@ export class CommentsTabComponent implements OnInit {
canUpdateNode = false;
constructor(private permission: NodePermissionService) {}
constructor(
private readonly permission: NodePermissionService,
@Optional() private readonly externalPermissionNodeService: ExternalNodePermissionCommentsTabService
) {}
ngOnInit(): void {
if (!this.node) {
@@ -53,6 +57,9 @@ export class CommentsTabComponent implements OnInit {
}
if (this.node.isFolder || (this.node.isFile && !isLocked({ entry: this.node }))) {
this.canUpdateNode = this.permission.check(this.node, ['update']);
if (this.externalPermissionNodeService) {
this.canUpdateNode &&= this.externalPermissionNodeService.canAddComments(this.node);
}
}
}
}

View File

@@ -0,0 +1,29 @@
/*!
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Alfresco Example Content Application
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/
import { Node } from '@alfresco/js-api';
export abstract class ExternalNodePermissionCommentsTabService {
abstract canAddComments(node: Node): boolean;
}

View File

@@ -31,4 +31,5 @@ export * from './lib/aca-content.routes';
export * from './lib/extensions/core.extensions.module';
export * from './lib/store/initial-state';
export * from './lib/services/content-url.service';
export * from './lib/components/info-drawer/comments-tab/external-node-permission-comments-tab.service';
export * from './lib/utils/aca-search-utils';