Files
dify/api/services/errors/workspace.py
yyh 1ef1ad22b9 feat(api): make invitations their own record with seat reservation and revoke
- Without RBAC, inviting a new email creates only the pending account and
  token; membership and the workspace switch happen at activation
- Every live invitation is indexed; re-inviting invalidates earlier links
- New POST /workspaces/{id}/members/pending-invitations/revoke (404
  pending_invitation_not_found)
- Invite capacity counts members + live invitations; acceptance re-checks
  and fails with workspace_member_limit_reached when full

Fixes SNP-1142, SNP-1143
2026-11-19 01:59:28 +08:00

100 lines
2.7 KiB
Python

"""Framework-neutral failures owned by workspace application services."""
class WorkspaceApplicationError(Exception):
"""Base class for workspace use-case failures, mapped by transport adapters."""
class AccountAlreadyInTenantError(WorkspaceApplicationError):
pass
class InvalidActionError(WorkspaceApplicationError):
pass
class CannotOperateSelfError(WorkspaceApplicationError):
pass
class MemberNotInTenantError(WorkspaceApplicationError):
pass
class RoleAlreadyAssignedError(WorkspaceApplicationError):
pass
class WorkSpaceNotAllowedCreateError(WorkspaceApplicationError):
pass
class WorkspacesLimitExceededError(WorkspaceApplicationError):
pass
class WorkspaceNotFoundError(WorkspaceApplicationError):
pass
class WorkspaceArchivedError(WorkspaceApplicationError):
pass
class WorkspaceNotLinkedError(WorkspaceApplicationError):
pass
class WorkspaceOwnerNotFoundError(WorkspaceApplicationError):
pass
class WorkspaceAlreadyHasOwnerError(WorkspaceApplicationError):
"""An owner cannot join a workspace that already has one."""
class InvalidWorkspaceMemberRoleError(WorkspaceApplicationError):
pass
class OwnerTransferSendIPLimitedError(WorkspaceApplicationError):
"""The caller IP exceeded the ownership-transfer email-send policy."""
class OwnerTransferSendRateLimitError(WorkspaceApplicationError):
"""Too many ownership-transfer confirmation messages were requested."""
def __init__(self, retry_after_minutes: int) -> None:
super().__init__("Too many ownership-transfer confirmation messages")
self.retry_after_minutes = retry_after_minutes
class OwnerTransferVerificationLimitError(WorkspaceApplicationError):
"""Too many invalid ownership-transfer verification codes were submitted."""
class InvalidOwnerTransferTokenError(WorkspaceApplicationError):
"""The ownership-transfer token is missing or invalid."""
class InvalidOwnerTransferEmailError(WorkspaceApplicationError):
"""The ownership-transfer token belongs to another email address."""
class InvalidOwnerTransferCodeError(WorkspaceApplicationError):
"""The verification code does not match the ownership-transfer token."""
class PendingInvitationNotFoundError(WorkspaceApplicationError):
"""No live invitation exists for the email in this workspace."""
class WorkspaceInvitationQuotaError(WorkspaceApplicationError):
def __init__(self, *, seats: bool = False) -> None:
super().__init__("Workspace invitation quota exceeded")
self.seats = seats
class WorkspaceMemberLicenseQuotaError(WorkspaceInvitationQuotaError):
"""The workspace member allowance in the license is exhausted."""