diff --git a/projects/aca-content/src/lib/components/info-drawer/comments-tab/comments-tab.component.spec.ts b/projects/aca-content/src/lib/components/info-drawer/comments-tab/comments-tab.component.spec.ts index 7e88e7b6b..be2d89448 100644 --- a/projects/aca-content/src/lib/components/info-drawer/comments-tab/comments-tab.component.spec.ts +++ b/projects/aca-content/src/lib/components/info-drawer/comments-tab/comments-tab.component.spec.ts @@ -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; 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); + }); }); diff --git a/projects/aca-content/src/lib/components/info-drawer/comments-tab/comments-tab.component.ts b/projects/aca-content/src/lib/components/info-drawer/comments-tab/comments-tab.component.ts index 52332d3ea..7ab27c2ed 100644 --- a/projects/aca-content/src/lib/components/info-drawer/comments-tab/comments-tab.component.ts +++ b/projects/aca-content/src/lib/components/info-drawer/comments-tab/comments-tab.component.ts @@ -22,11 +22,12 @@ * from Hyland Software. If not, see . */ -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); + } } } } diff --git a/projects/aca-content/src/lib/components/info-drawer/comments-tab/external-node-permission-comments-tab.service.ts b/projects/aca-content/src/lib/components/info-drawer/comments-tab/external-node-permission-comments-tab.service.ts new file mode 100644 index 000000000..8903e7825 --- /dev/null +++ b/projects/aca-content/src/lib/components/info-drawer/comments-tab/external-node-permission-comments-tab.service.ts @@ -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 . + */ + +import { Node } from '@alfresco/js-api'; + +export abstract class ExternalNodePermissionCommentsTabService { + abstract canAddComments(node: Node): boolean; +} diff --git a/projects/aca-content/src/public-api.ts b/projects/aca-content/src/public-api.ts index 21a0df3aa..8b6d1c60b 100644 --- a/projects/aca-content/src/public-api.ts +++ b/projects/aca-content/src/public-api.ts @@ -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';