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

Prompt SUSI for logged out users before showing them the no-access screen #232

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
34 changes: 11 additions & 23 deletions ecc/blocks/attendee-management-table/attendee-management-table.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable max-len */
import { getAllEventAttendees, getEvents } from '../../scripts/esp-controller.js';
import { ALLOWED_ACCOUNT_TYPES } from '../../constants/constants.js';
import { LIBS } from '../../scripts/scripts.js';
import {
getIcon,
buildNoAccessScreen,
camelToSentenceCase,
readBlockConfig,
signIn,
} from '../../scripts/utils.js';
import BlockMediator from '../../scripts/deps/block-mediator.min.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';

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

Expand Down Expand Up @@ -556,27 +556,15 @@ export default async function init(el) {
const config = readBlockConfig(el);
el.innerHTML = '';
buildLoadingScreen(el);
const profile = BlockMediator.get('imsProfile');

if (profile) {
if (profile.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(profile.account_type)) {
initProfileLogicTree({
noProfile: () => {
signIn();
},
noAccessProfile: () => {
buildNoAccessScreen(el);
} else {
},
validProfile: () => {
buildDashboard(el, config);
}

return;
}

if (!profile) {
const unsubscribe = BlockMediator.subscribe('imsProfile', ({ newValue }) => {
if (newValue?.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(newValue.account_type)) {
buildNoAccessScreen(el);
} else {
buildDashboard(el, config);
}

unsubscribe();
});
}
},
});
}
35 changes: 11 additions & 24 deletions ecc/blocks/ecc-dashboard/ecc-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import {
publishEvent,
unpublishEvent,
} from '../../scripts/esp-controller.js';
import { ALLOWED_ACCOUNT_TYPES } from '../../constants/constants.js';
import { LIBS } from '../../scripts/scripts.js';
import { getIcon, buildNoAccessScreen, getEventPageHost, readBlockConfig } from '../../scripts/utils.js';
import { getIcon, buildNoAccessScreen, getEventPageHost, readBlockConfig, signIn } from '../../scripts/utils.js';
import { quickFilter } from '../form-handler/data-handler.js';
import BlockMediator from '../../scripts/deps/block-mediator.min.js';
import { initProfileLogicTree } from '../../scripts/event-apis.js';

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

Expand Down Expand Up @@ -705,27 +704,15 @@ export default async function init(el) {
const config = readBlockConfig(el);
el.innerHTML = '';
buildLoadingScreen(el);
const profile = BlockMediator.get('imsProfile');

if (profile) {
if (profile.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(profile.account_type)) {
initProfileLogicTree({
noProfile: () => {
signIn();
},
noAccessProfile: () => {
buildNoAccessScreen(el);
} else {
},
validProfile: () => {
buildDashboard(el, config);
}

return;
}

if (!profile) {
const unsubscribe = BlockMediator.subscribe('imsProfile', ({ newValue }) => {
if (newValue?.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(newValue.account_type)) {
buildNoAccessScreen(el);
} else {
buildDashboard(el, config);
}

unsubscribe();
});
}
},
});
}
37 changes: 11 additions & 26 deletions ecc/blocks/form-handler/form-handler.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ALLOWED_ACCOUNT_TYPES } from '../../constants/constants.js';
import { LIBS } from '../../scripts/scripts.js';
import {
getIcon,
buildNoAccessScreen,
generateToolTip,
camelToSentenceCase,
getEventPageHost,
signIn,
} from '../../scripts/utils.js';
import {
createEvent,
Expand All @@ -25,8 +25,8 @@ import ProductSelectorGroup from '../../components/product-selector-group/produc
import PartnerSelector from '../../components/partner-selector/partner-selector.js';
import PartnerSelectorGroup from '../../components/partner-selector-group/partner-selector-group.js';
import getJoinedData, { getFilteredCachedResponse, quickFilter, setPayloadCache, setResponseCache } from './data-handler.js';
import BlockMediator from '../../scripts/deps/block-mediator.min.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 @@ -857,33 +857,18 @@ export default async function init(el) {
...promises,
]);

const profile = BlockMediator.get('imsProfile');

if (profile) {
if (profile.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(profile.account_type)) {
initProfileLogicTree({
noProfile: () => {
signIn();
},
noAccessProfile: () => {
buildNoAccessScreen(el);
el.classList.remove('loading');
} else {
},
validProfile: () => {
buildECCForm(el).then(() => {
el.classList.remove('loading');
});
}

return;
}

if (!profile) {
const unsubscribe = BlockMediator.subscribe('imsProfile', ({ newValue }) => {
if (newValue?.noProfile || !ALLOWED_ACCOUNT_TYPES.includes(newValue.account_type)) {
buildNoAccessScreen(el);
el.classList.remove('loading');
unsubscribe();
} else {
buildECCForm(el).then(() => {
el.classList.remove('loading');
unsubscribe();
});
}
});
}
},
});
}
35 changes: 35 additions & 0 deletions ecc/scripts/event-apis.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BlockMediator from './deps/block-mediator.min.js';
import { ALLOWED_ACCOUNT_TYPES } from '../constants/constants.js';

export async function getProfile() {
const { feds, adobeProfile, fedsConfig, adobeIMS } = window;
Expand Down Expand Up @@ -61,3 +62,37 @@ export function lazyCaptureProfile() {
}
}, 1000);
}

export function initProfileLogicTree(callbacks) {
const { noProfile, noAccessProfile, validProfile } = callbacks;

const profile = BlockMediator.get('imsProfile');

if (profile) {
if (profile.noProfile) {
noProfile();
} else if (!ALLOWED_ACCOUNT_TYPES.includes(profile.account_type)) {
noAccessProfile();
} else {
validProfile(profile);
}

return;
}

if (!profile) {
const unsubscribe = BlockMediator.subscribe('imsProfile', ({ newValue }) => {
if (newValue) {
if (newValue.noProfile) {
noProfile();
} else if (!ALLOWED_ACCOUNT_TYPES.includes(newValue.account_type)) {
noAccessProfile();
} else {
validProfile(newValue);
}
}

unsubscribe();
});
}
}
9 changes: 9 additions & 0 deletions ecc/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ export async function decorateTextarea(cell, extraOptions) {
cell.append(wrapper);
}

export function signIn() {
if (typeof window.adobeIMS?.signIn !== 'function') {
window?.lana.log({ message: 'IMS signIn method not available', tags: 'errorType=warn,module=gnav' });
return;
}

window.adobeIMS?.signIn();
}

export async function getSecret(key) {
if (secretCache.length === 0) {
const resp = await fetch('/ecc/system/secrets.json')
Expand Down
Loading