User profile controls that hide non-sales features from users outside sales

This commit is contained in:
2026-09-24 17:23:50 -03:00
parent f74071e39e
commit 451c27e9d7
22 changed files with 391 additions and 36 deletions

17
src/auth/current-user.js Normal file
View File

@@ -0,0 +1,17 @@
function createCurrentUser({ sendRuntimeMessage, appendBackgroundRequestLog, messageTypes }) {
let pending = null;
let allowed = false;
function ensure() {
if (!pending) {
pending = sendRuntimeMessage({ type: messageTypes.requestCurrentUser }).then(response => {
appendBackgroundRequestLog(response?.debugRequests);
const roles = response?.user?.roles;
allowed = response?.ok === true && Array.isArray(roles)
&& roles.every(role => typeof role === "string") && !roles.includes("SALES_REP");
return allowed;
}).catch(() => { allowed = false; return false; });
}
return pending;
}
return { ensure, allowsCrmActivities: () => allowed };
}