Skip to content

Commit

Permalink
Merge branch 'ASSETS-02024' into assets-98990
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickson-adbe committed Apr 5, 2024
2 parents 3c17743 + cff5f20 commit ba03cfb
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 8 deletions.
1 change: 1 addition & 0 deletions contenthub/hydration/hydration-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export function getMetadataSchema(facetOptions){
{ name: 'Digital Editions', id: 'digital-editions' },
{ name: 'Dreamweaver', id: 'dreamweaver' },
{ name: 'Fill Sign', id: 'fill-sign' },
{ name: 'Firefly', id: 'firefly' },
{ name: 'Frame.io', id: 'frame-io' },
{ name: 'Fresco', id: 'fresco' },
{ name: 'Http Dynamic Streaming', id: 'http-dynamic-streaming' },
Expand Down
2 changes: 1 addition & 1 deletion contenthub/hydration/hydration.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export async function openUploadDialog() {
dialogBody.appendChild(container);

const folderUUID = crypto.randomUUID();
const targetUploadPath = `/content/dam/hydrated-assets/${folderUUID.substring(0, 2)}/${folderUUID.substring(
const targetUploadPath = `/content/dam/gmo/upload/${folderUUID.substring(0, 2)}/${folderUUID.substring(
2,
4,
)}/${folderUUID}`;
Expand Down
65 changes: 65 additions & 0 deletions scripts/graphql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { getBearerToken } from './security.js';
import { getAdminConfig } from './site-config.js';

export async function graphqlAllCampaigns() {

const baseApiUrl = `${await getGraphqlEndpoint()}/graphql/execute.json`;
const projectId = 'gmo';
const queryName = 'getAllCampaigns'; //Todo Shivani will rename query to allCampaigns
const graphqlEndpoint = `${baseApiUrl}/${projectId}/${queryName}`;
const jwtToken = await getBearerToken();

// Return the fetch promise chain so that it can be awaited outside
return fetch(graphqlEndpoint, {
method: 'GET',
headers: {
Authorization: jwtToken,
},
}).then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
}).then(data => {
return data; // Make sure to return the data so that the promise resolves with it
}).catch(error => {
console.error('Error fetching data: ', error);
throw error; // Rethrow or handle error as appropriate
});
}

export async function graphqlCampaignByName(campaignName) {

const baseApiUrl = `${await getGraphqlEndpoint()}/graphql/execute.json`;
const projectId = 'gmo';
const queryName = 'campaign-name-in-param';
const encodedCampaignName = encodeURIComponent(campaignName);
const encodedSemiColon = encodeURIComponent(';');
//persisted query URLs have to be encoded together with the first semicolon
const graphqlEndpoint = `${baseApiUrl}/${projectId}/${queryName}${encodedSemiColon}campaignName=${encodedCampaignName}`;
const jwtToken = await getBearerToken();

// Return the fetch promise chain so that it can be awaited outside
return fetch(graphqlEndpoint, {
method: 'GET',
headers: {
Authorization: jwtToken,
},
}).then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
}).then(data => {
return data; // Make sure to return the data so that the promise resolves with it
}).catch(error => {
console.error('Error fetching data: ', error);
throw error; // Rethrow or handle error as appropriate
});
}


async function getGraphqlEndpoint() {
const result = await getAdminConfig();
return result.aemGraphqlEndpoint;
}
29 changes: 25 additions & 4 deletions scripts/security.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fetchCached } from './fetch-util.js';
import { isUnifiedShellRuntimeAvailable, shell, user } from '../contenthub/unified-shell.js';
import { getAdminConfig } from './site-config.js';
import { getAdminConfig, getBrandingConfig, isContentHub, getQuickLinkConfig, getBaseConfigPath } from './site-config.js';
import { getSecurityGroupMemberships } from './security-imslib.js';

/**
Expand Down Expand Up @@ -104,13 +104,34 @@ export async function checkUserAccess() {
const imsLibSecurityModule = await import('./security-imslib.js');
if (isPublicPage()) {
return true;
}
return await imsLibSecurityModule.isUserInSecurityGroup(imsUserGroup, await getBearerToken());
}

const isIMSUser = await imsLibSecurityModule.isUserInSecurityGroup(imsUserGroup, await getBearerToken());
if (isIMSUser) {
//Check if current page is present in the array of pages returned by function getQuickLinkConfig()
const presentInQuickLinks = (await getQuickLinkConfig()).some((grp) => grp.page === (window.location.pathname.replace(getBaseConfigPath((window.location.pathname)),'')));
return presentInQuickLinks;
}
else
{ //Not IMSUser
return isIMSUser;
}
}
}

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

/**
* Checks Group Access for the group that is stored in the admin-config.xslx for
* for the property name in parameter adminConfigGroupPropertyName
* @returns {boolean} for access to the group
*/
export async function checkPageGroupAccess(adminConfigGroupPropertyName) {
const adminConfig = await getAdminConfig();
const securityGroupMemberships = await getSecurityGroupMemberships(await getBearerToken());
return securityGroupMemberships.some((grp) => grp.groupName === adminConfig[adminConfigGroupPropertyName]);
}
16 changes: 13 additions & 3 deletions scripts/site-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fetchCached } from './fetch-util.js';
import { toCamelCase } from './lib-franklin.js';
import { checkPageGroupAccess } from './security.js';

const QA_BASE_PATH = 'qa';
const DRAFTS_BASE_PATH = 'drafts';
Expand Down Expand Up @@ -285,14 +286,23 @@ async function mapUserSettingsForId(configId, result) {
export async function getQuickLinkConfig() {
const result = [];
const response = await getConfig('site-config.json');
response.quicklinks?.data.forEach((row) => {
if (row.Title && row.Page) {

for (const row of response.quicklinks?.data || []) {
if (row.Title && row.Page && row.Group == '') {
result.push({
title: row.Title,
page: row.Page,
});
} else if (row.Title && row.Page && row.Group) {
if (await checkPageGroupAccess(row.Group))
{
result.push({
title: row.Title,
page: row.Page,
});
}
}
});
}
return result;
}

Expand Down

0 comments on commit ba03cfb

Please sign in to comment.