From df4a80f64154fb9cdfdcd27aaa508e34e2ff8c73 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 11 Oct 2022 22:21:30 +0100 Subject: [PATCH] [MNT-22754] fix context menus for records (#2706) * fix context menus for records * fix unit tests * fix unit tests --- .../aca-shared/rules/src/app.rules.spec.ts | 6 +++- projects/aca-shared/rules/src/app.rules.ts | 6 +++- projects/aca-shared/rules/src/public-api.ts | 1 + projects/aca-shared/rules/src/record.rules.ts | 36 +++++++++++++++++++ .../src/lib/evaluators.spec.ts | 2 ++ .../src/lib/evaluators.ts | 3 +- 6 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 projects/aca-shared/rules/src/record.rules.ts diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index b0f2599b9..5a5a17253 100644 --- a/projects/aca-shared/rules/src/app.rules.spec.ts +++ b/projects/aca-shared/rules/src/app.rules.spec.ts @@ -345,7 +345,11 @@ describe('app.evaluators', () => { check: () => (checked = true) }, selection: { - file: {}, + file: { + entry: { + isFile: true + } + }, isEmpty: false, nodes: [ { diff --git a/projects/aca-shared/rules/src/app.rules.ts b/projects/aca-shared/rules/src/app.rules.ts index fe1887e77..cfedc760f 100644 --- a/projects/aca-shared/rules/src/app.rules.ts +++ b/projects/aca-shared/rules/src/app.rules.ts @@ -26,6 +26,7 @@ import { AppConfigService } from '@alfresco/adf-core'; import { RuleContext } from '@alfresco/adf-extensions'; import * as navigation from './navigation.rules'; +import { isNodeRecord } from './record.rules'; import * as repository from './repository.rules'; import { isAdmin } from './user.rules'; @@ -358,6 +359,7 @@ export function canUploadVersion(context: RuleContext): boolean { return [ hasFileSelected(context), navigation.isNotTrashcan(context), + !isNodeRecord(context), isWriteLocked(context) ? isUserWriteLockOwner(context) : canUpdateSelectedNode(context) ].every(Boolean); } @@ -444,7 +446,9 @@ export const canManagePermissions = (context: RuleContext): boolean => * @param context Rule execution context */ export const canToggleEditOffline = (context: RuleContext): boolean => - [hasFileSelected(context), navigation.isNotTrashcan(context), canLockFile(context) || canUnlockFile(context)].every(Boolean); + [hasFileSelected(context), navigation.isNotTrashcan(context), canLockFile(context) || canUnlockFile(context), !isNodeRecord(context)].every( + Boolean + ); /** * @deprecated Uses workarounds for for recent files and search api issues. diff --git a/projects/aca-shared/rules/src/public-api.ts b/projects/aca-shared/rules/src/public-api.ts index 56fded04e..a9c270267 100644 --- a/projects/aca-shared/rules/src/public-api.ts +++ b/projects/aca-shared/rules/src/public-api.ts @@ -27,3 +27,4 @@ export * from './app.rules'; export * from './navigation.rules'; export * from './repository.rules'; export * from './user.rules'; +export * from './record.rules'; diff --git a/projects/aca-shared/rules/src/record.rules.ts b/projects/aca-shared/rules/src/record.rules.ts new file mode 100644 index 000000000..9eb98767e --- /dev/null +++ b/projects/aca-shared/rules/src/record.rules.ts @@ -0,0 +1,36 @@ +/*! + * @license + * Alfresco Example Content Application + * + * Copyright (C) 2005 - 2020 Alfresco Software Limited + * + * 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 + * along with Alfresco. If not, see . + */ + +import { RuleContext } from '@alfresco/adf-extensions'; + +export function isNodeRecord(context: RuleContext): boolean { + const { file } = context.selection; + return ( + file && + file.entry.isFile && + file.entry.aspectNames && + (file.entry.aspectNames.includes('rma:declaredRecord') || file.entry.aspectNames.includes('rma:record')) + ); +} diff --git a/projects/adf-office-services-ext/src/lib/evaluators.spec.ts b/projects/adf-office-services-ext/src/lib/evaluators.spec.ts index d5e850528..d087b2dec 100644 --- a/projects/adf-office-services-ext/src/lib/evaluators.spec.ts +++ b/projects/adf-office-services-ext/src/lib/evaluators.spec.ts @@ -86,6 +86,7 @@ describe('evaluators', () => { selection: { file: { entry: { + isFile: true, name: 'document.docx', isLocked: false, properties: {}, @@ -105,6 +106,7 @@ describe('evaluators', () => { selection: { file: { entry: { + isFile: true, name: 'document.docx', isLocked: false, properties: {}, diff --git a/projects/adf-office-services-ext/src/lib/evaluators.ts b/projects/adf-office-services-ext/src/lib/evaluators.ts index 42cb801f4..b8f5ab8b4 100644 --- a/projects/adf-office-services-ext/src/lib/evaluators.ts +++ b/projects/adf-office-services-ext/src/lib/evaluators.ts @@ -24,6 +24,7 @@ */ import { RuleContext } from '@alfresco/adf-extensions'; +import { isNodeRecord } from '@alfresco/aca-shared/rules'; import { getFileExtension, supportedExtensions } from './utils'; export function canOpenWithOffice(context: RuleContext): boolean { @@ -76,7 +77,7 @@ export function canOpenWithOffice(context: RuleContext): boolean { } // check if record - if (file.entry.aspectNames && (file.entry.aspectNames.includes('rma:declaredRecord') || file.entry.aspectNames.includes('rma:record'))) { + if (isNodeRecord(context)) { return false; }