diff --git a/projects/aca-content/assets/app.extensions.json b/projects/aca-content/assets/app.extensions.json index 34d8568eb..66a77d937 100644 --- a/projects/aca-content/assets/app.extensions.json +++ b/projects/aca-content/assets/app.extensions.json @@ -143,8 +143,7 @@ "click": "CREATE_FOLDER" }, "rules": { - "enabled": "app.navigation.folder.canCreate", - "visible": "app.isContentServiceEnabled" + "visible": "app.navigation.folder.canCreate" } }, { @@ -157,7 +156,7 @@ "click": "CREATE_LIBRARY" }, "rules": { - "visible": "app.isContentServiceEnabled" + "visible": "app.canCreateLibrary" } }, { @@ -171,8 +170,7 @@ "click": "FILE_FROM_TEMPLATE" }, "rules": { - "enabled": "app.navigation.folder.canUpload", - "visible": "app.isContentServiceEnabled" + "visible": "app.navigation.folder.canUpload" } }, { @@ -186,8 +184,7 @@ "click": "FOLDER_FROM_TEMPLATE" }, "rules": { - "enabled": "app.navigation.folder.canUpload", - "visible": "app.isContentServiceEnabled" + "visible": "app.navigation.folder.canUpload" } } ], @@ -198,13 +195,11 @@ "icon": "file_upload", "title": "APP.NEW_MENU.MENU_ITEMS.UPLOAD_FILE", "description": "APP.NEW_MENU.TOOLTIPS.UPLOAD_FILES", - "description-disabled": "APP.NEW_MENU.TOOLTIPS.UPLOAD_FILES_NOT_ALLOWED", "actions": { "click": "UPLOAD_FILES" }, "rules": { - "enabled": "app.navigation.folder.canUpload", - "visible": "app.isContentServiceEnabled" + "visible": "app.isUploadSupported" } }, { @@ -213,13 +208,11 @@ "icon": "file_upload", "title": "APP.NEW_MENU.MENU_ITEMS.UPLOAD_FOLDER", "description": "APP.NEW_MENU.TOOLTIPS.UPLOAD_FOLDERS", - "description-disabled": "APP.NEW_MENU.TOOLTIPS.UPLOAD_FOLDERS_NOT_ALLOWED", "actions": { "click": "UPLOAD_FOLDER" }, "rules": { - "enabled": "app.navigation.folder.canUpload", - "visible": "app.isContentServiceEnabled" + "visible": "app.isUploadSupported" } } ], diff --git a/projects/aca-content/src/lib/components/header-actions/header-actions.component.ts b/projects/aca-content/src/lib/components/header-actions/header-actions.component.ts index 0a0f6a718..4019bea0f 100644 --- a/projects/aca-content/src/lib/components/header-actions/header-actions.component.ts +++ b/projects/aca-content/src/lib/components/header-actions/header-actions.component.ts @@ -24,7 +24,6 @@ */ import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core'; -import { Router } from '@angular/router'; import { Store } from '@ngrx/store'; import { AppExtensionService } from '@alfresco/aca-shared'; import { SetCurrentFolderAction, AppStore } from '@alfresco/aca-shared/store'; @@ -44,7 +43,7 @@ export class HeaderActionsComponent implements OnInit, OnDestroy { createActions: Array = []; uploadActions: Array = []; - constructor(private router: Router, private store: Store, private extensions: AppExtensionService) {} + constructor(private store: Store, private extensions: AppExtensionService) {} ngOnInit(): void { this.extensions @@ -72,24 +71,12 @@ export class HeaderActionsComponent implements OnInit, OnDestroy { return action.id; } - private isPersonalFilesRoute(): boolean { - return this.router.url.includes('/personal-files'); - } - - private isFavoriteLibrariesRoute(): boolean { - return this.router.url.includes('/favorite/libraries'); - } - - private isLibrariesRoute(): boolean { - return this.router.url.includes('/libraries'); - } - canShowCreateButton(): boolean { - return this.createActions.length > 0 && (this.isPersonalFilesRoute() || this.isFavoriteLibrariesRoute() || this.isLibrariesRoute()); + return this.createActions.length > 0; } canShowUploadButton(): boolean { - return this.uploadActions.length > 0 && this.isPersonalFilesRoute(); + return this.uploadActions.length > 0; } canShowSearchSeparator(): boolean { diff --git a/projects/aca-shared/rules/src/app.rules.ts b/projects/aca-shared/rules/src/app.rules.ts index f4a1cc405..792f8d642 100644 --- a/projects/aca-shared/rules/src/app.rules.ts +++ b/projects/aca-shared/rules/src/app.rules.ts @@ -91,6 +91,14 @@ export interface AcaRuleContext extends RuleContext { */ export const isContentServiceEnabled = (): boolean => localStorage && localStorage.getItem('contentService') !== 'false'; +/** + * Checks if upload action is supported for the given context + * JSON ref: `app.isUploadSupported` + * + * @param content Rule execution context + */ +export const isUploadSupported = (context: RuleContext): boolean => + [isContentServiceEnabled(), navigation.isPersonalFiles(context) || navigation.isLibraryContent(context), canUpload(context)].every(Boolean); /** * Checks if user can copy selected node. * JSON ref: `app.canCopyNode` @@ -227,21 +235,35 @@ export const hasSelection = (context: RuleContext): boolean => !context.selectio * JSON ref: `app.navigation.folder.canCreate` */ export function canCreateFolder(context: RuleContext): boolean { - const { currentFolder } = context.navigation; - if (currentFolder) { - return context.permissions.check(currentFolder, ['create']); + if (isContentServiceEnabled() && (navigation.isPersonalFiles(context) || navigation.isLibraryContent(context))) { + const { currentFolder } = context.navigation; + + if (currentFolder) { + return context.permissions.check(currentFolder, ['create']); + } } return false; } +/** + * Checks if user can create a Library + * JSON ref: `app.canCreateLibrary` + * + * @param context Rule execution context + */ +export const canCreateLibrary = (context: RuleContext): boolean => [isContentServiceEnabled(), navigation.isLibraries(context)].every(Boolean); + /** * Checks if user can upload content to current folder. * JSON ref: `app.navigation.folder.canUpload` */ export function canUpload(context: RuleContext): boolean { - const { currentFolder } = context.navigation; - if (currentFolder) { - return context.permissions.check(currentFolder, ['create']); + if (isContentServiceEnabled() && (navigation.isPersonalFiles(context) || navigation.isLibraryContent(context))) { + const { currentFolder } = context.navigation; + + if (currentFolder) { + return context.permissions.check(currentFolder, ['create']); + } } return false; } diff --git a/projects/aca-shared/rules/src/navigation.rules.ts b/projects/aca-shared/rules/src/navigation.rules.ts index 1d6c56ea6..9e922725a 100644 --- a/projects/aca-shared/rules/src/navigation.rules.ts +++ b/projects/aca-shared/rules/src/navigation.rules.ts @@ -106,6 +106,11 @@ export function isLibraries(context: RuleContext): boolean { return url && (url.endsWith('/libraries') || url.startsWith('/search-libraries')); } +export function isLibraryContent(context: RuleContext): boolean { + const { url } = context.navigation; + return url && (url.endsWith('/libraries') || url.includes('/libraries/') || url.startsWith('/search-libraries')); +} + /** * Checks if the activated route is neither **Libraries** nor **Library Search Results**. * JSON ref: `app.navigation.isNotLibraries`