Skip to content

Commit

Permalink
'Add Assets' button can now be hidden by IMS group
Browse files Browse the repository at this point in the history
- Added checkAddAssetsAccess() that will compare 'imsAuthorGroup' in 'admin-config.xlsx' in sharepoint to the IMS groups of the current user.
- Code that loads the 'Add Assets' button will now not execute unless checkAddAssetsAccess() returns true.
  • Loading branch information
cheintzman committed Mar 8, 2024
1 parent 27bfdc9 commit a08f22d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
5 changes: 3 additions & 2 deletions blocks/adp-assets-actions/adp-assets-actions.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { openUploadDialog } from '../../contenthub/hydration/hydration.js';
import { decorateIcons } from '../../scripts/lib-franklin.js';
import { checkAddAssetsAccess } from '../../scripts/security.js';
import { isContentHub } from '../../scripts/site-config.js';

export default async function decorate(block) {
block.innerHTML = '';
const assetActionsDiv = document.createElement('div');
assetActionsDiv.className = 'actions-container';
// add Asset actions button
if (await isContentHub()) {
//add Asset actions button
if (await isContentHub() && await checkAddAssetsAccess()) {
const addAssetsButton = document.createElement('button');
addAssetsButton.classList.add('action', 'add-assets');
const addAssetsSpan = document.createElement('span');
Expand Down
29 changes: 15 additions & 14 deletions blocks/adp-header/adp-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
import {
getBrandingConfig, getQuickLinkConfig, isUrlPathNonRoot, getBaseConfigPath,
} from '../../scripts/site-config.js';
import { getUserProfile, getAvatarUrl, isPublicPage } from '../../scripts/security.js';
import { getUserProfile, getAvatarUrl, isPublicPage, checkAddAssetsAccess } from '../../scripts/security.js';
import { closeDialogEvent, createLinkHref, getSelectedAssetsFromInfiniteResultsBlock } from '../../scripts/shared.js';
import { EventNames, addEventListener, emitEvent } from '../../scripts/events.js';
import { openShareModalMultiSelectedAssets } from '../adp-share-modal/adp-share-modal.js';
Expand Down Expand Up @@ -315,7 +315,7 @@ async function handleRemoveMultiSelectedAssetsFromCollection() {
window.location.reload();
}

function initQuickLinks() {
async function initQuickLinks() {
if (document.querySelector('head meta[name="hide-quicklinks"]')?.getAttribute('content') === 'true') {
return;
}
Expand All @@ -341,18 +341,19 @@ function initQuickLinks() {
quickLinks.append(itemEl);
});

const navDiv = document.createElement('div');
navDiv.classList.add('item');
const addAssetsButton = document.createElement('button');
addAssetsButton.classList.add('action', 'add-assets');
navDiv.appendChild(addAssetsButton);
addAssetsButton.appendChild(document.createTextNode('Add Assets'));
addAssetsButton.addEventListener('click', () => {
openUploadDialog();
});
quickLinks.appendChild(navDiv);

// set aria-selected on quick links
if (await checkAddAssetsAccess()) {
const navDiv = document.createElement('div');
navDiv.classList.add('item');
const addAssetsButton = document.createElement('button');
addAssetsButton.classList.add('action', 'add-assets');
navDiv.appendChild(addAssetsButton);
addAssetsButton.appendChild(document.createTextNode('Add Assets'));
addAssetsButton.addEventListener('click', () => {
openUploadDialog();
});
quickLinks.appendChild(navDiv);
}
//set aria-selected on quick links
quickLinks.querySelectorAll('.item').forEach((item) => {
if (item.querySelector('a')?.dataset.page === window.location.pathname) {
item.setAttribute('aria-selected', 'true');
Expand Down
8 changes: 8 additions & 0 deletions scripts/security.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { fetchCached } from './fetch-util.js';
import { isUnifiedShellRuntimeAvailable, shell, user } from '../contenthub/unified-shell.js';
import { getAdminConfig } from './site-config.js';
import { getSecurityGroupMemberships } from './security-imslib.js';

/**
* @return {Promise<{imsOrgWithoutDomain: {string}, imsEnvironment: {string}, imsOrgID: {string}}|null>}
Expand Down Expand Up @@ -111,3 +113,9 @@ export async function checkUserAccess() {
}
}
}

export async function checkAddAssetsAccess() {
const adminConfig = await getAdminConfig();
const securityGroupMemberships = await getSecurityGroupMemberships(await getBearerToken());
return securityGroupMemberships.some((grp) => grp.groupName === adminConfig.imsAuthorGroup);
}

0 comments on commit a08f22d

Please sign in to comment.