2025-06-23 10:22:27 -04:00
|
|
|
import { z } from 'zod';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Granular Permission System Types for Agent Sharing
|
|
|
|
|
*
|
|
|
|
|
* This file contains TypeScript interfaces and Zod schemas for the enhanced
|
|
|
|
|
* agent permission system that supports sharing with specific users/groups
|
|
|
|
|
* and Entra ID integration.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// ===== ENUMS & CONSTANTS =====
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Principal types for permission system
|
|
|
|
|
*/
|
2025-08-02 16:02:56 -04:00
|
|
|
export enum PrincipalType {
|
|
|
|
|
USER = 'user',
|
|
|
|
|
GROUP = 'group',
|
|
|
|
|
PUBLIC = 'public',
|
2025-08-03 19:24:40 -04:00
|
|
|
ROLE = 'role',
|
2025-08-02 16:02:56 -04:00
|
|
|
}
|
2025-06-23 10:22:27 -04:00
|
|
|
|
2025-08-02 16:14:11 -04:00
|
|
|
/**
|
|
|
|
|
* Principal model types for MongoDB references
|
|
|
|
|
*/
|
|
|
|
|
export enum PrincipalModel {
|
|
|
|
|
USER = 'User',
|
|
|
|
|
GROUP = 'Group',
|
2025-08-03 19:24:40 -04:00
|
|
|
ROLE = 'Role',
|
2025-08-02 16:14:11 -04:00
|
|
|
}
|
|
|
|
|
|
2025-06-23 10:22:27 -04:00
|
|
|
/**
|
|
|
|
|
* Source of the principal (local LibreChat or external Entra ID)
|
|
|
|
|
*/
|
|
|
|
|
export type TPrincipalSource = 'local' | 'entra';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Access levels for agents
|
|
|
|
|
*/
|
|
|
|
|
export type TAccessLevel = 'none' | 'viewer' | 'editor' | 'owner';
|
|
|
|
|
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
/**
|
|
|
|
|
* Resource types for permission system
|
|
|
|
|
*/
|
|
|
|
|
export enum ResourceType {
|
|
|
|
|
AGENT = 'agent',
|
|
|
|
|
PROMPTGROUP = 'promptGroup',
|
2025-12-04 21:37:23 +01:00
|
|
|
MCPSERVER = 'mcpServer',
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
}
|
|
|
|
|
|
2025-06-23 10:22:27 -04:00
|
|
|
/**
|
|
|
|
|
* Permission bit constants for bitwise operations
|
|
|
|
|
*/
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
export enum PermissionBits {
|
|
|
|
|
/** 001 - Can view and use agent */
|
|
|
|
|
VIEW = 1,
|
|
|
|
|
/** 010 - Can modify agent settings */
|
|
|
|
|
EDIT = 2,
|
|
|
|
|
/** 100 - Can delete agent */
|
|
|
|
|
DELETE = 4,
|
|
|
|
|
/** 1000 - Can share agent with others (future) */
|
|
|
|
|
SHARE = 8,
|
|
|
|
|
}
|
2025-06-23 10:22:27 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Standard access role IDs
|
|
|
|
|
*/
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
export enum AccessRoleIds {
|
2025-07-26 12:28:31 -04:00
|
|
|
AGENT_VIEWER = 'agent_viewer',
|
|
|
|
|
AGENT_EDITOR = 'agent_editor',
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
AGENT_OWNER = 'agent_owner',
|
2025-07-26 12:28:31 -04:00
|
|
|
PROMPTGROUP_VIEWER = 'promptGroup_viewer',
|
|
|
|
|
PROMPTGROUP_EDITOR = 'promptGroup_editor',
|
|
|
|
|
PROMPTGROUP_OWNER = 'promptGroup_owner',
|
2025-12-04 21:37:23 +01:00
|
|
|
MCPSERVER_VIEWER = 'mcpServer_viewer',
|
|
|
|
|
MCPSERVER_EDITOR = 'mcpServer_editor',
|
|
|
|
|
MCPSERVER_OWNER = 'mcpServer_owner',
|
2025-07-26 12:28:31 -04:00
|
|
|
}
|
2025-06-23 10:22:27 -04:00
|
|
|
|
|
|
|
|
// ===== ZOD SCHEMAS =====
|
|
|
|
|
|
|
|
|
|
/**
|
2025-08-03 19:24:40 -04:00
|
|
|
* Principal schema - represents a user, group, role, or public access
|
2025-06-23 10:22:27 -04:00
|
|
|
*/
|
|
|
|
|
export const principalSchema = z.object({
|
2025-08-02 16:02:56 -04:00
|
|
|
type: z.nativeEnum(PrincipalType),
|
2025-08-03 19:24:40 -04:00
|
|
|
id: z.string().optional(), // undefined for 'public' type, role name for 'role' type
|
2025-06-23 10:22:27 -04:00
|
|
|
name: z.string().optional(),
|
|
|
|
|
email: z.string().optional(), // for user and group types
|
|
|
|
|
source: z.enum(['local', 'entra']).optional(),
|
|
|
|
|
avatar: z.string().optional(), // for user and group types
|
2025-08-03 19:24:40 -04:00
|
|
|
description: z.string().optional(), // for group and role types
|
2025-06-23 10:22:27 -04:00
|
|
|
idOnTheSource: z.string().optional(), // Entra ID for users/groups
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
accessRoleId: z.nativeEnum(AccessRoleIds).optional(), // Access role ID for permissions
|
2025-06-23 10:22:27 -04:00
|
|
|
memberCount: z.number().optional(), // for group type
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Access role schema - defines named permission sets
|
|
|
|
|
*/
|
|
|
|
|
export const accessRoleSchema = z.object({
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
accessRoleId: z.nativeEnum(AccessRoleIds),
|
2025-06-23 10:22:27 -04:00
|
|
|
name: z.string(),
|
|
|
|
|
description: z.string().optional(),
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
resourceType: z.nativeEnum(ResourceType).default(ResourceType.AGENT),
|
2025-06-23 10:22:27 -04:00
|
|
|
permBits: z.number(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Permission entry schema - represents a single ACL entry
|
|
|
|
|
*/
|
|
|
|
|
export const permissionEntrySchema = z.object({
|
|
|
|
|
id: z.string(),
|
2025-08-02 16:02:56 -04:00
|
|
|
principalType: z.nativeEnum(PrincipalType),
|
2025-06-23 10:22:27 -04:00
|
|
|
principalId: z.string().optional(), // undefined for 'public'
|
|
|
|
|
principalName: z.string().optional(),
|
|
|
|
|
role: accessRoleSchema,
|
|
|
|
|
grantedBy: z.string(),
|
|
|
|
|
grantedAt: z.string(), // ISO date string
|
|
|
|
|
inheritedFrom: z.string().optional(), // for project-level inheritance
|
|
|
|
|
source: z.enum(['local', 'entra']).optional(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resource permissions response schema
|
|
|
|
|
*/
|
|
|
|
|
export const resourcePermissionsResponseSchema = z.object({
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
resourceType: z.nativeEnum(ResourceType),
|
2025-06-23 10:22:27 -04:00
|
|
|
resourceId: z.string(),
|
|
|
|
|
permissions: z.array(permissionEntrySchema),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update resource permissions request schema
|
|
|
|
|
* This matches the user's requirement for the frontend DTO structure
|
|
|
|
|
*/
|
|
|
|
|
export const updateResourcePermissionsRequestSchema = z.object({
|
|
|
|
|
updated: principalSchema.array(),
|
|
|
|
|
removed: principalSchema.array(),
|
|
|
|
|
public: z.boolean(),
|
|
|
|
|
publicAccessRoleId: z.string().optional(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update resource permissions response schema
|
|
|
|
|
* Returns the updated permissions with accessRoleId included
|
|
|
|
|
*/
|
|
|
|
|
export const updateResourcePermissionsResponseSchema = z.object({
|
|
|
|
|
message: z.string(),
|
|
|
|
|
results: z.object({
|
|
|
|
|
principals: principalSchema.array(),
|
|
|
|
|
public: z.boolean(),
|
|
|
|
|
publicAccessRoleId: z.string().optional(),
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// ===== TYPESCRIPT TYPES =====
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Principal - represents a user, group, or public access
|
|
|
|
|
*/
|
|
|
|
|
export type TPrincipal = z.infer<typeof principalSchema>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Access role - defines named permission sets
|
|
|
|
|
*/
|
|
|
|
|
export type TAccessRole = z.infer<typeof accessRoleSchema>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Permission entry - represents a single ACL entry
|
|
|
|
|
*/
|
|
|
|
|
export type TPermissionEntry = z.infer<typeof permissionEntrySchema>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resource permissions response
|
|
|
|
|
*/
|
|
|
|
|
export type TResourcePermissionsResponse = z.infer<typeof resourcePermissionsResponseSchema>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update resource permissions request
|
|
|
|
|
* This matches the user's requirement for the frontend DTO structure
|
|
|
|
|
*/
|
|
|
|
|
export type TUpdateResourcePermissionsRequest = z.infer<
|
|
|
|
|
typeof updateResourcePermissionsRequestSchema
|
|
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update resource permissions response
|
|
|
|
|
* Returns the updated permissions with accessRoleId included
|
|
|
|
|
*/
|
|
|
|
|
export type TUpdateResourcePermissionsResponse = z.infer<
|
|
|
|
|
typeof updateResourcePermissionsResponseSchema
|
|
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Principal search request parameters
|
|
|
|
|
*/
|
|
|
|
|
export type TPrincipalSearchParams = {
|
|
|
|
|
q: string; // search query (required)
|
|
|
|
|
limit?: number; // max results (1-50, default 10)
|
2025-08-03 19:24:40 -04:00
|
|
|
type?: PrincipalType.USER | PrincipalType.GROUP | PrincipalType.ROLE; // filter by type (optional)
|
2025-06-23 10:22:27 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Principal search result item
|
|
|
|
|
*/
|
|
|
|
|
export type TPrincipalSearchResult = {
|
|
|
|
|
id?: string | null; // null for Entra ID principals that don't exist locally yet
|
2025-08-03 19:24:40 -04:00
|
|
|
type: PrincipalType.USER | PrincipalType.GROUP | PrincipalType.ROLE;
|
2025-06-23 10:22:27 -04:00
|
|
|
name: string;
|
|
|
|
|
email?: string; // for users and groups
|
|
|
|
|
username?: string; // for users
|
|
|
|
|
avatar?: string; // for users and groups
|
|
|
|
|
provider?: string; // for users
|
|
|
|
|
source: 'local' | 'entra';
|
|
|
|
|
memberCount?: number; // for groups
|
|
|
|
|
description?: string; // for groups
|
|
|
|
|
idOnTheSource?: string; // Entra ID for users (maps to openidId) and groups (maps to idOnTheSource)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Principal search response
|
|
|
|
|
*/
|
|
|
|
|
export type TPrincipalSearchResponse = {
|
|
|
|
|
query: string;
|
|
|
|
|
limit: number;
|
2025-08-03 19:24:40 -04:00
|
|
|
type?: PrincipalType.USER | PrincipalType.GROUP | PrincipalType.ROLE;
|
2025-06-23 10:22:27 -04:00
|
|
|
results: TPrincipalSearchResult[];
|
|
|
|
|
count: number;
|
|
|
|
|
sources: {
|
|
|
|
|
local: number;
|
|
|
|
|
entra: number;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Available roles response
|
|
|
|
|
*/
|
|
|
|
|
export type TAvailableRolesResponse = {
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
resourceType: ResourceType;
|
2025-06-23 10:22:27 -04:00
|
|
|
roles: TAccessRole[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get resource permissions response schema
|
|
|
|
|
* This matches the enhanced aggregation-based endpoint response format
|
|
|
|
|
*/
|
|
|
|
|
export const getResourcePermissionsResponseSchema = z.object({
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
resourceType: z.nativeEnum(ResourceType),
|
|
|
|
|
resourceId: z.nativeEnum(AccessRoleIds),
|
2025-06-23 10:22:27 -04:00
|
|
|
principals: z.array(principalSchema),
|
|
|
|
|
public: z.boolean(),
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
publicAccessRoleId: z.nativeEnum(AccessRoleIds).optional(),
|
2025-06-23 10:22:27 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get resource permissions response type
|
|
|
|
|
* This matches the enhanced aggregation-based endpoint response format
|
|
|
|
|
*/
|
|
|
|
|
export type TGetResourcePermissionsResponse = z.infer<typeof getResourcePermissionsResponseSchema>;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Effective permissions response schema
|
|
|
|
|
* Returns just the permission bitmask for a user on a resource
|
|
|
|
|
*/
|
|
|
|
|
export const effectivePermissionsResponseSchema = z.object({
|
|
|
|
|
permissionBits: z.number(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Effective permissions response type
|
|
|
|
|
* Returns just the permission bitmask for a user on a resource
|
|
|
|
|
*/
|
|
|
|
|
export type TEffectivePermissionsResponse = z.infer<typeof effectivePermissionsResponseSchema>;
|
|
|
|
|
|
2025-12-04 21:37:23 +01:00
|
|
|
/**
|
|
|
|
|
* All effective permissions response type
|
|
|
|
|
* Map of resourceId to permissionBits for all accessible resources
|
|
|
|
|
*/
|
|
|
|
|
export type TAllEffectivePermissionsResponse = Record<string, number>;
|
|
|
|
|
|
2025-06-23 10:22:27 -04:00
|
|
|
// ===== UTILITY TYPES =====
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Permission check result
|
|
|
|
|
*/
|
|
|
|
|
export interface TPermissionCheck {
|
|
|
|
|
canView: boolean;
|
|
|
|
|
canEdit: boolean;
|
|
|
|
|
canDelete: boolean;
|
|
|
|
|
canShare: boolean;
|
|
|
|
|
accessLevel: TAccessLevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===== HELPER FUNCTIONS =====
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert permission bits to access level
|
|
|
|
|
*/
|
|
|
|
|
export function permBitsToAccessLevel(permBits: number): TAccessLevel {
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
if ((permBits & PermissionBits.DELETE) > 0) return 'owner';
|
|
|
|
|
if ((permBits & PermissionBits.EDIT) > 0) return 'editor';
|
|
|
|
|
if ((permBits & PermissionBits.VIEW) > 0) return 'viewer';
|
2025-06-23 10:22:27 -04:00
|
|
|
return 'none';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert access role ID to permission bits
|
|
|
|
|
*/
|
|
|
|
|
export function accessRoleToPermBits(accessRoleId: string): number {
|
|
|
|
|
switch (accessRoleId) {
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
case AccessRoleIds.AGENT_VIEWER:
|
|
|
|
|
return PermissionBits.VIEW;
|
|
|
|
|
case AccessRoleIds.AGENT_EDITOR:
|
|
|
|
|
return PermissionBits.VIEW | PermissionBits.EDIT;
|
|
|
|
|
case AccessRoleIds.AGENT_OWNER:
|
|
|
|
|
return PermissionBits.VIEW | PermissionBits.EDIT | PermissionBits.DELETE;
|
2025-06-23 10:22:27 -04:00
|
|
|
default:
|
🔧 refactor: Organize Sharing/Agent Components and Improve Type Safety
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids, rename enums to PascalCase
refactor: organize Sharing/Agent components, improve type safety for resource types and access role ids
chore: move sharing related components to dedicated "Sharing" directory
chore: remove PublicSharingToggle component and update index exports
chore: move non-sidepanel agent components to `~/components/Agents`
chore: move AgentCategoryDisplay component with tests
chore: remove commented out code
refactor: change PERMISSION_BITS from const to enum for better type safety
refactor: reorganize imports in GenericGrantAccessDialog and update index exports for hooks
refactor: update type definitions to use ACCESS_ROLE_IDS for improved type safety
refactor: remove unused canAccessPromptResource middleware and related code
refactor: remove unused prompt access roles from createAccessRoleMethods
refactor: update resourceType in AclEntry type definition to remove unused 'prompt' value
refactor: introduce ResourceType enum and update resourceType usage across data provider files for improved type safety
refactor: update resourceType usage to ResourceType enum across sharing and permissions components for improved type safety
refactor: standardize resourceType usage to ResourceType enum across agent and prompt models, permissions controller, and middleware for enhanced type safety
refactor: update resourceType references from PROMPT_GROUP to PROMPTGROUP for consistency across models, middleware, and components
refactor: standardize access role IDs and resource type usage across agent, file, and prompt models for improved type safety and consistency
chore: add typedefs for TUpdateResourcePermissionsRequest and TUpdateResourcePermissionsResponse to enhance type definitions
chore: move SearchPicker to PeoplePicker dir
refactor: implement debouncing for query changes in SearchPicker for improved performance
chore: fix typing, import order for agent admin settings
fix: agent admin settings, prevent agent form submission
refactor: rename `ACCESS_ROLE_IDS` to `AccessRoleIds`
refactor: replace PermissionBits with PERMISSION_BITS
refactor: replace PERMISSION_BITS with PermissionBits
2025-07-28 17:52:36 -04:00
|
|
|
return PermissionBits.VIEW;
|
2025-06-23 10:22:27 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if permission bitmask contains other bitmask
|
|
|
|
|
* @param permissions - The permission bitmask to check
|
|
|
|
|
* @param requiredPermission - The required permission bit(s)
|
|
|
|
|
* @returns {boolean} Whether permissions contains requiredPermission
|
|
|
|
|
*/
|
|
|
|
|
export function hasPermissions(permissions: number, requiredPermission: number): boolean {
|
|
|
|
|
return (permissions & requiredPermission) === requiredPermission;
|
|
|
|
|
}
|