Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

3.8 KB
Raw Blame
import type { AccessControlTemplateLanguage } from '@/i18n/language'

export const SubjectType = {
  GROUP: 'group',
  ACCOUNT: 'account',
} as const

export type SubjectType = (typeof SubjectType)[keyof typeof SubjectType]

export const AccessMode = {
  PUBLIC: 'public',
  SPECIFIC_GROUPS_MEMBERS: 'private',
  ORGANIZATION: 'private_all',
  EXTERNAL_MEMBERS: 'sso_verified',
} as const

export type AccessMode = (typeof AccessMode)[keyof typeof AccessMode]

const accessModes = new Set<string>(Object.values(AccessMode))

export function isAccessMode(accessMode: string | null | undefined): accessMode is AccessMode {
  return !!accessMode && accessModes.has(accessMode)
}

export type AccessControlGroup = {
  id: string
  name: string
  groupSize: number
}

export type AccessControlAccount = {
  id: string
  name: string
  email: string
  avatar: string
  avatarUrl: string
}

export type SubjectGroup = {
  subjectId: string
  subjectType: SubjectType
  groupData: AccessControlGroup
}
export type SubjectAccount = {
  subjectId: string
  subjectType: SubjectType
  accountData: AccessControlAccount
}

export type Subject = SubjectGroup | SubjectAccount

type Permission = {
  key: string
  name: string
  description: string
}
export type PermissionGroup = {
  group_key: string
  group_name: string
  description: string
  permissions: Permission[]
}

export type PermissionKey = string

type RoleType = 'workspace' | 'app' | 'dataset'

export type RoleCategory = 'global_system_default' | 'global_custom'

export type Role = {
  id: string
  tenant_id: string
  type: RoleType
  category: RoleCategory
  name: string
  description: string
  is_builtin: boolean
  permission_keys: PermissionKey[]
  role_tag: 'owner' | 'admin' | '' // Identifies built-in workspace roles with special handling
}

type Pagination = {
  total_count: number
  per_page: number
  current_page: number
  total_pages: number
}

type PaginationParameters = {
  page?: number
  limit?: number
  reverse?: boolean
}

export type RoleListRequest = PaginationParameters & {
  include_owner?: 1 | 0
  language?: AccessControlTemplateLanguage
}

export type RoleListResponse = {
  data: Role[]
  pagination: Pagination
}

export type AccessPolicyResourceType = 'app' | 'dataset' | 'agent'

type AccessPolicyCategory = 'global_system_default' | 'global_custom'

export type AccessPolicy = {
  id: string
  tenant_id: string
  resource_type: AccessPolicyResourceType
  policy_key: string
  name: string
  description: string
  permission_keys: PermissionKey[]
  is_builtin: boolean
  category: AccessPolicyCategory
  created_at: string
  updated_at: string
}

type Bindings = {
  roles: Array<{
    role_id: string
    role_name: string
    binding_id: string
    is_locked: boolean
    role_tag: 'owner' | 'admin' | '' // Identifies built-in workspace roles with special handling
  }>
  accounts: Array<{
    account_id: string
    account_name: string
    binding_id: string
    is_locked: boolean
    avatar?: string
  }>
}

export type AccessPolicyWithBindings = {
  policy: AccessPolicy
} & Bindings

export type GetAppAccessPolicyByAppIdResponse = {
  app_id: string
  items: AccessPolicyWithBindings[]
}

export type GetDatasetAccessPolicyByDatasetIdResponse = {
  dataset_id: string
  items: AccessPolicyWithBindings[]
}

type Account = {
  account_id: string
  account_name: string
  email?: string
  avatar?: string
}

export type ResourceUserAccessSetting = {
  account: Account
  roles: Omit<Role, 'tenant_id' | 'description'>[]
  access_policies: Omit<AccessPolicy, 'created_at' | 'updated_at'>[]
}

export type ResourceUserAccessSettingsResponse = {
  data: ResourceUserAccessSetting[]
  pagination: Pagination
}

export type UpdateResourceUserAccessSettingsRequest = {
  accountId: string
  accessPolicyIds: string[]
}

export type RemoveResourceAccessPolicyMemberBindingsRequest = {
  accessPolicyId: string
  accountIds: string[]
}