access control by role plus by person in orgsettings
This commit is contained in:
@@ -13,7 +13,7 @@ import { resolveOrgRoleKey } from '../utils/permissions';
|
||||
*/
|
||||
export const usePermissions = () => {
|
||||
const { user } = useAuth();
|
||||
const { orgPermissions, orgMembers } = useMockStore();
|
||||
const { orgPermissions, orgMembers, userPermissionOverrides } = useMockStore();
|
||||
|
||||
const orgRoleKey = useMemo(
|
||||
() => resolveOrgRoleKey(user, orgMembers),
|
||||
@@ -24,10 +24,19 @@ export const usePermissions = () => {
|
||||
(moduleKey, action) => {
|
||||
if (!orgRoleKey) return false;
|
||||
if (orgRoleKey === 'OWNER') return true;
|
||||
|
||||
// Person-level override takes priority
|
||||
if (user?.id && userPermissionOverrides) {
|
||||
const override = userPermissionOverrides.find(
|
||||
o => o.userId === user.id && o.moduleKey === moduleKey && o.action === action
|
||||
);
|
||||
if (override) return override.effect === 'grant';
|
||||
}
|
||||
|
||||
const actions = orgPermissions[moduleKey]?.[orgRoleKey] || [];
|
||||
return actions.includes(action);
|
||||
},
|
||||
[orgRoleKey, orgPermissions],
|
||||
[orgRoleKey, orgPermissions, user, userPermissionOverrides],
|
||||
);
|
||||
|
||||
const canAny = useCallback(
|
||||
|
||||
Reference in New Issue
Block a user