diff --git a/docs/extending/rules.md b/docs/extending/rules.md index 7ca46ea0b..5c33042bf 100644 --- a/docs/extending/rules.md +++ b/docs/extending/rules.md @@ -168,6 +168,7 @@ The button will be visible only when the linked rule evaluates to `true`. | 1.8.0 | user.isAdmin | Checks if user is admin. | | 1.9.0 | app.canShowLanguagePicker | Whether language picker menu should be present or not. | | 1.9.0 | app.canShowLogout | Whether logout action should be present or not. | +| 1.12.0 | app.isLibraryManager | Checks if user is library manager. | ## Navigation Evaluators diff --git a/e2e/suites/actions-available/libraries/test-data-libraries.ts b/e2e/suites/actions-available/libraries/test-data-libraries.ts index ff584f342..ef864eba9 100644 --- a/e2e/suites/actions-available/libraries/test-data-libraries.ts +++ b/e2e/suites/actions-available/libraries/test-data-libraries.ts @@ -38,12 +38,12 @@ const memberToolbarPrimary = ['Leave Library', 'View Details', 'More Actions']; const favToolbarMore = ['Delete', 'Remove Favorite']; const notFavToolbarMore = ['Delete', 'Favorite']; const searchMemberToolbarPrimary = ['Toggle search filter', 'Leave Library', 'View Details', 'More Actions']; -const searchReqJoinToolbarPrimary = ['Toggle search filter', 'Cancel Join Request', 'View Details', 'More Actions']; -const searchNotMemberToolbarPrimary = ['Toggle search filter', 'Join', 'View Details', 'More Actions']; -const reqJoinToolbarMore = ['Cancel Join Request', 'View Details', 'More Actions']; +const searchReqJoinToolbarPrimary = ['Toggle search filter', 'Cancel Join Request', 'More Actions']; +const searchNotMemberToolbarPrimary = ['Toggle search filter', 'Join', 'More Actions']; +const reqJoinToolbarMore = ['Cancel Join Request', 'More Actions']; const notMemberFavContextMenu = ['Join', 'Delete', 'Remove Favorite']; const notMemberNotFavContextMenu = ['Join', 'Delete', 'Favorite']; -const notMemberToolbarPrimary = ['Join', 'View Details', 'More Actions']; +const notMemberToolbarPrimary = ['Join', 'More Actions']; const reqJoinNotFavContextMenu = ['Cancel Join Request', 'Delete', 'Favorite']; const reqJoinFavContextMenu = ['Cancel Join Request', 'Delete', 'Remove Favorite']; diff --git a/e2e/suites/info-drawer/library-properties.test.ts b/e2e/suites/info-drawer/library-properties.test.ts index 1da27d803..8552dac0e 100755 --- a/e2e/suites/info-drawer/library-properties.test.ts +++ b/e2e/suites/info-drawer/library-properties.test.ts @@ -112,7 +112,7 @@ describe('Library properties', () => { await infoDrawer.waitForInfoDrawerToOpen(); expect(await infoDrawer.getHeaderTitle()).toEqual('Details'); - expect(await infoDrawer.isAboutTabDisplayed()).toBe(true, 'About tab is not displayed'); + expect(await infoDrawer.isPropertiesTabDisplayed()).toBe(true, 'Properties tab is not displayed'); expect(await aboutTab.isNameDisplayed()).toBe(true, 'Name field not displayed'); expect(await aboutTab.isLibraryIdDisplayed()).toBe(true, 'Library ID field not displayed'); expect(await aboutTab.isVisibilityDisplayed()).toBe(true, 'Visibility field not displayed'); @@ -236,14 +236,11 @@ describe('Library properties', () => { done(); }); - it('[C289337] Edit button is not displayed when user is not the library manager', async () => { + it('[C289337] Info drawer button is not displayed when user is not the library manager', async () => { await loginPage.loginWith(user2); - await page.clickFileLibrariesAndWait(); await dataTable.selectItem(site.name); - await page.toolbar.viewDetailsButton.click(); - await infoDrawer.waitForInfoDrawerToOpen(); - expect(await aboutTab.isEditLibraryPropertiesDisplayed()).toBe(false, 'Edit action is displayed'); + expect(await page.toolbar.isButtonPresent('View Details')).toBe(false, 'View Details is present'); }); it('[C289344] Error notification', async () => { diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index 06d352f25..0c22cfd6f 100644 --- a/projects/aca-shared/rules/src/app.rules.spec.ts +++ b/projects/aca-shared/rules/src/app.rules.spec.ts @@ -475,4 +475,34 @@ describe('app.evaluators', () => { expect(app.canShowLogout(context)).toBe(true); }); }); + + describe('isLibraryManager', () => { + it('should return true when role is SiteManager', () => { + const context: any = { + selection: { + library: { + entry: { + role: 'SiteManager' + } + } + } + }; + + expect(app.isLibraryManager(context)).toBe(true); + }); + + it('should return false when role is different than SiteManager', () => { + const context: any = { + selection: { + library: { + entry: { + role: 'SiteCollaborator' + } + } + } + }; + + expect(app.isLibraryManager(context)).toBe(false); + }); + }); }); diff --git a/projects/aca-shared/rules/src/app.rules.ts b/projects/aca-shared/rules/src/app.rules.ts index 11381309e..b5df61c9f 100644 --- a/projects/aca-shared/rules/src/app.rules.ts +++ b/projects/aca-shared/rules/src/app.rules.ts @@ -546,3 +546,16 @@ export function canShowLanguagePicker(context: AcaRuleContext): boolean { export function canShowLogout(context: AcaRuleContext): boolean { return !context.withCredentials; } + +/** + * Checks if user is library manager + * JSON ref: `isLibraryManager` + * @param context Rule execution context + */ +export function isLibraryManager(context: RuleContext): boolean { + return ( + hasLibrarySelected(context) && + context.selection.library.entry && + context.selection.library.entry.role === 'SiteManager' + ); +} diff --git a/src/app/extensions/core.extensions.module.ts b/src/app/extensions/core.extensions.module.ts index d83fa19d2..659be1f97 100644 --- a/src/app/extensions/core.extensions.module.ts +++ b/src/app/extensions/core.extensions.module.ts @@ -131,6 +131,7 @@ export class CoreExtensionsModule { canManagePermissions: rules.canManagePermissions, canToggleEditOffline: rules.canToggleEditOffline, canToggleFavorite: rules.canToggleFavorite, + isLibraryManager: rules.isLibraryManager, 'app.selection.canDelete': rules.canDeleteSelection, 'app.selection.file.canUnlock': rules.canUnlockFile, diff --git a/src/assets/app.extensions.json b/src/assets/app.extensions.json index 7dc17cd1c..c193580b3 100644 --- a/src/assets/app.extensions.json +++ b/src/assets/app.extensions.json @@ -46,6 +46,14 @@ { "type": "rule", "value": "app.navigation.isNotSearchResults" }, { "type": "rule", "value": "app.navigation.isNotFavorites" } ] + }, + { + "id": "app.toolbar.favorite.canEditMetadata", + "type": "core.every", + "parameters": [ + { "type": "rule", "value": "app.selection.library" }, + { "type": "rule", "value": "isLibraryManager" } + ] } ], @@ -345,7 +353,7 @@ "order": 800, "component": "app.toolbar.toggleInfoDrawer", "rules": { - "visible": "app.selection.library" + "visible": "app.toolbar.favorite.canEditMetadata" } }, { @@ -1040,10 +1048,10 @@ { "id": "app.sidebar.library.properties", "order": 500, - "title": "APP.INFO_DRAWER.TABS.LIBRARY_PROPERTIES", + "title": "APP.INFO_DRAWER.TABS.PROPERTIES", "component": "app.components.tabs.library.metadata", "rules": { - "visible": "app.selection.library" + "visible": "app.toolbar.favorite.canEditMetadata" } } ]