feat: settings page update

This commit is contained in:
ivannoskov
2026-02-02 21:29:06 +03:00
parent 735077e707
commit 233bdf7907
6 changed files with 140 additions and 112 deletions

View File

@@ -53,7 +53,7 @@ interface WorkspaceContextType {
// Permissions
permissions: Permission[];
hasPermission: (key: PermissionKey, projectId?: string) => boolean;
hasPermission: (key: PermissionKey, projectId?: string, creativeId?: string, placementId?: string) => boolean;
isAdmin: boolean;
// Check if user is admin in a specific workspace
isWorkspaceAdmin: (workspaceId: string) => Promise<boolean>;
@@ -141,7 +141,7 @@ export const WorkspaceProvider: React.FC<WorkspaceProviderProps> = ({
const isAdmin = permissions.some((p) => p.key === "admin_full");
const hasPermission = useCallback(
(key: PermissionKey, projectId?: string): boolean => {
(key: PermissionKey, projectId?: string, creativeId?: string, placementId?: string): boolean => {
// Admin has all permissions
if (isAdmin) return true;
@@ -154,13 +154,30 @@ export const WorkspaceProvider: React.FC<WorkspaceProviderProps> = ({
// If projectId provided, check if it's in scopes
if (projectId) {
return permission.scopes.some(
const hasProjectScope = permission.scopes.some(
(s) => s.type === "project" && s.id === projectId
);
if (hasProjectScope) return true;
}
// Permission exists but is scoped - need projectId to verify
return true;
// If creativeId provided, check if it's in scopes
if (creativeId) {
const hasCreativeScope = permission.scopes.some(
(s) => s.type === "creative" && s.id === creativeId
);
if (hasCreativeScope) return true;
}
// If placementId provided, check if it's in scopes
if (placementId) {
const hasPlacementScope = permission.scopes.some(
(s) => s.type === "placement" && s.id === placementId
);
if (hasPlacementScope) return true;
}
// Permission exists but is scoped and no matching scope found
return false;
},
[permissions, isAdmin]
);