Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.8 KB
Raw Blame
import { useMemo } from 'react';
import { PermissionTypes, PrincipalType, Permissions } from 'librechat-data-provider';
import { useHasAccess } from '~/hooks';

/**
 * Hook to check people picker permissions and return the appropriate type filter
 * Note: SHARE_PUBLIC is now per-resource type (AGENTS, PROMPTS, MCP_SERVERS), not on PEOPLE_PICKER
 * @returns Object with permission states and type filter
 */
export const usePeoplePickerPermissions = () => {
  const canViewUsers = useHasAccess({
    permissionType: PermissionTypes.PEOPLE_PICKER,
    permission: Permissions.VIEW_USERS,
  });

  const canViewGroups = useHasAccess({
    permissionType: PermissionTypes.PEOPLE_PICKER,
    permission: Permissions.VIEW_GROUPS,
  });

  const canViewRoles = useHasAccess({
    permissionType: PermissionTypes.PEOPLE_PICKER,
    permission: Permissions.VIEW_ROLES,
  });

  const hasPeoplePickerAccess = canViewUsers || canViewGroups || canViewRoles;

  const peoplePickerTypeFilter: Array<
    PrincipalType.USER | PrincipalType.GROUP | PrincipalType.ROLE
  > | null = useMemo(() => {
    const allowedTypes: Array<PrincipalType.USER | PrincipalType.GROUP | PrincipalType.ROLE> = [];

    if (canViewUsers) {
      allowedTypes.push(PrincipalType.USER);
    }
    if (canViewGroups) {
      allowedTypes.push(PrincipalType.GROUP);
    }
    if (canViewRoles) {
      allowedTypes.push(PrincipalType.ROLE);
    }

    // Return null if no types are allowed (will show no results)
    // or if all types are allowed (no filtering needed)
    if (allowedTypes.length === 0 || allowedTypes.length === 3) {
      return null;
    }

    return allowedTypes;
  }, [canViewUsers, canViewGroups, canViewRoles]);

  return {
    canViewUsers,
    canViewRoles,
    canViewGroups,
    hasPeoplePickerAccess,
    peoplePickerTypeFilter,
  };
};