d750df7fff
Closes #14726 ### Added - `trashRetentionDays` field to workspace entity (default: 14 days) - Automated trash cleanup using BullMQ jobs - Daily cron (00:10 UTC) that enqueues cleanup jobs for all active workspaces - Per-workspace limit: 100k records deleted per day - Calendar-based retention: records deleted on day X are cleaned up X+14 days later (at midnight UTC boundaries) ### Architecture - **Cron (WorkspaceTrashCleanupCronJob):** Runs daily, enqueues jobs in parallel for all workspaces - **Job (WorkspaceTrashCleanupJob):** Processes individual workspace cleanup - **Service (WorkspaceTrashCleanupService):** Discovers tables with `deletedAt`, deletes old records with quota enforcement - **Command:** `npx nx run twenty-server:command cron:workspace:cleanup-trash` to register the cron ### Testing - Unit tests for service with 100% coverage of public API - Tested quota enforcement, error handling, and edge cases --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
101 lines
3.0 KiB
TypeScript
101 lines
3.0 KiB
TypeScript
import {
|
|
AVAILABLE_WORKSPACE_FOR_AUTH_FRAGMENT,
|
|
AVAILABLE_WORKSPACES_FOR_AUTH_FRAGMENT,
|
|
} from '@/auth/graphql/fragments/authFragments';
|
|
import { OBJECT_PERMISSION_FRAGMENT } from '@/settings/roles/graphql/fragments/objectPermissionFragment';
|
|
import { ROLE_FRAGMENT } from '@/settings/roles/graphql/fragments/roleFragment';
|
|
import { BILLING_SUBSCRIPTION_FRAGMENT } from '@/users/graphql/fragments/billingSubscriptionsFragment';
|
|
import { CURRENT_BILLING_SUBSCRIPTION_FRAGMENT } from '@/users/graphql/fragments/currentBillingSubscriptionFragement';
|
|
import { WORKSPACE_URLS_FRAGMENT } from '@/users/graphql/fragments/workspaceUrlsFragment';
|
|
import { DELETED_WORKSPACE_MEMBER_QUERY_FRAGMENT } from '@/workspace-member/graphql/fragments/deletedWorkspaceMemberQueryFragment';
|
|
import { PARTIAL_WORKSPACE_MEMBER_QUERY_FRAGMENT } from '@/workspace-member/graphql/fragments/partialWorkspaceMemberQueryFragment';
|
|
import { WORKSPACE_MEMBER_QUERY_FRAGMENT } from '@/workspace-member/graphql/fragments/workspaceMemberQueryFragment';
|
|
import { gql } from '@apollo/client';
|
|
|
|
export const USER_QUERY_FRAGMENT = gql`
|
|
fragment UserQueryFragment on User {
|
|
id
|
|
firstName
|
|
lastName
|
|
email
|
|
canAccessFullAdminPanel
|
|
canImpersonate
|
|
supportUserHash
|
|
onboardingStatus
|
|
workspaceMember {
|
|
...WorkspaceMemberQueryFragment
|
|
}
|
|
workspaceMembers {
|
|
...PartialWorkspaceMemberQueryFragment
|
|
}
|
|
deletedWorkspaceMembers {
|
|
...DeletedWorkspaceMemberQueryFragment
|
|
}
|
|
currentUserWorkspace {
|
|
permissionFlags
|
|
objectsPermissions {
|
|
...ObjectPermissionFragment
|
|
}
|
|
twoFactorAuthenticationMethodSummary {
|
|
twoFactorAuthenticationMethodId
|
|
status
|
|
strategy
|
|
}
|
|
}
|
|
currentWorkspace {
|
|
id
|
|
displayName
|
|
logo
|
|
inviteHash
|
|
allowImpersonation
|
|
activationStatus
|
|
isPublicInviteLinkEnabled
|
|
isGoogleAuthEnabled
|
|
isMicrosoftAuthEnabled
|
|
isPasswordAuthEnabled
|
|
subdomain
|
|
hasValidEnterpriseKey
|
|
customDomain
|
|
isCustomDomainEnabled
|
|
workspaceUrls {
|
|
...WorkspaceUrlsFragment
|
|
}
|
|
featureFlags {
|
|
key
|
|
value
|
|
}
|
|
metadataVersion
|
|
currentBillingSubscription {
|
|
...CurrentBillingSubscriptionFragment
|
|
}
|
|
billingSubscriptions {
|
|
...BillingSubscriptionFragment
|
|
}
|
|
workspaceMembersCount
|
|
defaultRole {
|
|
...RoleFragment
|
|
}
|
|
defaultAgent {
|
|
id
|
|
}
|
|
isTwoFactorAuthenticationEnforced
|
|
trashRetentionDays
|
|
}
|
|
availableWorkspaces {
|
|
...AvailableWorkspacesFragment
|
|
}
|
|
userVars
|
|
}
|
|
|
|
${WORKSPACE_MEMBER_QUERY_FRAGMENT}
|
|
${DELETED_WORKSPACE_MEMBER_QUERY_FRAGMENT}
|
|
${PARTIAL_WORKSPACE_MEMBER_QUERY_FRAGMENT}
|
|
${OBJECT_PERMISSION_FRAGMENT}
|
|
${WORKSPACE_URLS_FRAGMENT}
|
|
${ROLE_FRAGMENT}
|
|
${AVAILABLE_WORKSPACES_FOR_AUTH_FRAGMENT}
|
|
${AVAILABLE_WORKSPACE_FOR_AUTH_FRAGMENT}
|
|
${CURRENT_BILLING_SUBSCRIPTION_FRAGMENT}
|
|
${BILLING_SUBSCRIPTION_FRAGMENT}
|
|
`;
|