Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(teams): return crm_enabled from GET /team (#4764)
Evan Hutnikd469d2edf7cc
diff --git a/.sqlx/query-322b3420ee6b76c4b85d1953e2bfb47c8b8ba0618e2833475801815dff29d42b.json b/.sqlx/query-4c49a19453f820f3daa2f654a67db0bc895b15a7cd5f282133e292f97e42ec19.jsonsimilarity index 50%rename from .sqlx/query-322b3420ee6b76c4b85d1953e2bfb47c8b8ba0618e2833475801815dff29d42b.jsonrename to .sqlx/query-4c49a19453f820f3daa2f654a67db0bc895b15a7cd5f282133e292f97e42ec19.jsonindex baf375e8ba..7133edad58 100644--- a/.sqlx/query-322b3420ee6b76c4b85d1953e2bfb47c8b8ba0618e2833475801815dff29d42b.json+++ b/.sqlx/query-4c49a19453f820f3daa2f654a67db0bc895b15a7cd5f282133e292f97e42ec19.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT id, name, slug, owner_id\n FROM team\n WHERE id = $1\n ",+ "query": "\n SELECT t.id, t.name, t.slug, t.owner_id,\n COALESCE(tcs.crm_enabled, FALSE) AS \"crm_enabled!\"\n FROM team t\n JOIN team_user tu ON t.id = tu.team_id\n LEFT JOIN team_crm_settings tcs ON tcs.team_id = t.id\n WHERE tu.user_id = $1\n ","describe": {"columns": [{@@ -22,19 +22,25 @@"ordinal": 3,"name": "owner_id","type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "crm_enabled!",+ "type_info": "Bool"}],"parameters": {"Left": [- "Uuid"+ "Text"]},"nullable": [false,false,false,- false+ false,+ null]},- "hash": "322b3420ee6b76c4b85d1953e2bfb47c8b8ba0618e2833475801815dff29d42b"+ "hash": "4c49a19453f820f3daa2f654a67db0bc895b15a7cd5f282133e292f97e42ec19"}diff --git a/.sqlx/query-cba64686023001741b1fa46b747fffa9af9eabd558af03fd0e2a250d29a4a64d.json b/.sqlx/query-c2628632426ab991146cd647e78158438a5126b027a0c12b834b8874a166c9c5.jsonsimilarity index 59%rename from .sqlx/query-cba64686023001741b1fa46b747fffa9af9eabd558af03fd0e2a250d29a4a64d.jsonrename to .sqlx/query-c2628632426ab991146cd647e78158438a5126b027a0c12b834b8874a166c9c5.jsonindex fc4e6700ae..8aa827f2d3 100644--- a/.sqlx/query-cba64686023001741b1fa46b747fffa9af9eabd558af03fd0e2a250d29a4a64d.json+++ b/.sqlx/query-c2628632426ab991146cd647e78158438a5126b027a0c12b834b8874a166c9c5.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n SELECT t.id, t.name, t.slug, t.owner_id\n FROM team t\n JOIN team_user tu ON t.id = tu.team_id\n WHERE tu.user_id = $1\n ",+ "query": "\n SELECT t.id, t.name, t.slug, t.owner_id,\n COALESCE(tcs.crm_enabled, FALSE) AS \"crm_enabled!\"\n FROM team t\n LEFT JOIN team_crm_settings tcs ON tcs.team_id = t.id\n WHERE t.id = $1\n ","describe": {"columns": [{@@ -22,19 +22,25 @@"ordinal": 3,"name": "owner_id","type_info": "Text"+ },+ {+ "ordinal": 4,+ "name": "crm_enabled!",+ "type_info": "Bool"}],"parameters": {"Left": [- "Text"+ "Uuid"]},"nullable": [false,false,false,- false+ false,+ null]},- "hash": "cba64686023001741b1fa46b747fffa9af9eabd558af03fd0e2a250d29a4a64d"+ "hash": "c2628632426ab991146cd647e78158438a5126b027a0c12b834b8874a166c9c5"}diff --git a/apps/web/src/features/settings/Crm.tsx b/apps/web/src/features/settings/Crm.tsxindex cac95bf3cb..fcebb83ede 100644--- a/apps/web/src/features/settings/Crm.tsx+++ b/apps/web/src/features/settings/Crm.tsx@@ -114,20 +114,19 @@ const DISABLE_CRM_PHRASE = 'Disable CRM';function CrmEnablementSection() {const isTeamAdmin = useIsTeamAdmin();+ const teamQuery = useCurrentTeamQuery();const patchCrmMutation = usePatchTeamCrmSettingsMutation();- // The team API doesn't report `crm_enabled`, so the toggle is optimistic:- // it starts from "enabled" and tracks the results of changes made here.- const [crmEnabled, setCrmEnabled] = createSignal(true);+ // The mutation invalidates the team query on success, which refetches+ // the authoritative flag.+ const crmEnabled = () => teamQuery.data?.team.crm_enabled ?? false;const [showDisableModal, setShowDisableModal] = createSignal(false);const [disableConfirmation, setDisableConfirmation] = createSignal('');const handleToggle = (next: boolean) => {if (!isTeamAdmin() || patchCrmMutation.isPending) return;if (next) {- patchCrmMutation.mutate(true, {- onSuccess: (data) => setCrmEnabled(data.enabled),- });+ patchCrmMutation.mutate(true);} else {// Disabling purges the team's CRM data — force a typed confirmation.setDisableConfirmation('');@@ -137,10 +136,7 @@ function CrmEnablementSection() {const handleDisable = () => {patchCrmMutation.mutate(false, {- onSuccess: (data) => {- setCrmEnabled(data.enabled);- setShowDisableModal(false);- },+ onSuccess: () => setShowDisableModal(false),});};@@ -149,7 +145,7 @@ function CrmEnablementSection() {<SettingsCard><SettingsRowlabel="Enable CRM"- description="Turns the CRM on for everyone on your team. This setting isn't reported by the server, so the toggle reflects your latest change here."+ description="Turns the CRM on for everyone on your team."hideDescriptionOnMobile><Showdiff --git a/apps/web/src/lib/queries/team/teams.ts b/apps/web/src/lib/queries/team/teams.tsindex f3c87648da..5f533d4920 100644--- a/apps/web/src/lib/queries/team/teams.ts+++ b/apps/web/src/lib/queries/team/teams.ts@@ -235,6 +235,7 @@ export function useCreateTeamWithInvitesMutation(name,slug: 'MACRO', // optimisitc slugowner_id: userInfo.userId,+ crm_enabled: false,};queryClient.setQueryData<Team[]>(diff --git a/apps/web/src/lib/service-clients/service-auth/generated/schemas/team.ts b/apps/web/src/lib/service-clients/service-auth/generated/schemas/team.tsindex 1eed38acde..d160c92d48 100644--- a/apps/web/src/lib/service-clients/service-auth/generated/schemas/team.ts+++ b/apps/web/src/lib/service-clients/service-auth/generated/schemas/team.ts@@ -9,6 +9,9 @@* The Team struct*/export interface Team {+ /** Whether the CRM is enabled for this team (from `team_crm_settings`;+`false` when no row exists). */+ crm_enabled: boolean;id: string;name: string;owner_id: string;diff --git a/apps/web/src/lib/service-clients/service-auth/openapi.json b/apps/web/src/lib/service-clients/service-auth/openapi.jsonindex 9a7aa0b784..57797a1994 100644--- a/apps/web/src/lib/service-clients/service-auth/openapi.json+++ b/apps/web/src/lib/service-clients/service-auth/openapi.json@@ -4207,8 +4207,12 @@"Team": {"type": "object","description": "The Team struct",- "required": ["id", "name", "slug", "owner_id"],+ "required": ["id", "name", "slug", "owner_id", "crm_enabled"],"properties": {+ "crm_enabled": {+ "type": "boolean",+ "description": "Whether the CRM is enabled for this team (from `team_crm_settings`;\n`false` when no row exists)."+ },"id": {"type": "string","format": "uuid"diff --git a/crates/teams/src/domain/model.rs b/crates/teams/src/domain/model.rsindex 2f5fe35b76..1837bb7dec 100644--- a/crates/teams/src/domain/model.rs+++ b/crates/teams/src/domain/model.rs@@ -238,6 +238,9 @@ pub struct Team {pub(crate) slug: String,#[cfg_attr(feature = "axum", schema(value_type = String))]pub(crate) owner_id: MacroUserIdStr<'static>,+ /// Whether the CRM is enabled for this team (from `team_crm_settings`;+ /// `false` when no row exists).+ pub(crate) crm_enabled: bool,}impl Team {@@ -247,12 +250,14 @@ impl Team {name: String,slug: String,owner_id: MacroUserIdStr<'static>,+ crm_enabled: bool,) -> Self {Self {id,name,slug,owner_id,+ crm_enabled,}}}@@ -277,6 +282,11 @@ impl Team {pub fn owner_id(&self) -> &str {self.owner_id.as_ref()}++ /// Whether the CRM is enabled for this team+ pub fn crm_enabled(&self) -> bool {+ self.crm_enabled+ }}/// Request to create a new teamdiff --git a/crates/teams/src/domain/team_service/test.rs b/crates/teams/src/domain/team_service/test.rsindex 031a99a6b5..b572cf3c79 100644--- a/crates/teams/src/domain/team_service/test.rs+++ b/crates/teams/src/domain/team_service/test.rs@@ -8,7 +8,7 @@ use std::{};use entity_access::domain::models::{- AdminTeamRole, EntityAccessReceipt, EntityType, RequiredPermission,+ AdminTeamRole, EntityAccessReceipt, EntityType, MemberTeamRole, RequiredPermission,};use macro_user_id::{email::Email, lowercased::Lowercase, user_id::MacroUserIdStr};use notification::domain::{@@ -108,6 +108,7 @@ impl MockTeamRepository {MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap().into_owned(),+ false,),github_installation_move_calls: Arc::new(Mutex::new(Vec::new())),subscription_update_calls: Arc::new(Mutex::new(Vec::new())),@@ -1014,6 +1015,7 @@ async fn test_create_team_moves_github_installation_to_created_team() {"New Team".to_string(),"NEW_TEAM".to_string(),user_id.clone().into_owned(),+ false,);let mark_sent_calls: Arc<Mutex<Vec<Vec<uuid::Uuid>>>> = Arc::new(Mutex::new(Vec::new()));let mut team_repo = MockTeamRepository::new(Vec::new(), "Test Team", mark_sent_calls);@@ -1050,6 +1052,7 @@ async fn test_create_team_propagates_github_installation_move_failure() {"New Team".to_string(),"NEW_TEAM".to_string(),user_id.clone().into_owned(),+ false,);let mark_sent_calls: Arc<Mutex<Vec<Vec<uuid::Uuid>>>> = Arc::new(Mutex::new(Vec::new()));let mut team_repo = MockTeamRepository::new(Vec::new(), "Test Team", mark_sent_calls);@@ -1089,6 +1092,7 @@ async fn team_analytics_create_team_emits_created_event_with_team_id() {"Analytics Team".to_string(),"ANALYTICS_TEAM".to_string(),user_id.clone().into_owned(),+ false,);let mark_sent_calls: Arc<Mutex<Vec<Vec<uuid::Uuid>>>> = Arc::new(Mutex::new(Vec::new()));let mut team_repo = MockTeamRepository::new(Vec::new(), "Test Team", mark_sent_calls);@@ -1133,6 +1137,7 @@ async fn team_analytics_failure_is_swallowed_by_create_team() {"Analytics Team".to_string(),"ANALYTICS_TEAM".to_string(),user_id.clone().into_owned(),+ false,);let mark_sent_calls: Arc<Mutex<Vec<Vec<uuid::Uuid>>>> = Arc::new(Mutex::new(Vec::new()));let mut team_repo = MockTeamRepository::new(Vec::new(), "Test Team", mark_sent_calls);@@ -1163,6 +1168,7 @@ async fn team_analytics_create_team_does_not_emit_when_side_effect_fails() {"Analytics Team".to_string(),"ANALYTICS_TEAM".to_string(),user_id.clone().into_owned(),+ false,);let mark_sent_calls: Arc<Mutex<Vec<Vec<uuid::Uuid>>>> = Arc::new(Mutex::new(Vec::new()));let mut team_repo = MockTeamRepository::new(Vec::new(), "Test Team", mark_sent_calls);@@ -1462,6 +1468,40 @@ async fn team_analytics_invite_users_does_not_emit_when_invite_creation_fails()assert!(events.lock().unwrap().is_empty());}+/// get_team reports the `crm_enabled` flag stored on the team row.+#[tokio::test]+async fn test_get_team_reports_crm_enabled() {+ let team_id = uuid::Uuid::from_u128(1);+ let owner_id = MacroUserIdStr::parse_from_str("macro|[email protected]")+ .unwrap()+ .into_owned();+ let team = Team::new(+ team_id,+ "Test Team".to_string(),+ "TEST_TEAM".to_string(),+ owner_id.clone(),+ true,+ );++ let mark_sent_calls: Arc<Mutex<Vec<Vec<uuid::Uuid>>>> = Arc::new(Mutex::new(Vec::new()));+ let team_repo =+ MockTeamRepository::new(Vec::new(), "Test Team", mark_sent_calls).with_team(team);+ let notification_ingress = Arc::new(MockNotificationIngress::new(HashSet::new()));+ let service = TeamServiceImpl::new(+ team_repo,+ MockCustomerRepository::default(),+ MockTeamChannelsRepository::default(),+ MockUserRolesAndPermissionsService::default(),+ notification_ingress,+ NoOpCrmEnqueuer,+ NoOpTeamCrmSettingsRepository,+ );++ let receipt = test_team_receipt::<MemberTeamRole>(team_id, &owner_id);+ let team = service.get_team(receipt).await.unwrap();+ assert!(team.team.crm_enabled());+}+fn build_service_with_team(team: Team,) -> (@@ -1499,6 +1539,7 @@ async fn test_patch_team_rejects_owner_role_assignment() {"Test Team".to_string(),"TEST_TEAM".to_string(),owner_id,+ false,);let (service, role_calls, name_calls) = build_service_with_team(team);@@ -1536,6 +1577,7 @@ async fn test_patch_team_rejects_owner_downgrade() {"Test Team".to_string(),"TEST_TEAM".to_string(),owner_id.clone(),+ false,);let (service, role_calls, name_calls) = build_service_with_team(team);@@ -1574,6 +1616,7 @@ async fn test_patch_team_applies_role_updates_and_name() {"Old Name".to_string(),"OLD_NAME".to_string(),owner_id.clone(),+ false,);let (service, role_calls, name_calls) = build_service_with_team(team);@@ -1631,6 +1674,7 @@ async fn test_patch_team_empty_role_updates() {"Old Name".to_string(),"OLD_NAME".to_string(),owner_id.clone(),+ false,);let (service, role_calls, name_calls) = build_service_with_team(team);@@ -1668,6 +1712,7 @@ async fn test_invite_users_to_team_backfills_legacy_team_subscription() {"Legacy Team".to_string(),"legacy-team".to_string(),owner_id.clone().into_owned(),+ false,));team_repo.team_payment_status = false;team_repo.team_subscription_id = None;@@ -1735,6 +1780,7 @@ async fn test_join_team_backfills_legacy_team_subscription() {"Legacy Team".to_string(),"legacy-team".to_string(),owner_id.clone().into_owned(),+ false,));team_repo.team_payment_status = false;team_repo.team_subscription_id = None;@@ -1792,6 +1838,7 @@ async fn test_join_team_rolls_back_accept_when_backfill_fails() {"Legacy Team".to_string(),"legacy-team".to_string(),owner_id.into_owned(),+ false,));team_repo.team_payment_status = false;team_repo.team_subscription_id = None;diff --git a/crates/teams/src/outbound/team_repo.rs b/crates/teams/src/outbound/team_repo.rsindex b79fca3fe5..d0a314da72 100644--- a/crates/teams/src/outbound/team_repo.rs+++ b/crates/teams/src/outbound/team_repo.rs@@ -160,6 +160,8 @@ impl TeamRepositoryImpl {owner_id: MacroUserIdStr::parse_from_str(&row.owner_id).map_err(type_err)?.into_owned(),+ // New teams have no team_crm_settings row yet.+ crm_enabled: false,})}).fetch_one(&mut *transaction)@@ -1049,9 +1051,11 @@ impl TeamRepository for TeamRepositoryImpl {async fn get_team_by_id(&self, team_id: &uuid::Uuid) -> Result<TeamWithMembers, TeamError> {let team = sqlx::query!(r#"- SELECT id, name, slug, owner_id- FROM team- WHERE id = $1+ SELECT t.id, t.name, t.slug, t.owner_id,+ COALESCE(tcs.crm_enabled, FALSE) AS "crm_enabled!"+ FROM team t+ LEFT JOIN team_crm_settings tcs ON tcs.team_id = t.id+ WHERE t.id = $1"#,team_id,)@@ -1063,6 +1067,7 @@ impl TeamRepository for TeamRepositoryImpl {owner_id: MacroUserIdStr::parse_from_str(&row.owner_id).map_err(type_err)?.into_owned(),+ crm_enabled: row.crm_enabled,})}).fetch_one(&self.pool)@@ -1100,9 +1105,11 @@ impl TeamRepository for TeamRepositoryImpl {async fn get_user_teams(&self, user_id: &MacroUserIdStr<'_>) -> Result<Vec<Team>, TeamError> {let teams = sqlx::query!(r#"- SELECT t.id, t.name, t.slug, t.owner_id+ SELECT t.id, t.name, t.slug, t.owner_id,+ COALESCE(tcs.crm_enabled, FALSE) AS "crm_enabled!"FROM team tJOIN team_user tu ON t.id = tu.team_id+ LEFT JOIN team_crm_settings tcs ON tcs.team_id = t.idWHERE tu.user_id = $1"#,user_id.as_ref(),@@ -1115,6 +1122,7 @@ impl TeamRepository for TeamRepositoryImpl {owner_id: MacroUserIdStr::parse_from_str(&row.owner_id).map_err(type_err)?.into_owned(),+ crm_enabled: row.crm_enabled,})}).fetch_all(&self.pool)