feat: Create Integration Attribute Sync records (#26007)
* Add db schema * Add `CredentialRepository.findByTeamIdAndSlugs` * Add enabled app slugs for attribute syncing * Create repository for `IntegrationAttributeSync` * Create zod schemas * Create `AttributeSyncUserRuleOutputMapper` * Create `IntegrationAttributeSyncService` * Create DI contianer * Create trpc endpoints * Create page * Include team name in `CredentialRepository.findByTeamIdAndSlugs` * Update schema and relations * Update types and schemas * Add more methods to IntegrationAttributeSyncRepository * Add more services to `IntegrationAttributeSyncService` - getById - Init updateIncludeRulesAndMappings * Refactor `getTeams.handler` to use repository * Create `createAttributeSync` trpc endpoint * Create `updateAttributeSync` trpc endpoint * Add router to trpc * Create attribute sync child components * Pass custom actions to `FormCard` * Create `IntegrationAttributeSyncCard` * Pass inital props via server side * Fix prop * Only refetch on mutation * Fixes * Add form error when duplicate field and attribute combo * Add `updateTransactionWithRUleAndMappings` logic * Adjust zod schemas * Service add `updateIncludeRulesAndMappings` * Pass orgId from server to component * Rename types * Add deleteById method to repository * Add name to integrationAttributeSync * Add deleteById method to service * Rename method * Add deleteAttributeSync trpc endpoint * Make the IntegrationAttributeSyncCard a dummy component * test: add tests for IntegrationAttributeSync feature Co-Authored-By: [email protected] <[email protected]> * Move creating a attribute sync record to the service * Add i18n strings * Safe select credential in find by id and team * Fix default credentialId value in form * Update repository return types * Add i18n string * Make credentialId optional for form schema * Fix label * Add cascade deletes * Add verification that syncs belong to org * Create mapper for repository output * Type fixes * Remove old test file * Pass `attributeOptions` from parent to children * Infer types from zod schema * Type fixes * Type fix * Clean up * Add i18n strings * Remove unused file * Address feedback * Add migration file * Address feedback * Add validation for new integration values * Remove unused router * Move away from z.infer to z.ZodType * Clean up comments * Type fix * Type fixes * Type fix * fix: add passthrough to syncFormDataSchema to preserve extra fields Co-Authored-By: [email protected] <[email protected]> * fix: remove incorrect test that expected extra fields to pass through syncFormDataSchema Co-Authored-By: [email protected] <[email protected]> * Add indexes * Add aria label * Address feedback - consistent validation * Fix import paths for attribute types * refactor: change attributeSyncRules array to singular attributeSyncRule The database schema enforces a one-to-one relationship between IntegrationAttributeSync and AttributeSyncRule (via @unique constraint), and the UI only supports a single rule. This change makes the TypeScript type match the database schema and UI behavior. Changes: - Update IntegrationAttributeSync interface to use attributeSyncRule: AttributeSyncRule | null - Update mapper to return singular rule instead of wrapping in array - Update UI component to access sync.attributeSyncRule directly - Update IIntegrationAttributeSyncUpdateParams Omit type - Update tests to use attributeSyncRule: null instead of attributeSyncRules: [] Co-Authored-By: [email protected] <[email protected]> * feat: implement FeatureOptInService (#25805) * feat: implement FeatureOptInService WIP * clean up * feat: consolidate feature repositories and add updateFeatureForUser - Implement updateFeatureForUser in FeaturesRepository (similar to updateFeatureForTeam) - Move getUserFeatureState and getTeamFeatureState from PrismaFeatureOptInRepository to FeaturesRepository - Update FeatureOptInService to use only FeaturesRepository - Add setUserFeatureState and setTeamFeatureState methods to FeatureOptInService - Update _router.ts to remove PrismaFeatureOptInRepository usage - Remove PrismaFeatureOptInRepository.ts and FeatureOptInRepositoryInterface.ts - Update features.repository.interface.ts and features.repository.mock.ts - Add integration tests for updateFeatureForUser, getUserFeatureState, getTeamFeatureState - Update service.integration-test.ts to use FeaturesRepository Co-Authored-By: [email protected] <[email protected]> * refactor: rename updateFeatureForUser to setUserFeatureState Rename to match the convention used for setTeamFeatureState Co-Authored-By: [email protected] <[email protected]> * refactor: return FeatureState type from getUserFeatureState and getTeamFeatureState * fix integration tests * clean up logics * update services and router * refactor: change getUserFeatureState and getTeamFeatureState to accept featureIds array - Renamed getUserFeatureState to getUserFeatureStates - Renamed getTeamFeatureState to getTeamFeatureStates - Changed parameter from featureId: string to featureIds: string[] - Changed return type from FeatureState to Record<string, FeatureState> - Updated FeatureOptInService to use the new batch methods - Added tests for querying multiple features in a single call - Optimized listFeaturesForTeam to fetch all feature states in one query Co-Authored-By: [email protected] <[email protected]> * feat: add getFeatureStateForTeams for batch querying multiple teams - Added getFeatureStateForTeams method to query a single feature across multiple teams in one call - Updated FeatureOptInService.resolveFeatureStateAcrossTeams to use the new batch method - Replaces N+1 queries with a single database query for team states - Added comprehensive integration tests for the new method Co-Authored-By: [email protected] <[email protected]> * refactor: combine org and team state queries into single call - Include orgId in the teamIds array passed to getFeatureStateForTeams - Extract org state and team states from the combined result - Reduces database queries from 3 to 2 in resolveFeatureStateAcrossTeams Co-Authored-By: [email protected] <[email protected]> * refactor: use team.isOrganization and clarify computeEffectiveState comment Co-Authored-By: [email protected] <[email protected]> * refactor: use MembershipRepository.findAllByUserId with isOrganization Co-Authored-By: [email protected] <[email protected]> * feat: add featureId validation using isOptInFeature type guard Co-Authored-By: [email protected] <[email protected]> * less queries * add fallback value * fix type error * move files * add autoOptInFeatures column * use autoOptInFeatures flag within FeatureOptInService * add setUserAutoOptIn and setTeamAutoOptIn * fix computeEffectiveState logic * rewrite computeEffectiveState * clean up integration tests * clean up in afterEach * fix type error * refactor: use FeaturesRepository methods instead of direct Prisma calls Replace all manual userFeatures and teamFeatures Prisma operations with the new setUserFeatureState and setTeamFeatureState repository methods. Changes include: - Admin handlers (assignFeatureToTeam, unassignFeatureFromTeam) - Test fixtures and integration tests - Playwright fixtures - Development scripts This ensures consistent feature flag management through the repository pattern and supports the new tri-state semantics (enabled/disabled/inherit). Co-Authored-By: [email protected] <[email protected]> * clean up * fix the logic * extract some logic into applyAutoOptIn() * remove wrong code * refactor: convert setUserFeatureState and setTeamFeatureState to object params with discriminated union - Convert multiple positional parameters to single object parameter - Use discriminated union types: assignedBy required for enabled/disabled, omitted for inherit - Update all callers across repository, service, handlers, fixtures, and tests * fix type error * use Promise.all * fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * Prevent duplicate field and attribute mappings * Add validation that attribute belongs to the org * fix: address Cubic AI review feedback - Add @@index([credentialId]) to IntegrationAttributeSync model for efficient cascade deletes and credential-based queries (confidence: 9/10) - Fix translation key from 'credential_required' to 'attribute_sync_credential_required' to match existing locale definition (confidence: 10/10) Co-Authored-By: [email protected] <[email protected]> * fix: address remaining cubic review feedback - RuleBuilder.tsx: Use unique IDs for React keys instead of array index to prevent reconciliation bugs when removing conditions - updateAttributeSync.handler.ts: Add early organization check before service calls for consistency - createAttributeSync.handler.ts: Add CredentialNotFoundError class for type-safe error handling instead of string matching - IntegrationAttributeSyncService.test.ts: Replace expect.fail() with proper Vitest rejects.toSatisfy() pattern Co-Authored-By: [email protected] <[email protected]> * Pull test file from main --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Eunjae Lee <[email protected]>
This commit is contained in:
40 files changed
+3524
-19
No files matched your search
+62
@@ -0,0 +1,62 @@
|
||||
import { _generateMetadata, getTranslate } from "app/_utils";
|
||||
|
||||
import IntegrationAttributeSyncView from "@calcom/features/ee/integration-attribute-sync/IntegrationAttributeSyncView";
|
||||
import { getIntegrationAttributeSyncService } from "@calcom/features/ee/integration-attribute-sync/di/IntegrationAttributeSyncService.container";
|
||||
import { TeamRepository } from "@calcom/features/ee/teams/repositories/TeamRepository";
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
import { PrismaAttributeRepository } from "@calcom/features/attributes/repositories/PrismaAttributeRepository";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
|
||||
import { validateUserHasOrgPerms } from "../../../actions/validateUserHasOrgPerms";
|
||||
|
||||
export const generateMetadata = async () =>
|
||||
await _generateMetadata(
|
||||
(t) => t("attribute_sync"),
|
||||
(t) => t("attribute_sync_description"),
|
||||
undefined,
|
||||
undefined,
|
||||
"/settings/organizations/attributes/sync"
|
||||
);
|
||||
|
||||
const Page = async () => {
|
||||
const t = await getTranslate();
|
||||
|
||||
const session = await validateUserHasOrgPerms({
|
||||
permission: "organization.attributes.create",
|
||||
fallbackRoles: ["ADMIN", "OWNER"],
|
||||
redirectTo: "/settings/my-account/profile",
|
||||
});
|
||||
|
||||
const organizationId = session.user.org.id;
|
||||
|
||||
const integrationAttributeSyncService = getIntegrationAttributeSyncService();
|
||||
const teamRepository = new TeamRepository(prisma);
|
||||
const attributeRepo = new PrismaAttributeRepository(prisma);
|
||||
|
||||
const [credentialData, integrationAttributeSyncs, organizationTeams, attributes] = await Promise.all([
|
||||
integrationAttributeSyncService.getEnabledAppCredentials(organizationId),
|
||||
integrationAttributeSyncService.getAllIntegrationAttributeSyncs(organizationId),
|
||||
teamRepository.findAllByParentId({
|
||||
parentId: organizationId,
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
}),
|
||||
attributeRepo.findAllByOrgIdWithOptions({ orgId: organizationId }),
|
||||
]);
|
||||
|
||||
return (
|
||||
<SettingsHeader title={t("attribute_sync")} description={t("attribute_sync_description")}>
|
||||
<IntegrationAttributeSyncView
|
||||
credentialsData={credentialData}
|
||||
initialIntegrationAttributeSyncs={integrationAttributeSyncs}
|
||||
organizationTeams={organizationTeams}
|
||||
attributes={attributes}
|
||||
organizationId={organizationId}
|
||||
/>
|
||||
</SettingsHeader>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page;
|
||||
@@ -0,0 +1,4 @@
|
||||
import { createNextApiHandler } from "@calcom/trpc/server/createNextApiHandler";
|
||||
import { attributeSyncRouter } from "@calcom/trpc/server/routers/viewer/attribute-sync/_router";
|
||||
|
||||
export default createNextApiHandler(attributeSyncRouter);
|
||||
@@ -374,6 +374,7 @@
|
||||
"done": "Done",
|
||||
"all_done": "All done!",
|
||||
"all": "All",
|
||||
"any": "Any",
|
||||
"yours": "Your account",
|
||||
"available_apps": "Available Apps",
|
||||
"available_apps_lower_case": "Available apps",
|
||||
@@ -3101,6 +3102,47 @@
|
||||
"back_to_attributes": "Back to attributes",
|
||||
"delete_attribute": "Are you sure you want to delete this option?",
|
||||
"delete_attribute_description": "This option is assigned to {{numberOfUsers}} members. Deleting it will remove it from their profile.",
|
||||
"attribute_sync": "Attribute Sync",
|
||||
"attribute_sync_description": "Setup attribute syncing with 3rd party integrations",
|
||||
"attribute_sync_new_integration_sync": "New Integration Sync",
|
||||
"attribute_sync_credential": "Credential",
|
||||
"attribute_sync_credential_required": "Credential is required",
|
||||
"attribute_sync_credential_validation": "Select a credential for the attribute sync",
|
||||
"attribute_sync_select_credential": "Select a credential...",
|
||||
"attribute_sync_credential_description": "Choose which integration credential to use for syncing attributes",
|
||||
"attribute_sync_user_filter_rules": "User Filter Rules",
|
||||
"attribute_sync_user_filter_rules_description": "Define which users to sync based on team membership or attributes",
|
||||
"attribute_sync_field_mappings": "Field Mappings",
|
||||
"attribute_sync_duplicate_field_mapping": "Duplicate field name and attribute combination found",
|
||||
"attribute_sync_duplicate_attribute_mapping": "Each attribute can only be mapped once",
|
||||
"attribute_sync_field_mappings_description": "Map integration field names to Cal.com attributes for syncing",
|
||||
"attribute_sync_created_successfully": "Attribute sync created successfully",
|
||||
"attribute_sync_updated_successfully": "Attribute sync updated successfully",
|
||||
"attribute_sync_deleted_successfully": "Attribute sync deleted successfully",
|
||||
"attribute_sync_delete_title": "Delete Attribute Sync",
|
||||
"attribute_sync_delete_confirmation": "Are you sure you want to delete this sync? This action cannot be undone.",
|
||||
"attribute_sync_no_mappings": "No field mappings added. Click below to add your first mapping.",
|
||||
"attribute_sync_add_mapping": "Add mapping",
|
||||
"attribute_sync_field_placeholder": "e.g., Department, Title...",
|
||||
"attribute_sync_select_attribute": "Select Cal.com attribute...",
|
||||
"attribute_sync_add_new": "Add new sync",
|
||||
"attribute_sync_select_teams": "Select team(s)...",
|
||||
"attribute_sync_select_attribute_first": "Select an attribute first",
|
||||
"attribute_sync_select_values": "Select value(s)...",
|
||||
"attribute_sync_enter_text_value": "Enter text value...",
|
||||
"attribute_sync_enter_number_value": "Enter number value...",
|
||||
"attribute_sync_sync_users_where": "Sync users where",
|
||||
"attribute_sync_conditions_match": "conditions match:",
|
||||
"attribute_sync_no_conditions": "No conditions added. Click below to add your first condition.",
|
||||
"attribute_sync_add_condition": "Add condition",
|
||||
"attribute_sync_operator_is_any_of": "is any of",
|
||||
"attribute_sync_operator_is_not_any_of": "is not any of",
|
||||
"attribute_sync_operator_is": "is",
|
||||
"attribute_sync_operator_is_not": "is not",
|
||||
"attribute_sync_operator_includes_any_of": "includes any of",
|
||||
"attribute_sync_operator_does_not_include": "does not include",
|
||||
"attribute_sync_operator_equals": "equals",
|
||||
"attribute_sync_operator_not_equals": "not equals",
|
||||
"disable_all_emails_to_attendees": "Disable standard emails to attendees related to this event type",
|
||||
"disable_all_emails_description": "Disables standard email communication related to this event type, including booking confirmations, reminders, and cancellations.",
|
||||
"disable_all_emails_to_hosts": "Disable standard emails to hosts related to this event type",
|
||||
|
||||
Reference in new issue
Block a user