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.

feat(settings): resend pending team invites (#8820)

Jacob Beckermana22df076e846
diff --git a/.sqlx/query-587ab2cbf540d6f98236ca8cc3c098a0efa439c0ccefa93c46971a0f2fe7efcf.json b/.sqlx/query-d8dfd71f5f0d103ff143998cb13f4ab6360b2e3b937aef86365ca9fa4a2385df.json
similarity index 72%
rename from .sqlx/query-587ab2cbf540d6f98236ca8cc3c098a0efa439c0ccefa93c46971a0f2fe7efcf.json
rename to .sqlx/query-d8dfd71f5f0d103ff143998cb13f4ab6360b2e3b937aef86365ca9fa4a2385df.json
index 6fa7775825..656d1b2ad8 100644
--- a/.sqlx/query-587ab2cbf540d6f98236ca8cc3c098a0efa439c0ccefa93c46971a0f2fe7efcf.json
+++ b/.sqlx/query-d8dfd71f5f0d103ff143998cb13f4ab6360b2e3b937aef86365ca9fa4a2385df.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n SELECT id, team_id, email\n FROM team_invite\n WHERE team_id = $1\n AND email = ANY($2::text[])\n AND last_sent_at < NOW() - INTERVAL '5 minutes'\n ",
+ "query": "\n SELECT id, team_id, email\n FROM team_invite\n WHERE team_id = $1\n AND email = ANY($2::text[])\n AND last_sent_at <= NOW() - make_interval(secs => $3)\n ",
"describe": {
"columns": [
{
@@ -22,7 +22,8 @@
"parameters": {
"Left": [
"Uuid",
- "TextArray"
+ "TextArray",
+ "Float8"
]
},
"nullable": [
@@ -31,5 +32,5 @@
false
]
},
- "hash": "587ab2cbf540d6f98236ca8cc3c098a0efa439c0ccefa93c46971a0f2fe7efcf"
+ "hash": "d8dfd71f5f0d103ff143998cb13f4ab6360b2e3b937aef86365ca9fa4a2385df"
}
diff --git a/apps/web/src/features/settings/TeamMembers.tsx b/apps/web/src/features/settings/TeamMembers.tsx
index cb1f15664b..70b22ea705 100644
--- a/apps/web/src/features/settings/TeamMembers.tsx
+++ b/apps/web/src/features/settings/TeamMembers.tsx
@@ -7,20 +7,16 @@ import { useUserId } from '@core/context/user';
import { getDisplayName, macroIdToEmail, tryMacroId } from '@core/user';
import { debouncedDependent } from '@core/util/debounce';
import { fuzzyFilter } from '@core/util/fuzzy';
-import { getWebOrigin } from '@core/util/webOrigin';
-import { formatRelativeTimestamp } from '@entity';
import type { CollectionNode } from '@kobalte/core';
import { Select } from '@kobalte/core/select';
import CaretDownIcon from '@phosphor/caret-down.svg';
import CheckIcon from '@phosphor/check.svg';
-import EnvelopeIcon from '@phosphor/envelope.svg';
-import LinkIcon from '@phosphor/link.svg';
import PlusIcon from '@phosphor/plus.svg';
import TrashIcon from '@phosphor/trash.svg';
-import XIcon from '@phosphor/x.svg';
import { useAiBillingSummaryQuery } from '@queries/auth';
import {
useDeleteTeamInviteMutation,
+ useResendTeamInviteMutation,
useTeamInvitesQuery,
} from '@queries/team/invites';
import {
@@ -38,14 +34,8 @@ import type { TeamInviteDetails } from '@service-auth/generated/schemas/teamInvi
import type { TeamMember } from '@service-auth/generated/schemas/teamMember';
import { TeamRole } from '@service-auth/generated/schemas/teamRole';
import { Button, ConfirmDialog, ToggleSwitch, Tooltip } from '@ui';
-import {
- createMemo,
- createSignal,
- For,
- mapArray,
- onCleanup,
- Show,
-} from 'solid-js';
+import { createMemo, createSignal, For, mapArray, Show } from 'solid-js';
+import { TeamInviteRow } from './components/team-invite-row';
import { TeamSeatPlanSelect } from './components/team-seat-plan-select';
import {
SettingsCard,
@@ -54,7 +44,11 @@ import {
SettingsSection,
} from './primitives';
import { InviteToTeamDialog, useTeamViewer } from './Team';
-import { canInviteToTeam, canRemoveTeamMember } from './teamMemberPermissions';
+import {
+ canInviteToTeam,
+ canRemoveTeamMember,
+ isTeamAdminOrOwner,
+} from './teamMemberPermissions';
const roleOrder: Record<string, number> = {
[TeamRole.owner]: 0,
@@ -240,72 +234,6 @@ function MemberName(props: { memberId: string }) {
return <span class="font-medium">{displayName()}</span>;
}
-function InviteRow(props: {
- invite: TeamInviteDetails;
- canChange: boolean;
- onCancel: () => void;
-}) {
- const [copied, setCopied] = createSignal(false);
- let copyResetTimeout: ReturnType<typeof setTimeout> | undefined;
- onCleanup(() => clearTimeout(copyResetTimeout));
- const handleCopyLink = async () => {
- try {
- await navigator.clipboard.writeText(
- `${getWebOrigin()}/app/team-invite?id=${props.invite.id}`
- );
- } catch (err) {
- console.error('Failed to copy to clipboard', err);
- return;
- }
- setCopied(true);
- clearTimeout(copyResetTimeout);
- copyResetTimeout = setTimeout(() => setCopied(false), 2000);
- };
-
- return (
- <div class="flex items-center justify-between gap-2 px-4 py-4">
- <div class="flex items-center gap-3 min-w-0 flex-1">
- <div class="size-8 rounded-full bg-accent/10 flex items-center justify-center shrink-0">
- <EnvelopeIcon class="size-4 text-accent" />
- </div>
- <div class="min-w-0 flex-1">
- <div class="text-sm text-ink truncate">{props.invite.email}</div>
- <div class="text-xs text-ink-muted">
- Invited as {props.invite.team_role} ·{' '}
- {formatRelativeTimestamp(props.invite.created_at, {
- condensed: true,
- })}
- </div>
- </div>
- </div>
- <Show when={props.canChange}>
- <Tooltip label={copied() ? 'Copied' : 'Copy invite link'}>
- <Button
- variant="ghost"
- size="sm"
- class="shrink-0"
- onClick={handleCopyLink}
- >
- <Show when={copied()} fallback={<LinkIcon class="size-4" />}>
- <CheckIcon class="size-4" />
- </Show>
- </Button>
- </Tooltip>
- <Tooltip label="Cancel invite">
- <Button
- variant="ghost"
- size="sm"
- class="shrink-0"
- onClick={props.onCancel}
- >
- <XIcon class="size-4" />
- </Button>
- </Tooltip>
- </Show>
- </div>
- );
-}
-
/** Team › Members: the roster, roles and seats, and how people join. */
export function TeamMembers(props: { team: TeamSummary }) {
const userId = useUserId();
@@ -319,6 +247,7 @@ export function TeamMembers(props: { team: TeamSummary }) {
const invitesQuery = useTeamInvitesQuery(() => props.team.id);
const deleteInviteMutation = useDeleteTeamInviteMutation();
+ const resendInviteMutation = useResendTeamInviteMutation();
const removeUserMutation = useRemoveUserFromTeamMutation();
const patchTeamMutation = usePatchTeamMutation();
const toggleAutoJoinMutation = useToggleAutoJoinDomainMutation();
@@ -575,7 +504,8 @@ export function TeamMembers(props: { team: TeamSummary }) {
<Show
when={
- (isOwner() || allowNonAdminInvites()) &&
+ // Listing and cancelling invites are admin-only on the server.
+ isTeamAdminOrOwner(currentUserRole()) &&
(invitesQuery.data?.invites?.length ?? 0) > 0
}
>
@@ -583,9 +513,19 @@ export function TeamMembers(props: { team: TeamSummary }) {
<SettingsCard>
<For each={invitesQuery.data?.invites ?? []}>
{(invite) => (
- <InviteRow
+ <TeamInviteRow
invite={invite}
- canChange={isOwner() || allowNonAdminInvites()}
+ canChange={isTeamAdminOrOwner(currentUserRole())}
+ resending={
+ resendInviteMutation.isPending &&
+ resendInviteMutation.variables?.email === invite.email
+ }
+ onResend={() =>
+ resendInviteMutation.mutate({
+ teamId: props.team.id,
+ email: invite.email,
+ })
+ }
onCancel={() => setShowCancelInviteModal(invite)}
/>
)}
diff --git a/apps/web/src/features/settings/components/team-invite-row.test.tsx b/apps/web/src/features/settings/components/team-invite-row.test.tsx
new file mode 100644
index 0000000000..1c4fd9eefc
--- /dev/null
+++ b/apps/web/src/features/settings/components/team-invite-row.test.tsx
@@ -0,0 +1,77 @@
+/**
+ * @vitest-environment jsdom
+ */
+
+import type { TeamInviteDetails } from '@service-auth/generated/schemas/teamInviteDetails';
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { TeamInviteRow } from './team-invite-row';
+
+vi.mock('@entity', () => ({
+ formatRelativeTimestamp: () => '1h',
+}));
+vi.mock('@core/util/webOrigin', () => ({
+ getWebOrigin: () => 'https://macro.com',
+}));
+
+const HOUR = 60 * 60 * 1000;
+
+function invite(lastSentHoursAgo: number): TeamInviteDetails {
+ const lastSent = new Date(Date.now() - lastSentHoursAgo * HOUR).toISOString();
+ return {
+ id: 'invite-1',
+ email: '[email protected]',
+ team_id: 'team-1',
+ team_role: 'member',
+ invited_by: 'macro|[email protected]',
+ created_at: lastSent,
+ last_sent_at: lastSent,
+ };
+}
+
+function renderRow(lastSentHoursAgo: number) {
+ const onResend = vi.fn();
+ render(() => (
+ <TeamInviteRow
+ invite={invite(lastSentHoursAgo)}
+ canChange
+ resending={false}
+ onResend={onResend}
+ onCancel={vi.fn()}
+ />
+ ));
+ return { onResend, resend: screen.getByLabelText('Resend invite') };
+}
+
+describe('TeamInviteRow', () => {
+ afterEach(cleanup);
+
+ it('resends an invite whose last email is over an hour old', () => {
+ const { onResend, resend } = renderRow(72);
+
+ fireEvent.click(resend);
+
+ expect(onResend).toHaveBeenCalledOnce();
+ });
+
+ it('keeps Resend off inside the email rate limit', () => {
+ const { onResend, resend } = renderRow(0.25);
+
+ expect((resend as HTMLButtonElement).disabled).toBe(true);
+ fireEvent.click(resend);
+ expect(onResend).not.toHaveBeenCalled();
+ });
+
+ it('shows when the invite was last sent', () => {
+ renderRow(0.25);
+
+ expect(screen.getByText(/Invited as member · sent 1h/)).toBeTruthy();
+ });
+
+ it('names every icon-only action', () => {
+ renderRow(72);
+
+ expect(screen.getByLabelText('Copy invite link')).toBeTruthy();
+ expect(screen.getByLabelText('Cancel invite')).toBeTruthy();
+ });
+});
diff --git a/apps/web/src/features/settings/components/team-invite-row.tsx b/apps/web/src/features/settings/components/team-invite-row.tsx
new file mode 100644
index 0000000000..406ba8b6a7
--- /dev/null
+++ b/apps/web/src/features/settings/components/team-invite-row.tsx
@@ -0,0 +1,102 @@
+import { getWebOrigin } from '@core/util/webOrigin';
+import { formatRelativeTimestamp } from '@entity';
+import CheckIcon from '@phosphor/check.svg';
+import EnvelopeIcon from '@phosphor/envelope.svg';
+import LinkIcon from '@phosphor/link.svg';
+import PaperPlaneTiltIcon from '@phosphor/paper-plane-tilt.svg';
+import XIcon from '@phosphor/x.svg';
+import type { TeamInviteDetails } from '@service-auth/generated/schemas/teamInviteDetails';
+import { Button, Tooltip } from '@ui';
+import { createSignal, onCleanup, Show } from 'solid-js';
+import { canResendInvite } from '../teamInviteResend';
+
+/** A pending team invite with its resend, copy-link, and cancel actions. */
+export function TeamInviteRow(props: {
+ invite: TeamInviteDetails;
+ canChange: boolean;
+ resending: boolean;
+ onResend: () => void;
+ onCancel: () => void;
+}) {
+ const canResend = () =>
+ canResendInvite(props.invite.last_sent_at, new Date());
+ const [copied, setCopied] = createSignal(false);
+ let copyResetTimeout: ReturnType<typeof setTimeout> | undefined;
+ onCleanup(() => clearTimeout(copyResetTimeout));
+ const handleCopyLink = async () => {
+ try {
+ await navigator.clipboard.writeText(
+ `${getWebOrigin()}/app/team-invite?id=${props.invite.id}`
+ );
+ } catch (err) {
+ console.error('Failed to copy to clipboard', err);
+ return;
+ }
+ setCopied(true);
+ clearTimeout(copyResetTimeout);
+ copyResetTimeout = setTimeout(() => setCopied(false), 2000);
+ };
+
+ return (
+ <div class="flex items-center justify-between gap-2 px-4 py-4">
+ <div class="flex items-center gap-3 min-w-0 flex-1">
+ <div class="size-8 rounded-full bg-accent/10 flex items-center justify-center shrink-0">
+ <EnvelopeIcon class="size-4 text-accent" />
+ </div>
+ <div class="min-w-0 flex-1">
+ <div class="text-sm text-ink truncate">{props.invite.email}</div>
+ <div class="text-xs text-ink-muted">
+ Invited as {props.invite.team_role} · sent{' '}
+ {formatRelativeTimestamp(props.invite.last_sent_at, {
+ condensed: true,
+ })}
+ </div>
+ </div>
+ </div>
+ <Show when={props.canChange}>
+ <Tooltip
+ label={
+ canResend()
+ ? 'Resend invite'
+ : 'You can resend an hour after the last email'
+ }
+ >
+ <Button
+ variant="ghost"
+ size="sm"
+ class="shrink-0"
+ aria-label="Resend invite"
+ disabled={!canResend() || props.resending}
+ onClick={props.onResend}
+ >
+ <PaperPlaneTiltIcon class="size-4" />
+ </Button>
+ </Tooltip>
+ <Tooltip label={copied() ? 'Copied' : 'Copy invite link'}>
+ <Button
+ variant="ghost"
+ size="sm"
+ class="shrink-0"
+ aria-label="Copy invite link"
+ onClick={handleCopyLink}
+ >
+ <Show when={copied()} fallback={<LinkIcon class="size-4" />}>
+ <CheckIcon class="size-4" />
+ </Show>
+ </Button>
+ </Tooltip>
+ <Tooltip label="Cancel invite">
+ <Button
+ variant="ghost"
+ size="sm"
+ class="shrink-0"
+ aria-label="Cancel invite"
+ onClick={props.onCancel}
+ >
+ <XIcon class="size-4" />
+ </Button>
+ </Tooltip>
+ </Show>
+ </div>
+ );
+}
diff --git a/apps/web/src/features/settings/teamInviteResend.test.ts b/apps/web/src/features/settings/teamInviteResend.test.ts
new file mode 100644
index 0000000000..70bf7f2bd4
--- /dev/null
+++ b/apps/web/src/features/settings/teamInviteResend.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from 'vitest';
+import { canResendInvite, inviteResendAvailableAt } from './teamInviteResend';
+
+const lastSentAt = '2026-10-20T12:00:00.000Z';
+
+describe('canResendInvite', () => {
+ it('waits out the invite email rate limit', () => {
+ expect(canResendInvite(lastSentAt, new Date('2026-10-20T12:30:00Z'))).toBe(
+ false
+ );
+ expect(canResendInvite(lastSentAt, new Date('2026-10-20T12:59:59Z'))).toBe(
+ false
+ );
+ });
+
+ it('allows a resend an hour after the last email', () => {
+ expect(canResendInvite(lastSentAt, new Date('2026-10-20T13:00:00Z'))).toBe(
+ true
+ );
+ });
+});
+
+describe('inviteResendAvailableAt', () => {
+ it('is an hour after the last email', () => {
+ expect(inviteResendAvailableAt(lastSentAt).toISOString()).toBe(
+ '2026-10-20T13:00:00.000Z'
+ );
+ });
+});
diff --git a/apps/web/src/features/settings/teamInviteResend.ts b/apps/web/src/features/settings/teamInviteResend.ts
new file mode 100644
index 0000000000..be5fce1c95
--- /dev/null
+++ b/apps/web/src/features/settings/teamInviteResend.ts
@@ -0,0 +1,17 @@
+import { addMinutes } from 'date-fns';
+
+/**
+ * An invite's email is rate limited to one per this many minutes, so a
+ * resend any sooner would be dropped. Mirrors `invite_resend_interval` in the teams
+ * crate, which rejects earlier resends.
+ */
+const INVITE_RESEND_INTERVAL_MINUTES = 60;
+
+/** When an invite last emailed at `lastSentAt` may be emailed again. */
+export function inviteResendAvailableAt(lastSentAt: string): Date {
+ return addMinutes(new Date(lastSentAt), INVITE_RESEND_INTERVAL_MINUTES);
+}
+
+export function canResendInvite(lastSentAt: string, now: Date): boolean {
+ return now >= inviteResendAvailableAt(lastSentAt);
+}
diff --git a/apps/web/src/lib/queries/team/invites.ts b/apps/web/src/lib/queries/team/invites.ts
index 0fb91e7a2b..3667c65ff2 100644
--- a/apps/web/src/lib/queries/team/invites.ts
+++ b/apps/web/src/lib/queries/team/invites.ts
@@ -54,6 +54,29 @@ export function useInviteToTeamMutation(callbacks?: InviteToTeamCallbacks) {
}));
}
+type ResendTeamInviteArgs = { teamId: string; email: string };
+
+/** Emails a pending invite again; re-inviting its address resends it. */
+export function useResendTeamInviteMutation() {
+ return useMutation(() => ({
+ mutationFn: async ({ email }: ResendTeamInviteArgs) => {
+ await throwOnErr(() =>
+ authServiceClient.inviteToTeam({ invites: [{ email }] })
+ );
+ },
+
+ onSuccess: (_data: void, { teamId }: ResendTeamInviteArgs) => {
+ fireAndForget(invalidateTeamInvites(teamId), 'team-invitations');
+ toast.success('Invitation resent');
+ },
+
+ onError: (error: Error) => {
+ console.error('Failed to resend team invite', error);
+ toast.failure('Failed to resend invitation');
+ },
+ }));
+}
+
type DeleteTeamInviteArgs = { teamId: string; teamInviteId: string };
type DeleteTeamInviteContext = {
previousInvites: TeamInvitesResponse | undefined;
diff --git a/crates/invite_email/AGENTS.md b/crates/invite_email/AGENTS.md
index 9c25d7e099..d6f9ac489a 100644
--- a/crates/invite_email/AGENTS.md
+++ b/crates/invite_email/AGENTS.md
@@ -55,7 +55,10 @@ invites, and the colleague-joined email.
- `InviteToTeamMetadata.reminder` marks the reminder emails `teams` sends for
unanswered invites; it only prefixes the subject with "Reminder:". A
reminder shares the invite's rate-limit bucket (one email per invite per
- 2 days), so reminders must stay more than 2 days apart.
+ hour), so reminders must stay more than an hour apart. Manual resends wait
+ out the same window: `teams` reads it from
+ `InviteToTeamMetadata::rate_limit_config()` (`invite_resend_interval`), and
+ the web app's **Resend** mirrors it in `teamInviteResend.ts`.
- Metadata is queued and stored as JSON, and the notification service
publishes it in its OpenAPI spec. A new field needs `#[serde(default)]` so
payloads queued before a deploy still deserialize, and a regenerated web
diff --git a/crates/invite_email/src/lib.rs b/crates/invite_email/src/lib.rs
index c3308a2486..fb41a39420 100644
--- a/crates/invite_email/src/lib.rs
+++ b/crates/invite_email/src/lib.rs
@@ -376,10 +376,11 @@ impl NotificationExtEmail for InviteToTeamMetadata {
}
fn rate_limit_config() -> RateLimitConfig {
- const TWO_DAYS: u64 = 24 * 2;
+ // Long enough to stop repeat mail to one address, short enough that an
+ // inviter can resend when someone says the email never came.
RateLimitConfig {
max_count: 1,
- window: Duration::from_hours(TWO_DAYS),
+ window: Duration::from_hours(1),
}
}
diff --git a/crates/teams/src/domain/team_service.rs b/crates/teams/src/domain/team_service.rs
index 8ad5b86abf..4f09ac2e5a 100644
--- a/crates/teams/src/domain/team_service.rs
+++ b/crates/teams/src/domain/team_service.rs
@@ -63,6 +63,14 @@ use crate::domain::{
/// Most new invites a non-enterprise team may create in a rolling day.
const MAX_TEAM_INVITES_PER_DAY: usize = 50;
+/// How long after an invite's last email it may be sent again: the invite
+/// email's own rate-limit window, so a resend is never dropped by it.
+#[cfg(feature = "ports")]
+pub fn invite_resend_interval() -> std::time::Duration {
+ use notification::domain::models::NotificationExtEmail;
+ InviteToTeamMetadata::rate_limit_config().window
+}
+
/// The roles a member of a paying or enterprise team holds: the team
/// subscriber role plus the tier role of their seat's plan.
fn team_member_roles_to_add(plan: SeatPlan) -> Vec<RoleId> {
diff --git a/crates/teams/src/outbound/team_repo.rs b/crates/teams/src/outbound/team_repo.rs
index ca5d121e51..d039b76a7a 100644
--- a/crates/teams/src/outbound/team_repo.rs
+++ b/crates/teams/src/outbound/team_repo.rs
@@ -9,6 +9,7 @@ use crate::domain::{
},
owned_entity_cleanup::ClearedTeam,
team_repo::{TeamMembersService, TeamRepository},
+ team_service::invite_resend_interval,
};
use entity_access_db_utils::{EntityAccessSourceType, delete_source_grants, team_share};
use macro_user_id::{
@@ -437,17 +438,19 @@ impl TeamRepository for TeamRepositoryImpl {
.fetch_all(&mut *transaction)
.await?;
- // Also re-send existing invites whose rate limit window has passed
+ // Also re-send existing invites whose email rate limit has passed;
+ // sooner, the email would be dropped while `last_sent_at` moved on.
let resent_invites: Vec<(uuid::Uuid, uuid::Uuid, String)> = sqlx::query!(
r#"
SELECT id, team_id, email
FROM team_invite
WHERE team_id = $1
AND email = ANY($2::text[])
- AND last_sent_at < NOW() - INTERVAL '5 minutes'
+ AND last_sent_at <= NOW() - make_interval(secs => $3)
"#,
team_id,
&email_strings[..],
+ invite_resend_interval().as_secs_f64(),
)
.map(|r| (r.id, r.team_id, r.email))
.fetch_all(&mut *transaction)
diff --git a/crates/teams/src/outbound/team_repo/test.rs b/crates/teams/src/outbound/team_repo/test.rs
index 50f5f0244f..efe7787969 100644
--- a/crates/teams/src/outbound/team_repo/test.rs
+++ b/crates/teams/src/outbound/team_repo/test.rs
@@ -513,8 +513,8 @@ async fn test_get_new_invites_keeps_invites_scoped_to_team(
Ok(())
}
-/// Re-inviting an already-invited user within the 5-minute window should not
-/// return them (rate limited), so the result should be empty.
+/// Re-inviting an already-invited user inside the invite email's rate-limit
+/// window should not return them (rate limited), so the result should be empty.
#[sqlx::test(
migrator = "MACRO_DB_MIGRATIONS",
fixtures(path = "../../../fixtures", scripts("teams"))
@@ -538,8 +538,39 @@ async fn test_invite_existing_user_within_rate_limit(pool: Pool<Postgres>) -> an
Ok(())
}
-/// Re-inviting an already-invited user after the 5-minute window has passed
-/// should return them (re-sent).
+/// A resend minutes after the last email would be dropped by the email's
+/// rate limit, so the repository must not offer it for sending.
+#[sqlx::test(
+ migrator = "MACRO_DB_MIGRATIONS",
+ fixtures(path = "../../../fixtures", scripts("teams"))
+)]
+async fn test_invite_existing_user_inside_email_rate_limit(
+ pool: Pool<Postgres>,
+) -> anyhow::Result<()> {
+ let team_repo = TeamRepositoryImpl::new(pool.clone());
+ let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]")?;
+ let team_id = macro_uuid::string_to_uuid("11111111-1111-1111-1111-111111111111")?;
+
+ sqlx::query!(
+ r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '30 minutes' WHERE team_id = $1 AND email = '[email protected]'"#,
+ &team_id,
+ )
+ .execute(&pool)
+ .await?;
+
+ let invites = vec![Email::parse_from_str("[email protected]")?.lowercase()];
+ let invites = non_empty::NonEmpty::new(invites.as_slice())?;
+ let invited = team_repo
+ .invite_users_to_team(&team_id, &user_id, invites)
+ .await?;
+
+ assert!(invited.is_empty());
+
+ Ok(())
+}
+
+/// Re-inviting an already-invited user after the invite email's rate-limit
+/// window has passed should return them (re-sent).
#[sqlx::test(
migrator = "MACRO_DB_MIGRATIONS",
fixtures(path = "../../../fixtures", scripts("teams"))
@@ -549,9 +580,9 @@ async fn test_invite_existing_user_after_rate_limit(pool: Pool<Postgres>) -> any
let user_id = MacroUserIdStr::parse_from_str("macro|[email protected]")?;
let team_id = macro_uuid::string_to_uuid("11111111-1111-1111-1111-111111111111")?;
- // Push last_sent_at back 10 minutes so the rate limit window has passed
+ // Push last_sent_at back past the invite email's rate-limit window
sqlx::query!(
- r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '10 minutes' WHERE team_id = $1 AND email = '[email protected]'"#,
+ r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '3 days' WHERE team_id = $1 AND email = '[email protected]'"#,
&team_id,
)
.execute(&pool)
@@ -583,7 +614,7 @@ async fn test_invite_mix_new_and_existing(pool: Pool<Postgres>) -> anyhow::Resul
// Push existing invite past the rate limit window
sqlx::query!(
- r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '10 minutes' WHERE team_id = $1 AND email = '[email protected]'"#,
+ r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '3 days' WHERE team_id = $1 AND email = '[email protected]'"#,
&team_id,
)
.execute(&pool)
@@ -621,7 +652,7 @@ async fn test_reinvite_updates_last_sent_at(pool: Pool<Postgres>) -> anyhow::Res
// Push past rate limit
sqlx::query!(
- r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '10 minutes' WHERE team_id = $1 AND email = '[email protected]'"#,
+ r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '3 days' WHERE team_id = $1 AND email = '[email protected]'"#,
&team_id,
)
.execute(&pool)
@@ -663,7 +694,7 @@ async fn test_resend_without_mark_sent_stays_eligible(pool: Pool<Postgres>) -> a
// Push past rate limit
sqlx::query!(
- r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '10 minutes' WHERE team_id = $1 AND email = '[email protected]'"#,
+ r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '3 days' WHERE team_id = $1 AND email = '[email protected]'"#,
&team_id,
)
.execute(&pool)
@@ -702,7 +733,7 @@ async fn test_mark_invites_sent(pool: Pool<Postgres>) -> anyhow::Result<()> {
// Push last_sent_at back so it's past the rate limit
sqlx::query!(
- r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '10 minutes' WHERE id = $1"#,
+ r#"UPDATE team_invite SET last_sent_at = NOW() - INTERVAL '3 days' WHERE id = $1"#,
&invite_id,
)
.execute(&pool)
diff --git a/docs/agent-guide/settings.md b/docs/agent-guide/settings.md
index 05a38c27a5..c54eef1c69 100644
--- a/docs/agent-guide/settings.md
+++ b/docs/agent-guide/settings.md
@@ -154,6 +154,10 @@ grants a Pro seat (an enterprise team, or one with a subscription), otherwise
An unanswered invite gets up to two reminder emails, with subjects starting
**Reminder:**, 3 days after the last email and 4 days after that. Invites more
than 14 days old, already-members, and invites whose sender left the team get none.
+**Pending invites** on **Team → Members** lists each invite with when it was
+last sent, for owners and admins, who can **Resend**, copy the invite link,
+or cancel it. Resend unlocks an hour after the last email, the email's rate
+limit; re-inviting the address from **Invite** follows the same rule.
Under **Team → Members** (**Invite settings**), owners/admins can turn
**Auto-join on domain** off and can restrict invitations to admins with