User profile controls that hide non-sales features from users outside sales
This commit is contained in:
@@ -18,11 +18,14 @@ function createOpportunitiesController({
|
||||
resetWorkloadActions,
|
||||
requestOpptyProductsInBackground,
|
||||
requestTokenRelayOnce,
|
||||
ensureCurrentUser,
|
||||
setOpportunitiesTableState
|
||||
}) {
|
||||
async function requestOpportunitiesForPeriod(period) {
|
||||
const dateRange = getFiscalPeriodRange(period, new Date());
|
||||
const requestVersion = ++opportunitiesQueryState.periodRequestVersion;
|
||||
await ensureCurrentUser();
|
||||
if (!isCurrentPeriodRequest(requestVersion)) return;
|
||||
|
||||
if (preferencesState.selectedOpportunityTypeValues.size === 0) {
|
||||
setOpportunitiesTableState({
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
function createOpportunityCrmServiceRequests({ requestCrmServiceRequest, isCurrentPeriodRequest, bindPopover, closePopover, environment }) {
|
||||
function createOpportunityCrmServiceRequests({ requestCrmServiceRequest, isCurrentPeriodRequest, bindPopover, closePopover, allowsCrmActivities, environment }) {
|
||||
let status = "idle";
|
||||
let byOpportunity = new Map();
|
||||
let pending = null;
|
||||
let generation = 0;
|
||||
function reset() { closePopover(); generation += 1; pending = null; status = "idle"; byOpportunity = new Map(); }
|
||||
function load(token, version) {
|
||||
if (!isCurrentPeriodRequest(version)) return;
|
||||
if (!allowsCrmActivities() || !isCurrentPeriodRequest(version)) return;
|
||||
if (!pending) pending = run(token, version, generation);
|
||||
return pending;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ function createOpportunityCrmServiceRequests({ requestCrmServiceRequest, isCurre
|
||||
}
|
||||
}
|
||||
function createBadge(optyNumber) {
|
||||
if (!optyNumber || status === "idle" || status === "loading") return null;
|
||||
if (!allowsCrmActivities() || !optyNumber || status === "idle" || status === "loading") return null;
|
||||
const items = byOpportunity.get(String(optyNumber)) || [];
|
||||
const badge = environment.document.createElement(items.length && status === "ready" ? "button" : "span");
|
||||
badge.className = "opportunities-extension-crm-sr-badge";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
function createOpportunityWorkloadActions({ authSessionState, requestConsumerTokenServiceOnce, sendRuntimeMessage,
|
||||
function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivities, requestConsumerTokenServiceOnce, sendRuntimeMessage,
|
||||
appendBackgroundRequestLog, queueProductsTableRender, productsContentState, messageTypes, environment }) {
|
||||
let session = newSession();
|
||||
function newSession() { return { enabled: true, records: new Map(), queue: [], running: 0 }; }
|
||||
@@ -12,7 +12,7 @@ function createOpportunityWorkloadActions({ authSessionState, requestConsumerTok
|
||||
return [...new Set((products?.items || []).map(item => String(item?.RevnId ?? "").trim()).filter(Boolean))];
|
||||
}
|
||||
function loadProducts(products) {
|
||||
if (!session.enabled) return;
|
||||
if (!session.enabled || !allowsCrmActivities()) return;
|
||||
for (const revnId of idsFor(products)) {
|
||||
if (session.records.has(revnId)) continue;
|
||||
const record = { status: "loading", actions: [], hasNext: false };
|
||||
@@ -36,9 +36,9 @@ function createOpportunityWorkloadActions({ authSessionState, requestConsumerTok
|
||||
async function run(current, { revnId, record }) {
|
||||
try {
|
||||
const authorizations = await requestConsumerTokenServiceOnce();
|
||||
if (!current.enabled || current !== session) return;
|
||||
if (!current.enabled || current !== session || !allowsCrmActivities()) return;
|
||||
const result = await sendRuntimeMessage({ type: messageTypes.requestWlActions, revnId, authorization: authorizations?.workloadActions });
|
||||
if (!current.enabled || current !== session) return;
|
||||
if (!current.enabled || current !== session || !allowsCrmActivities()) return;
|
||||
appendBackgroundRequestLog(result?.debugRequests);
|
||||
if (!result?.ok) throw new Error(result?.error || "Unable to load workload actions.");
|
||||
record.actions = result.actions;
|
||||
@@ -53,7 +53,7 @@ function createOpportunityWorkloadActions({ authSessionState, requestConsumerTok
|
||||
}
|
||||
}
|
||||
function createBadge(optyNumber) {
|
||||
if (!session.enabled || !optyNumber) return null;
|
||||
if (!session.enabled || !allowsCrmActivities() || !optyNumber) return null;
|
||||
const products = productsContentState.opptyProductsByNumber.get(String(optyNumber));
|
||||
if (!products) return null;
|
||||
const ids = idsFor(products);
|
||||
|
||||
Reference in New Issue
Block a user