Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(teams): let teammates join without membership caps (#6699)

Jacob Beckermana7cdc6e059c4
diff --git a/crates/teams/src/domain/model.rs b/crates/teams/src/domain/model.rs
index 054e8a877a..fd0869c7fd 100644
--- a/crates/teams/src/domain/model.rs
+++ b/crates/teams/src/domain/model.rs
@@ -39,24 +39,6 @@ pub enum TeamPlan {
Growth,
}
-impl TeamPlan {
- /// Get the seat cap associated with a team plan
- pub fn seat_cap(&self) -> i32 {
- match self {
- TeamPlan::Idea => 3,
- TeamPlan::PreSeed => 6,
- TeamPlan::Seed => 10,
- TeamPlan::SeriesA => 25,
- TeamPlan::Growth => i32::MAX,
- }
- }
-}
-
-/// Maximum number of members (including the owner) a team may have without a
-/// Stripe subscription. Teams at or under this size are free; growing past it
-/// requires the owner to subscribe.
-pub const FREE_TEAM_MAX_MEMBERS: i32 = 5;
-
/// Slug assigned when a team name cannot be converted to a valid team slug.
pub const DEFAULT_TEAM_SLUG: &str = "MACRO";
@@ -535,9 +517,6 @@ pub enum InviteUsersToTeamError {
/// Too many emails were provided
#[error("Too many emails were provided")]
TooManyEmails,
- /// Not enough open seats
- #[error("Not enough open seats")]
- NotEnoughOpenSeats,
/// The team only allows admins to invite and the caller is not an admin
#[error("only team admins may invite users to this team")]
NonAdminInvitesDisabled,
@@ -667,9 +646,6 @@ pub enum JoinTeamError {
#[error("Underlying user roles and permissions error")]
/// Underlying user roles and permissions error
AddRolesToUserError(#[from] UserRolesAndPermissionsError),
- /// The team has no subscription and is already at the free member limit
- #[error("Team is at the free member limit of {FREE_TEAM_MAX_MEMBERS}")]
- FreeTeamLimitReached,
}
/// Errors for toggling a team's auto-join domain
diff --git a/crates/teams/src/domain/team_repo.rs b/crates/teams/src/domain/team_repo.rs
index ae48b68ebd..f9404a381c 100644
--- a/crates/teams/src/domain/team_repo.rs
+++ b/crates/teams/src/domain/team_repo.rs
@@ -48,7 +48,7 @@ pub trait TeamRepository: Clone + Send + Sync + 'static {
) -> impl Future<Output = Result<bool, TeamError>> + Send;
/// Creates a new team with the provided normalized slug. `subscription_id` is `None` for
- /// free teams (capped at [`crate::domain::model::FREE_TEAM_MAX_MEMBERS`] members).
+ /// free teams. Membership is not capped by team size.
fn create_team(
&self,
user_id: &MacroUserIdStr<'_>,
@@ -325,8 +325,8 @@ pub trait TeamMembersService: Clone + Send + Sync + 'static {
/// The TeamService defines a set of actions to perform on the teams
pub trait TeamService: Clone + Send + Sync + 'static {
- /// Creates a new team. `subscription_id` is `None` for free teams
- /// (capped at [`crate::domain::model::FREE_TEAM_MAX_MEMBERS`] members).
+ /// Creates a new team. `subscription_id` is `None` for free teams.
+ /// Membership is not capped by team size.
fn create_team(
&self,
user_id: &MacroUserIdStr<'_>,
@@ -502,8 +502,7 @@ pub trait TeamService: Clone + Send + Sync + 'static {
/// roles / channel side effects as `join_team`.
///
/// Returns the new team member, or None when no team matched or the
- /// user could not be joined (already a member, team at its seat cap,
- /// ...).
+ /// user is already on a team. Membership is not capped by plan or team size.
fn try_join_team_by_domain(
&self,
user_id: &MacroUserIdStr<'_>,
diff --git a/crates/teams/src/domain/team_service.rs b/crates/teams/src/domain/team_service.rs
index c0d696f7e4..cf4f14081d 100644
--- a/crates/teams/src/domain/team_service.rs
+++ b/crates/teams/src/domain/team_service.rs
@@ -39,9 +39,9 @@ use crate::domain::{
TeamMemberRoleChangedMetadata, TeamUpdatedMetadata,
},
model::{
- CreateTeamError, CustomerError, DeleteTeamError, FREE_TEAM_MAX_MEMBERS,
- InviteUsersToTeamError, JoinTeamError, PatchTeamCrmSettingsResponse, PatchTeamRequest,
- RemoveTeamInviteError, RemoveUserFromTeamError, RestorePermissionsForTeamMembersError,
+ CreateTeamError, CustomerError, DeleteTeamError, InviteUsersToTeamError, JoinTeamError,
+ PatchTeamCrmSettingsResponse, PatchTeamRequest, RemoveTeamInviteError,
+ RemoveUserFromTeamError, RestorePermissionsForTeamMembersError,
RevokePermissionsForTeamMembersError, Team, TeamError, TeamInvite, TeamInviteDetails,
TeamMember, TeamMembers, TeamRole, TeamWithMembers, ToggleAutoJoinDomainError,
TryJoinTeamByDomainError, is_generic_email_domain, team_slug_from_name,
@@ -418,7 +418,7 @@ where
/// Runs [`Self::backfill_legacy_team_subscription`], treating "the owner
/// simply has no active subscription" as a benign outcome: the team is a
- /// free team (capped at [`FREE_TEAM_MAX_MEMBERS`]) rather than an error.
+ /// free team rather than an error. Team size does not require an upgrade.
/// Every other failure still propagates.
async fn backfill_legacy_team_subscription_or_free(
&self,
@@ -711,33 +711,13 @@ where
}
}
- let team_plan = self.team_repository.get_team_plan(&team_id).await?;
- let seat_count = self.team_repository.get_team_seat_count(&team_id).await?;
-
+ // Membership is not capped by plan or team size. Existing invite
+ // permissions still apply; billing and entitlements are handled on join.
let new_invites = self
.team_repository
.get_new_invites(&team_id, invites.clone())
.await?;
- if let Some(team_plan) = team_plan
- && seat_count + new_invites.len() as i32 > team_plan.seat_cap()
- {
- return Err(InviteUsersToTeamError::NotEnoughOpenSeats);
- }
-
- // Free teams (no subscription) are capped at FREE_TEAM_MAX_MEMBERS.
- if !enterprise
- && team_plan.is_none()
- && self
- .team_repository
- .get_team_subscription_id(&team_id)
- .await?
- .is_none()
- && seat_count + new_invites.len() as i32 > FREE_TEAM_MAX_MEMBERS
- {
- return Err(InviteUsersToTeamError::NotEnoughOpenSeats);
- }
-
let new_invite_emails: HashSet<String> = new_invites
.iter()
.map(|email| email.as_ref().to_owned())
@@ -1263,47 +1243,8 @@ where
};
match team_subscription_id {
- // Free team: no seat billing, but the member count (which
- // already includes this newly accepted member) must stay
- // within the free limit.
- None => {
- let seat_count = match self
- .team_repository
- .get_team_seat_count(&team_member.team_id)
- .await
- {
- Ok(seat_count) => seat_count,
- Err(error) => {
- self.team_repository
- .rollback_accept_team_invite(&accepted_invite)
- .await
- .inspect_err(|rollback_err| {
- tracing::error!(
- error=?rollback_err,
- "unable to rollback accepted team invite after getting team seat count failed"
- );
- })
- .ok();
- return Err(JoinTeamError::TeamError(error));
- }
- };
-
- if seat_count > FREE_TEAM_MAX_MEMBERS {
- self.team_repository
- .rollback_accept_team_invite(&accepted_invite)
- .await
- .inspect_err(|rollback_err| {
- tracing::error!(
- error=?rollback_err,
- "unable to rollback accepted team invite after the free member limit check"
- );
- })
- .ok();
- return Err(JoinTeamError::FreeTeamLimitReached);
- }
-
- None
- }
+ // Free membership never creates a paid seat or grants premium roles.
+ None => None,
Some(subscription_id) => {
if let Err(e) = self
.customer_repository
@@ -1782,16 +1723,6 @@ where
.get_team_enterprise_status(&team_id)
.await?;
- // Mirror the seat-cap check from invite_users_to_team - an
- // auto-join must not push the team past its plan's seat cap.
- if let Some(team_plan) = self.team_repository.get_team_plan(&team_id).await? {
- let seat_count = self.team_repository.get_team_seat_count(&team_id).await?;
- if seat_count + 1 > team_plan.seat_cap() {
- tracing::info!(%team_id, %user_id, "skipping team auto-join: team is at its seat cap");
- return Ok(None);
- }
- }
-
// Add the user to the team directly (no invite), then run the same
// billing / roles / channels side effects as join_team, rolling
// the membership back if any of them fail.
@@ -1874,38 +1805,8 @@ where
};
match team_subscription_id {
- // Free team: no seat billing. The member count (already
- // bumped by add_user_to_team) must stay within the free
- // limit - over the cap, skip the auto-join silently like
- // the plan seat-cap check above.
- None => {
- let seat_count = match self.team_repository.get_team_seat_count(&team_id).await
- {
- Ok(seat_count) => seat_count,
- Err(error) => {
- self.rollback_add_user_to_team(
- &team_id,
- user_id,
- "getting team seat count",
- )
- .await;
- return Err(error.into());
- }
- };
-
- if seat_count > FREE_TEAM_MAX_MEMBERS {
- tracing::info!(%team_id, %user_id, "skipping team auto-join: free team is at its member limit");
- self.rollback_add_user_to_team(
- &team_id,
- user_id,
- "the free member limit check",
- )
- .await;
- return Ok(None);
- }
-
- None
- }
+ // Free membership never creates a paid seat or grants premium roles.
+ None => None,
Some(subscription_id) => {
if let Err(e) = self
.customer_repository
diff --git a/crates/teams/src/domain/team_service/test.rs b/crates/teams/src/domain/team_service/test.rs
index 976d5fe261..f1d4c86d43 100644
--- a/crates/teams/src/domain/team_service/test.rs
+++ b/crates/teams/src/domain/team_service/test.rs
@@ -66,6 +66,10 @@ use crate::domain::{
team_repo::TeamRepository,
};
+// Historical thresholds are regression fixtures, not membership policy.
+const FORMER_FREE_MEMBER_LIMIT: i32 = 5;
+const FORMER_IDEA_MEMBER_LIMIT: i32 = 3;
+
// -- Mock TeamRepository --
#[derive(Clone)]
@@ -2395,7 +2399,7 @@ async fn invite_users_to_team_enterprise_bypasses_billing_and_preserves_side_eff
team_repo.team_subscription_id = Some("sub_enterprise_sentinel".parse().unwrap());
team_repo.stripe_customer_id = Some("cus_enterprise_sentinel".parse().unwrap());
team_repo.team_plan = Some(TeamPlan::Idea);
- team_repo.seat_count = TeamPlan::Idea.seat_cap() - 1;
+ team_repo.seat_count = FORMER_IDEA_MEMBER_LIMIT - 1;
let enterprise_status_lookup_calls = team_repo.enterprise_status_lookup_calls.clone();
let payment_status_lookup_calls = team_repo.team_payment_status_lookup_calls.clone();
@@ -2597,7 +2601,7 @@ async fn toggle_allow_non_admin_invites_delegates_to_repository() {
}
#[tokio::test]
-async fn invite_users_to_team_enterprise_enforces_team_plan_seat_cap() {
+async fn invite_users_to_team_enterprise_allows_invites_past_former_plan_limit() {
let team_id = uuid::Uuid::from_u128(6010);
let invite_id = uuid::Uuid::from_u128(6011);
let invited_by = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
@@ -2611,7 +2615,7 @@ async fn invite_users_to_team_enterprise_enforces_team_plan_seat_cap() {
team_repo.team_payment_status = false;
team_repo.team_subscription_id = Some("sub_enterprise_sentinel".parse().unwrap());
team_repo.team_plan = Some(TeamPlan::Idea);
- team_repo.seat_count = TeamPlan::Idea.seat_cap();
+ team_repo.seat_count = FORMER_IDEA_MEMBER_LIMIT;
let payment_status_lookup_calls = team_repo.team_payment_status_lookup_calls.clone();
let subscription_id_lookup_calls = team_repo.team_subscription_id_lookup_calls.clone();
@@ -2637,18 +2641,19 @@ async fn invite_users_to_team_enterprise_enforces_team_plan_seat_cap() {
let invites = non_empty::NonEmpty::new(invite_emails.as_slice()).unwrap();
let receipt = test_team_receipt::<MemberTeamRole>(team_id, &invited_by);
- let error = service
+ let result = service
.invite_users_to_team(receipt, invites)
.await
- .unwrap_err();
+ .unwrap();
- assert!(matches!(error, InviteUsersToTeamError::NotEnoughOpenSeats));
+ assert_eq!(result.len(), 1);
+ assert_eq!(result[0].team_invite_id, invite_id);
assert_eq!(*payment_status_lookup_calls.lock().unwrap(), 0);
assert_eq!(*subscription_id_lookup_calls.lock().unwrap(), 0);
- assert_eq!(*invitation_persistence_calls.lock().unwrap(), 0);
- assert_eq!(notification_ingress.call_count.load(Ordering::SeqCst), 0);
- assert!(mark_sent_calls.lock().unwrap().is_empty());
- assert!(analytics_events.lock().unwrap().is_empty());
+ assert_eq!(*invitation_persistence_calls.lock().unwrap(), 1);
+ assert_eq!(notification_ingress.call_count.load(Ordering::SeqCst), 1);
+ assert_eq!(*mark_sent_calls.lock().unwrap(), vec![vec![invite_id]]);
+ assert_eq!(analytics_events.lock().unwrap().len(), 1);
}
#[tokio::test]
@@ -4030,7 +4035,7 @@ async fn test_join_team_owner_without_subscription_joins_as_free_team() {
team_repo.team_payment_status = false;
team_repo.team_subscription_id = None;
team_repo.stripe_customer_id = Some("cus_backfill_join".parse().unwrap());
- team_repo.seat_count = FREE_TEAM_MAX_MEMBERS;
+ team_repo.seat_count = FORMER_FREE_MEMBER_LIMIT;
team_repo.accepted_invite = Some(make_accepted_invite(team_id, invite_id, &user_id));
let rollback_accept_calls = team_repo.rollback_accept_calls.clone();
@@ -4765,13 +4770,11 @@ async fn test_try_join_team_by_domain_returns_none_when_already_member() {
}
#[tokio::test]
-async fn test_try_join_team_by_domain_skips_team_at_seat_cap() {
+async fn test_try_join_team_by_domain_paid_team_joins_past_former_plan_limit() {
let team_id = uuid::Uuid::from_u128(79);
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
let mark_sent_calls: Arc<Mutex<Vec<Vec<uuid::Uuid>>>> = Arc::new(Mutex::new(Vec::new()));
- // The mock would add the member, so a None result proves the seat-cap
- // check short-circuited before the membership insert.
let mut team_repo = MockTeamRepository::new(Vec::new(), "Test Team", mark_sent_calls);
team_repo.team_id_for_domain = Some(team_id);
team_repo.add_user_to_team_result = Some(make_team_member(
@@ -4780,7 +4783,8 @@ async fn test_try_join_team_by_domain_skips_team_at_seat_cap() {
TeamRole::Member,
));
team_repo.team_plan = Some(TeamPlan::Idea);
- team_repo.seat_count = TeamPlan::Idea.seat_cap();
+ team_repo.seat_count = FORMER_IDEA_MEMBER_LIMIT;
+ team_repo.team_subscription_id = Some("sub_test".parse().unwrap());
let customer_repo = MockCustomerRepository::default();
let increment_calls = customer_repo.increment_calls.clone();
@@ -4799,9 +4803,18 @@ async fn test_try_join_team_by_domain_skips_team_at_seat_cap() {
let member = service.try_join_team_by_domain(&user_id).await.unwrap();
- assert!(member.is_none());
- assert!(increment_calls.lock().unwrap().is_empty());
- assert!(event_broker.events().is_empty());
+ assert_eq!(member.unwrap().team_id, team_id);
+ assert_eq!(
+ *increment_calls.lock().unwrap(),
+ vec![("sub_test".to_string(), 1)]
+ );
+ let events = event_broker.events();
+ assert_eq!(events.len(), 1);
+ assert_eq!(events[0].envelope["event_type"], "team.member_joined");
+ assert_eq!(
+ events[0].envelope["metadata"]["join_method"]["type"],
+ "domain_auto_join"
+ );
}
#[tokio::test]
@@ -4992,12 +5005,12 @@ async fn try_join_team_by_domain_enterprise_bypasses_billing_and_preserves_side_
}
#[tokio::test]
-async fn try_join_team_by_domain_enterprise_still_enforces_local_seat_cap() {
+async fn try_join_team_by_domain_enterprise_joins_past_former_plan_limit() {
let team_id = uuid::Uuid::from_u128(82);
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
let mut team_repository = make_enterprise_domain_join_team_repository(team_id, &user_id);
team_repository.team_plan = Some(TeamPlan::Idea);
- team_repository.seat_count = TeamPlan::Idea.seat_cap();
+ team_repository.seat_count = FORMER_IDEA_MEMBER_LIMIT;
let customer_repository = MockCustomerRepository::default();
let channels_repository = RecordingChannelService::default();
let roles_service = MockUserRolesAndPermissionsService::default();
@@ -5017,7 +5030,7 @@ async fn try_join_team_by_domain_enterprise_still_enforces_local_seat_cap() {
let member = service.try_join_team_by_domain(&user_id).await.unwrap();
- assert!(member.is_none());
+ assert_eq!(member.unwrap().team_id, team_id);
assert_eq!(
*team_repository
.enterprise_status_lookup_calls
@@ -5025,18 +5038,18 @@ async fn try_join_team_by_domain_enterprise_still_enforces_local_seat_cap() {
.unwrap(),
1
);
- assert_eq!(*team_repository.add_user_to_team_calls.lock().unwrap(), 0);
+ assert_eq!(*team_repository.add_user_to_team_calls.lock().unwrap(), 1);
assert_eq!(*team_repository.remove_user_calls.lock().unwrap(), 0);
assert_no_enterprise_join_team_billing_calls(&team_repository, &customer_repository);
- assert!(roles_service.upsert_calls.lock().unwrap().is_empty());
- assert!(
- channels_repository
- .auto_join_calls
- .lock()
- .unwrap()
- .is_empty()
+ assert_eq!(roles_service.upsert_calls.lock().unwrap().len(), 1);
+ assert_eq!(
+ *channels_repository.auto_join_calls.lock().unwrap(),
+ vec![(team_id, user_id.as_ref().to_string())]
+ );
+ assert_eq!(
+ *crm_enqueuer.populated.lock().unwrap(),
+ vec![user_id.as_ref().to_string()]
);
- assert!(crm_enqueuer.populated.lock().unwrap().is_empty());
assert!(events.lock().unwrap().is_empty());
}
@@ -5698,7 +5711,7 @@ async fn team_contacts_domain_join_does_not_enqueue_for_existing_member() {
}
#[tokio::test]
-async fn team_contacts_domain_join_does_not_enqueue_at_seat_cap() {
+async fn team_contacts_domain_join_enqueues_past_former_plan_limit() {
let team_id = uuid::Uuid::from_u128(6013);
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
let mut team_repository = MockTeamRepository::new(
@@ -5706,9 +5719,18 @@ async fn team_contacts_domain_join_does_not_enqueue_at_seat_cap() {
"Contacts Team",
Arc::new(Mutex::new(Vec::new())),
);
+ let owner = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ team_repository = team_repository.with_team(Team::new(
+ team_id,
+ "Contacts Team".to_string(),
+ "CONTACTS_TEAM".to_string(),
+ owner.clone().into_owned(),
+ false,
+ true,
+ ));
team_repository.team_id_for_domain = Some(team_id);
team_repository.team_plan = Some(TeamPlan::Idea);
- team_repository.seat_count = TeamPlan::Idea.seat_cap();
+ team_repository.seat_count = FORMER_IDEA_MEMBER_LIMIT;
team_repository.add_user_to_team_result = Some(make_team_member(
team_id,
user_id.as_ref(),
@@ -5728,10 +5750,14 @@ async fn team_contacts_domain_join_does_not_enqueue_at_seat_cap() {
let member = service.try_join_team_by_domain(&user_id).await.unwrap();
- assert!(member.is_none());
- assert_eq!(*team_repository.add_user_to_team_calls.lock().unwrap(), 0);
- assert_eq!(*team_repository.get_team_by_id_calls.lock().unwrap(), 0);
- assert!(contacts_enqueuer.batches.lock().unwrap().is_empty());
+ assert_eq!(member.unwrap().team_id, team_id);
+ assert_eq!(*team_repository.add_user_to_team_calls.lock().unwrap(), 1);
+ let batches = contacts_enqueuer.batches.lock().unwrap();
+ assert_eq!(batches.len(), 1);
+ assert_eq!(
+ contact_connection_set(&batches[0]),
+ HashSet::from([(user_id.as_ref().to_string(), owner.as_ref().to_string())])
+ );
}
#[tokio::test]
@@ -5893,7 +5919,7 @@ async fn invite_users_to_team_free_team_under_cap_skips_billing() {
// A free team: in good standing, no subscription linked.
team_repo.team_payment_status = true;
team_repo.team_subscription_id = None;
- team_repo.seat_count = FREE_TEAM_MAX_MEMBERS - 1;
+ team_repo.seat_count = FORMER_FREE_MEMBER_LIMIT - 1;
let invitation_persistence_calls = team_repo.invite_users_to_team_calls.clone();
@@ -5933,7 +5959,7 @@ async fn invite_users_to_team_free_team_under_cap_skips_billing() {
}
#[tokio::test]
-async fn invite_users_to_team_free_team_enforces_member_cap() {
+async fn invite_users_to_team_free_team_allows_invites_past_former_limit() {
let team_id = uuid::Uuid::from_u128(7010);
let invite_id = uuid::Uuid::from_u128(7011);
let invited_by = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
@@ -5945,13 +5971,16 @@ async fn invite_users_to_team_free_team_enforces_member_cap() {
);
team_repo.team_payment_status = true;
team_repo.team_subscription_id = None;
- team_repo.seat_count = FREE_TEAM_MAX_MEMBERS;
+ team_repo.seat_count = FORMER_FREE_MEMBER_LIMIT;
let invitation_persistence_calls = team_repo.invite_users_to_team_calls.clone();
+ let customer_repo = MockCustomerRepository::default();
+ let increment_calls = customer_repo.increment_calls.clone();
+ let convert_calls = customer_repo.convert_calls.clone();
let service = TeamServiceImpl::new(
team_repo,
- MockCustomerRepository::default(),
+ customer_repo,
RecordingChannelService::default(),
MockUserRolesAndPermissionsService::default(),
Arc::new(MockNotificationIngress::new(HashSet::new())),
@@ -5967,13 +5996,15 @@ async fn invite_users_to_team_free_team_enforces_member_cap() {
let invites = non_empty::NonEmpty::new(invite_emails.as_slice()).unwrap();
let receipt = test_team_receipt::<MemberTeamRole>(team_id, &invited_by);
- let result = service.invite_users_to_team(receipt, invites).await;
+ let result = service
+ .invite_users_to_team(receipt, invites)
+ .await
+ .unwrap();
- assert!(matches!(
- result,
- Err(InviteUsersToTeamError::NotEnoughOpenSeats)
- ));
- assert_eq!(*invitation_persistence_calls.lock().unwrap(), 0);
+ assert_eq!(result.len(), 1);
+ assert_eq!(*invitation_persistence_calls.lock().unwrap(), 1);
+ assert!(increment_calls.lock().unwrap().is_empty());
+ assert!(convert_calls.lock().unwrap().is_empty());
}
#[tokio::test]
@@ -5986,7 +6017,7 @@ async fn join_team_free_team_skips_billing_and_premium_roles() {
team_repo.team_payment_status = true;
team_repo.team_subscription_id = None;
// Seat count already includes the newly accepted member.
- team_repo.seat_count = FREE_TEAM_MAX_MEMBERS;
+ team_repo.seat_count = FORMER_FREE_MEMBER_LIMIT;
team_repo.accepted_invite = Some(make_accepted_invite(team_id, invite_id, &user_id));
let rollback_accept_calls = team_repo.rollback_accept_calls.clone();
@@ -6022,7 +6053,7 @@ async fn join_team_free_team_skips_billing_and_premium_roles() {
}
#[tokio::test]
-async fn join_team_free_team_over_cap_rolls_back() {
+async fn join_team_free_team_accepts_sixth_member_without_billing_or_premium_roles() {
let team_id = uuid::Uuid::from_u128(7030);
let invite_id = uuid::Uuid::from_u128(7031);
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
@@ -6030,7 +6061,7 @@ async fn join_team_free_team_over_cap_rolls_back() {
let mut team_repo = MockTeamRepository::new(Vec::new(), "Free Team", mark_sent_calls);
team_repo.team_payment_status = true;
team_repo.team_subscription_id = None;
- team_repo.seat_count = FREE_TEAM_MAX_MEMBERS + 1;
+ team_repo.seat_count = FORMER_FREE_MEMBER_LIMIT + 1;
team_repo.accepted_invite = Some(make_accepted_invite(team_id, invite_id, &user_id));
let rollback_accept_calls = team_repo.rollback_accept_calls.clone();
@@ -6049,17 +6080,20 @@ async fn join_team_free_team_over_cap_rolls_back() {
NoOpTeamCrmSettingsRepository,
);
- let result = service.join_team(&invite_id, &user_id).await;
+ let member = service.join_team(&invite_id, &user_id).await.unwrap();
- assert!(matches!(result, Err(JoinTeamError::FreeTeamLimitReached)));
- assert_eq!(*rollback_accept_calls.lock().unwrap(), 1);
+ assert_eq!(member.team_id, team_id);
+ assert_eq!(*rollback_accept_calls.lock().unwrap(), 0);
assert!(increment_calls.lock().unwrap().is_empty());
assert!(roles_service.upsert_calls.lock().unwrap().is_empty());
- assert!(channels_repo.auto_join_calls.lock().unwrap().is_empty());
+ assert_eq!(
+ *channels_repo.auto_join_calls.lock().unwrap(),
+ vec![(team_id, user_id.as_ref().to_string())]
+ );
}
#[tokio::test]
-async fn try_join_team_by_domain_free_team_at_cap_skips() {
+async fn try_join_team_by_domain_free_team_adds_sixth_member_without_billing_or_premium_roles() {
let team_id = uuid::Uuid::from_u128(7040);
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
let mark_sent_calls = Arc::new(Mutex::new(Vec::new()));
@@ -6072,7 +6106,7 @@ async fn try_join_team_by_domain_free_team_at_cap_skips() {
team_repo.team_id_for_domain = Some(team_id);
team_repo.team_payment_status = true;
team_repo.team_subscription_id = None;
- team_repo.seat_count = FREE_TEAM_MAX_MEMBERS + 1;
+ team_repo.seat_count = FORMER_FREE_MEMBER_LIMIT + 1;
team_repo.add_user_to_team_result = Some(member.clone());
team_repo.removed_member = Some(member);
let add_user_calls = team_repo.add_user_to_team_calls.clone();
@@ -6081,24 +6115,38 @@ async fn try_join_team_by_domain_free_team_at_cap_skips() {
let customer_repo = MockCustomerRepository::default();
let increment_calls = customer_repo.increment_calls.clone();
let roles_service = MockUserRolesAndPermissionsService::default();
+ let channels = RecordingChannelService::default();
+ let event_broker = RecordingEventBroker::default();
let service = TeamServiceImpl::new(
team_repo,
customer_repo,
- RecordingChannelService::default(),
+ channels.clone(),
roles_service.clone(),
Arc::new(MockNotificationIngress::new(HashSet::new())),
NoOpCrmEnqueuer,
NoOpTeamCrmSettingsRepository,
- );
+ )
+ .with_event_broker(event_broker.clone());
let result = service.try_join_team_by_domain(&user_id).await.unwrap();
- assert!(result.is_none());
+ assert_eq!(result.unwrap().team_id, team_id);
assert_eq!(*add_user_calls.lock().unwrap(), 1);
- assert_eq!(*remove_user_calls.lock().unwrap(), 1);
+ assert_eq!(*remove_user_calls.lock().unwrap(), 0);
assert!(increment_calls.lock().unwrap().is_empty());
assert!(roles_service.upsert_calls.lock().unwrap().is_empty());
+ assert_eq!(
+ *channels.auto_join_calls.lock().unwrap(),
+ vec![(team_id, user_id.as_ref().to_string())]
+ );
+ let events = event_broker.events();
+ assert_eq!(events.len(), 1);
+ assert_eq!(events[0].envelope["event_type"], "team.member_joined");
+ assert_eq!(
+ events[0].envelope["metadata"]["join_method"]["type"],
+ "domain_auto_join"
+ );
}
#[tokio::test]
diff --git a/crates/teams/src/inbound/axum_router.rs b/crates/teams/src/inbound/axum_router.rs
index 012a77232e..535ae1bb88 100644
--- a/crates/teams/src/inbound/axum_router.rs
+++ b/crates/teams/src/inbound/axum_router.rs
@@ -258,13 +258,6 @@ impl IntoResponse for InviteUsersToTeamError {
message: "only team admins may invite users to this team".into(),
}),
),
- InviteUsersToTeamError::NotEnoughOpenSeats => (
- StatusCode::BAD_REQUEST,
- Json(ErrorResponse {
- message: "free team member limit reached; upgrade to invite more members"
- .into(),
- }),
- ),
InviteUsersToTeamError::CustomerError(_) => (
StatusCode::INTERNAL_SERVER_ERROR,
Json(ErrorResponse {
@@ -291,13 +284,6 @@ impl IntoResponse for JoinTeamError {
message: "internal server error".into(),
}),
),
- JoinTeamError::FreeTeamLimitReached => (
- StatusCode::FORBIDDEN,
- Json(ErrorResponse {
- message: "team is at the free member limit - upgrade to add more members"
- .into(),
- }),
- ),
_ => (
StatusCode::INTERNAL_SERVER_ERROR,
Json(ErrorResponse {
diff --git a/crates/teams/src/inbound/axum_router/create_team.rs b/crates/teams/src/inbound/axum_router/create_team.rs
index 3c4c634f53..3359ba2dbd 100644
--- a/crates/teams/src/inbound/axum_router/create_team.rs
+++ b/crates/teams/src/inbound/axum_router/create_team.rs
@@ -35,8 +35,8 @@ pub async fn handler<T: TeamService, Eas: EntityAccessService, Auth: MacroAuthor
Json(req): Json<CreateTeamRequest>,
) -> Result<Json<Team>, CreateTeamError> {
let user = &user.authorization.user;
- // Teams are free up to FREE_TEAM_MAX_MEMBERS members - a subscription is
- // linked when the owner has one, but is no longer required to create.
+ // Team creation and membership do not require a subscription. Link the
+ // owner's existing subscription when present for paid billing/entitlements.
let subscription_id = state
.service
.is_user_premium(&user.macro_user_id)
diff --git a/crates/teams/src/inbound/axum_router/test.rs b/crates/teams/src/inbound/axum_router/test.rs
index b7eda7426b..63f746c20e 100644
--- a/crates/teams/src/inbound/axum_router/test.rs
+++ b/crates/teams/src/inbound/axum_router/test.rs
@@ -124,15 +124,15 @@ async fn invite_to_team_validation_error_response_is_preserved() {
}
#[tokio::test]
-async fn invite_to_free_team_at_capacity_returns_bad_request() {
+async fn invite_to_team_preserves_admin_only_invite_restriction() {
let error =
- InviteToTeamError::InviteUsersToTeamError(InviteUsersToTeamError::NotEnoughOpenSeats);
+ InviteToTeamError::InviteUsersToTeamError(InviteUsersToTeamError::NonAdminInvitesDisabled);
let (status, body_text, _) = response_parts(error).await;
- assert_eq!(status, StatusCode::BAD_REQUEST);
+ assert_eq!(status, StatusCode::FORBIDDEN);
assert_eq!(
body_text,
- r#"{"message":"free team member limit reached; upgrade to invite more members"}"#
+ r#"{"message":"only team admins may invite users to this team"}"#
);
}
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index 3bb287936b..19e7ffa470 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -732,6 +732,24 @@ and prevent dismissal; canceling leaves the underlying data unchanged.
## Settings — `/app/settings/<section>`
+### Team membership
+
+Team membership has no size cap, including free teams. Invitations and domain
+auto-join must keep working beyond five members and the former stage-plan limits.
+Free-team joins do not create a paid subscription, bill a seat, or grant premium
+roles. Teams with an existing paid subscription retain their per-seat billing;
+enterprise teams retain their billing bypass.
+
+Under **Team**, owners/admins can turn **Auto-join on domain** off and can restrict
+invitations to admins with **Members can invite**. These controls still apply.
+To verify the membership flow, use a local free team with five members: invite
+and accept a sixth member, then sign up another user on its enabled auto-join
+domain. Both should appear in the team's member list and configured auto-join
+channels without an upgrade prompt. Repeat with auto-join disabled to verify a
+same-domain signup is not added automatically.
+
+### Navigation
+
On phones, **More views → Settings** opens an inset glass sheet over the current
page. The main page has a profile shortcut and grouped Account, Preferences,
Workspace, and enabled agent/admin sections. Tap a row to open that settings