Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Add Assets' button can now be hidden by IMS group #44

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading