Skip to content

Commit

Permalink
Merge pull request #303 from adobecom/series-users
Browse files Browse the repository at this point in the history
User access update (based on pending SMC changes)
  • Loading branch information
qiyundai authored Dec 17, 2024
2 parents e216526 + 436b2bf commit 5187579
Show file tree
Hide file tree
Showing 21 changed files with 362 additions and 181 deletions.
27 changes: 11 additions & 16 deletions ecc/blocks/attendee-management-table/attendee-management-table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-len */
import { getAllEventAttendees, getEvents } from '../../scripts/esp-controller.js';
import { getAllEventAttendees, getEventsForUser } from '../../scripts/esp-controller.js';
import { LIBS } from '../../scripts/scripts.js';
import {
getIcon,
Expand All @@ -12,7 +12,7 @@ import {
} from '../../scripts/utils.js';
import SearchablePicker from '../../components/searchable-picker/searchable-picker.js';
import FilterMenu from '../../components/filter-menu/filter-menu.js';
import { initProfileLogicTree } from '../../scripts/event-apis.js';
import { getUser, initProfileLogicTree, userHasAccessToEvent } from '../../scripts/profile.js';

const { createTag } = await import(`${LIBS}/utils/utils.js`);

Expand Down Expand Up @@ -512,16 +512,6 @@ function buildDashboardTable(props, config) {
populateTable(props, config);
}

async function getEventsArray() {
const resp = await getEvents();

if (resp.error) {
return [];
}

return resp.events;
}

function renderTableLoadingOverlay(props) {
const tableContainer = props.el.querySelector('.dashboard-table-container');
const loadingOverlay = createTag('div', { class: 'loading-overlay' });
Expand Down Expand Up @@ -628,7 +618,7 @@ async function buildDashboard(el, config) {
createTag('div', { class: 'dashboard-body-container' }, '', { parent: mainContainer });

const uspEventId = new URLSearchParams(window.location.search).get('eventId');
const events = await getEventsArray();
const events = await getEventsForUser();

const props = {
el,
Expand All @@ -644,8 +634,13 @@ async function buildDashboard(el, config) {
let data = [];

if (props.currentEventId) {
const resp = await getAllEventAttendees(props.currentEventId);
if (resp && !resp.error) data = resp;
if (userHasAccessToEvent(await getUser(), props.currentEventId)) {
const resp = await getAllEventAttendees(props.currentEventId);
if (resp && !resp.error) data = resp;
} else {
buildNoAccessScreen(el);
return;
}
}

props.data = data;
Expand Down Expand Up @@ -722,7 +717,7 @@ export default async function init(el) {
return;
}

initProfileLogicTree({
await initProfileLogicTree('attendee-management-table', {
noProfile: () => {
signIn();
},
Expand Down
31 changes: 11 additions & 20 deletions ecc/blocks/ecc-dashboard/ecc-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
createEvent,
deleteEvent,
getEventImages,
getEvents,
getEventsForUser,
publishEvent,
unpublishEvent,
} from '../../scripts/esp-controller.js';
Expand All @@ -16,8 +16,9 @@ import {
getEventServiceEnv,
getDevToken,
} from '../../scripts/utils.js';
import { quickFilter } from '../../scripts/event-data-handler.js';
import { initProfileLogicTree } from '../../scripts/event-apis.js';

import { quickFilter } from '../event-creation-form/data-handler.js';
import { initProfileLogicTree } from '../../scripts/profile.js';

const { createTag } = await import(`${LIBS}/utils/utils.js`);

Expand Down Expand Up @@ -316,10 +317,10 @@ function initMoreOptions(props, config, eventObj, row) {
return;
}

const newJson = await getEvents();
props.data = newJson.events;
props.filteredData = newJson.events;
props.paginatedData = newJson.events;
const newJson = await getEventsForUser();
props.data = newJson;
props.filteredData = newJson;
props.paginatedData = newJson;
const modTimeHeader = props.el.querySelector('th.sortable.modificationTime');
if (modTimeHeader) {
props.currentSort = { field: 'modificationTime', el: modTimeHeader };
Expand Down Expand Up @@ -361,7 +362,7 @@ function initMoreOptions(props, config, eventObj, row) {
return;
}

const newJson = await getEvents();
const newJson = await getEventsForUser();
props.data = newJson.events;
props.filteredData = newJson.events;
props.paginatedData = newJson.events;
Expand Down Expand Up @@ -647,16 +648,6 @@ function buildDashboardTable(props, config) {
}
}

async function getEventsArray() {
const resp = await getEvents();

if (resp.error) {
return [];
}

return resp.events;
}

function buildNoEventScreen(el, config) {
el.classList.add('no-events');

Expand All @@ -681,7 +672,7 @@ async function buildDashboard(el, config) {
currentSort: {},
};

const data = await getEventsArray();
const data = await getEventsForUser();
if (!data?.length) {
buildNoEventScreen(el, config);
} else {
Expand Down Expand Up @@ -738,7 +729,7 @@ export default async function init(el) {
return;
}

initProfileLogicTree({
await initProfileLogicTree('ecc-dashboard', {
noProfile: () => {
signIn();
},
Expand Down
6 changes: 3 additions & 3 deletions ecc/blocks/event-creation-form/event-creation-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import ProductSelector from '../../components/product-selector/product-selector.
import ProductSelectorGroup from '../../components/product-selector-group/product-selector-group.js';
import PartnerSelector from '../../components/partner-selector/partner-selector.js';
import PartnerSelectorGroup from '../../components/partner-selector-group/partner-selector-group.js';
import getJoinedData, { getFilteredCachedResponse, hasContentChanged, quickFilter, setPayloadCache, setResponseCache } from '../../scripts/event-data-handler.js';
import getJoinedData, { getFilteredCachedResponse, hasContentChanged, quickFilter, setPayloadCache, setResponseCache } from './data-handler.js';
import CustomSearch from '../../components/custom-search/custom-search.js';
import { initProfileLogicTree } from '../../scripts/event-apis.js';
import { initProfileLogicTree } from '../../scripts/profile.js';

const { createTag } = await import(`${LIBS}/utils/utils.js`);
const { decorateButtons } = await import(`${LIBS}/utils/decorate.js`);
Expand Down Expand Up @@ -1060,7 +1060,7 @@ export default async function init(el) {
return;
}

initProfileLogicTree({
initProfileLogicTree('event-creation-form', {
noProfile: () => {
signIn();
},
Expand Down
18 changes: 15 additions & 3 deletions ecc/blocks/event-format-component/controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-unused-vars */
import { getAllSeries } from '../../scripts/esp-controller.js';
import { getSeriesForUser } from '../../scripts/esp-controller.js';
import BlockMediator from '../../scripts/deps/block-mediator.min.js';
import { LIBS } from '../../scripts/scripts.js';
import { changeInputValue } from '../../scripts/utils.js';
Expand Down Expand Up @@ -76,14 +76,26 @@ async function populateSeriesOptions(props, component) {
const seriesSelect = component.querySelector('#series-select-input');
if (!seriesSelect) return;

const { series } = await getAllSeries();
const series = await getSeriesForUser();

if (!series) {
seriesSelect.pending = false;
seriesSelect.disabled = true;
return;
}

Object.values(series).forEach((val) => {
Object.values(series).filter((s) => {
const hasRequiredVals = s.seriesId && s.seriesName;
const isPublished = s.seriesStatus?.toLowerCase() === 'published';

const currentCloud = props.eventDataResp.cloudType || props.payload.cloudType;
const isInCurrentCloud = s.cloudType === currentCloud;

return hasRequiredVals && isPublished && isInCurrentCloud;
}).forEach((val) => {
if (!val.seriesId || !val.seriesName) return;
if (val.seriesStatus?.toLowerCase() !== 'published') return;

const opt = createTag('sp-menu-item', { value: val.seriesId }, val.seriesName);
seriesSelect.append(opt);
});
Expand Down
7 changes: 2 additions & 5 deletions ecc/blocks/event-format-component/event-format-component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable max-len */
import { SUPPORTED_CLOUDS } from '../../constants/constants.js';
import { LIBS } from '../../scripts/scripts.js';
import { generateToolTip } from '../../scripts/utils.js';

Expand All @@ -15,10 +16,8 @@ async function decorateCloudTagSelect(column) {

// FIXME: cloulds shouldn't be hardcoded
// const clouds = await getClouds();
// const clouds = [{ id: 'CreativeCloud', name: 'Creative Cloud' }, { id: 'DX', name: 'Experience Cloud' }];
const clouds = [{ id: 'CreativeCloud', name: 'Creative Cloud' }];

Object.entries(clouds).forEach(([, val]) => {
Object.entries(SUPPORTED_CLOUDS).forEach(([, val]) => {
const opt = createTag('sp-menu-item', { value: val.id }, val.name);
select.append(opt);
});
Expand Down Expand Up @@ -69,8 +68,6 @@ export default function init(el) {
cols.forEach(async (c, ci) => {
if (ci === 0) decorateCloudTagSelect(c);
if (ci === 1) decorateSeriesSelect(c);
// if (ci === 2) decorateNewSeriesBtnAndModal(c);
// if (ci === 2) decorateCheckbox(c);
});
}

Expand Down
2 changes: 1 addition & 1 deletion ecc/blocks/event-partners-component/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
removeSponsorFromEvent,
updateSponsorInEvent,
} from '../../scripts/esp-controller.js';
import { getFilteredCachedResponse } from '../../scripts/event-data-handler.js';
import { getFilteredCachedResponse } from '../event-creation-form/data-handler.js';

let PARTNERS_SERIES_ID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ let responseCache = {};
let payloadCache = {};

const submissionFilter = [
// from payload and response
'agenda',
'topics',
'eventType',
Expand Down Expand Up @@ -57,6 +56,13 @@ export function setPayloadCache(payload) {
}

export function getFilteredCachedPayload() {
const { topics } = payloadCache;

if (topics) {
payloadCache.topics = Object.values(topics).reduce((acc, val) => acc.concat(val), []);
}

console.log('payloadCache', payloadCache);
return payloadCache;
}

Expand Down
42 changes: 24 additions & 18 deletions ecc/blocks/form-handler/form-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import ProductSelector from '../../components/product-selector/product-selector.
import ProductSelectorGroup from '../../components/product-selector-group/product-selector-group.js';
import PartnerSelector from '../../components/partner-selector/partner-selector.js';
import PartnerSelectorGroup from '../../components/partner-selector-group/partner-selector-group.js';
import getJoinedData, { getFilteredCachedResponse, hasContentChanged, quickFilter, setPayloadCache, setResponseCache } from '../../scripts/event-data-handler.js';
import getJoinedData, { getFilteredCachedResponse, hasContentChanged, quickFilter, setPayloadCache, setResponseCache } from './data-handler.js';
import { getUser, initProfileLogicTree, userHasAccessToEvent } from '../../scripts/profile.js';
import CustomSearch from '../../components/custom-search/custom-search.js';
import { initProfileLogicTree } from '../../scripts/event-apis.js';

const { createTag } = await import(`${LIBS}/utils/utils.js`);
const { decorateButtons } = await import(`${LIBS}/utils/decorate.js`);
Expand Down Expand Up @@ -233,22 +233,28 @@ async function loadEventData(props) {
const eventId = urlParams.get('eventId');

if (eventId) {
setTimeout(() => {
if (!props.eventDataResp.eventId) {
const toastArea = props.el.querySelector('.toast-area');
if (!toastArea) return;

const toast = createTag('sp-toast', { open: true, timeout: 10000 }, 'Event data is taking longer than usual to load. Please check if the Adobe corp. VPN is connected or if the eventId URL Param is valid.', { parent: toastArea });
toast.addEventListener('close', () => {
toast.remove();
});
}
}, 5000);
const user = await getUser();
if (userHasAccessToEvent(user, eventId)) {
setTimeout(() => {
if (!props.eventDataResp.eventId) {
const toastArea = props.el.querySelector('.toast-area');
if (!toastArea) return;

const toast = createTag('sp-toast', { open: true, timeout: 10000 }, 'Event data is taking longer than usual to load. Please check if the Adobe corp. VPN is connected or if the eventId URL Param is valid.', { parent: toastArea });
toast.addEventListener('close', () => {
toast.remove();
});
}
}, 5000);

props.el.classList.add('disabled');
const eventData = await getEvent(eventId);
props.eventDataResp = { ...props.eventDataResp, ...eventData };
props.el.classList.remove('disabled');
props.el.classList.add('disabled');
const eventData = await getEvent(eventId);
props.eventDataResp = { ...props.eventDataResp, ...eventData };
props.el.classList.remove('disabled');
} else {
buildNoAccessScreen(props.el);
props.el.classList.remove('loading');
}
}
}

Expand Down Expand Up @@ -1056,7 +1062,7 @@ export default async function init(el) {
return;
}

initProfileLogicTree({
await initProfileLogicTree('event-creation-form', {
noProfile: () => {
signIn();
},
Expand Down
2 changes: 1 addition & 1 deletion ecc/blocks/img-upload-component/controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
import { deleteImage, getEventImages, uploadImage } from '../../scripts/esp-controller.js';
import { LIBS } from '../../scripts/scripts.js';
import { getFilteredCachedResponse } from '../../scripts/event-data-handler.js';
import { getFilteredCachedResponse } from '../event-creation-form/data-handler.js';

const { createTag } = await import(`${LIBS}/utils/utils.js`);

Expand Down
2 changes: 1 addition & 1 deletion ecc/blocks/profile-component/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
removeSpeakerFromEvent,
getEventSpeaker,
} from '../../scripts/esp-controller.js';
import { getFilteredCachedResponse } from '../../scripts/event-data-handler.js';
import { getFilteredCachedResponse } from '../event-creation-form/data-handler.js';

export async function onSubmit(component, props) {
if (component.closest('.fragment')?.classList.contains('hidden')) return;
Expand Down
4 changes: 2 additions & 2 deletions ecc/blocks/series-creation-form/series-creation-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getSeriesById,
} from '../../scripts/esp-controller.js';
import getJoinedData, { getFilteredCachedResponse, quickFilter, setPayloadCache, setResponseCache } from './data-handler.js';
import { initProfileLogicTree } from '../../scripts/event-apis.js';
import { initProfileLogicTree } from '../../scripts/profile.js';

const { createTag } = await import(`${LIBS}/utils/utils.js`);
const { decorateButtons } = await import(`${LIBS}/utils/decorate.js`);
Expand Down Expand Up @@ -815,7 +815,7 @@ export default async function init(el) {
return;
}

initProfileLogicTree({
initProfileLogicTree('series-creation-form', {
noProfile: () => {
signIn();
},
Expand Down
6 changes: 3 additions & 3 deletions ecc/blocks/series-dashboard/series-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getEventServiceEnv,
getDevToken,
} from '../../scripts/utils.js';
import { initProfileLogicTree } from '../../scripts/event-apis.js';
import { initProfileLogicTree } from '../../scripts/profile.js';
import { quickFilter } from '../series-creation-form/data-handler.js';

const { createTag } = await import(`${LIBS}/utils/utils.js`);
Expand Down Expand Up @@ -606,7 +606,7 @@ function buildLoadingScreen(el) {
el.classList.add('loading');
const loadingScreen = createTag('sp-theme', { color: 'light', scale: 'medium', class: 'loading-screen' });
createTag('sp-progress-circle', { size: 'l', indeterminate: true }, '', { parent: loadingScreen });
createTag('sp-field-label', {}, 'Loading Series dashboard...', { parent: loadingScreen });
createTag('sp-field-label', {}, 'Loading event series dashboard...', { parent: loadingScreen });

el.prepend(loadingScreen);
}
Expand All @@ -633,7 +633,7 @@ export default async function init(el) {
return;
}

initProfileLogicTree({
initProfileLogicTree('series-dashboard', {
noProfile: () => {
signIn();
},
Expand Down
Loading

0 comments on commit 5187579

Please sign in to comment.