Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Fix Codex review findings on the settings ledger (#1277)

Goldflagfcbaf461a63f
diff --git a/client/messages/en.json b/client/messages/en.json
index d557a317c..981186a11 100644
--- a/client/messages/en.json
+++ b/client/messages/en.json
@@ -1642,7 +1642,6 @@
"lYB8jy": "{count} users",
"lbr3Lq": "Copy link",
"lg/l37": "Session %",
- "lgv6Qm": "After that this organization has no plan, and its sites stop collecting new events. Data already collected is kept.",
"lmjFSA": "Select Google Search Console Property",
"lnIbba": "IP address tracking disabled",
"lnaWo/": "Region",
@@ -2058,6 +2057,7 @@
"yiPdvO": "Takes effect when the trial ends.",
"yl0JSO": "Changing these notes does not change assignment or tracking.",
"ym0FiC": "Upgrade your plan to continue collecting analytics.",
+ "ymAtqC": "After that, unless the organization has another plan such as an AppSumo license, sites added since {cutoff} stop collecting new events and older sites drop to {limit} events a month. Data already collected is kept.",
"ytceSa": "No goal connected",
"yunf47": "Session Duration",
"yxDujp": "Add trait",
diff --git a/client/src/api/admin/endpoints/auth.ts b/client/src/api/admin/endpoints/auth.ts
index d56ab58fa..65e3beabf 100644
--- a/client/src/api/admin/endpoints/auth.ts
+++ b/client/src/api/admin/endpoints/auth.ts
@@ -18,6 +18,8 @@ export type GetOrganizationMembersResponse = {
siteIds: number[];
/** The role all the member's site grants carry; null when they carry none (their organization role applies) or differ. */
siteRole: SiteGrantRole | null;
+ /** Each direct grant with its own role (null: the member's organization role applies on that site). */
+ siteGrants?: { siteId: number; role: SiteGrantRole | null }[];
};
teams: {
id: string;
diff --git a/client/src/app/settings/components/siteAccess.test.ts b/client/src/app/settings/components/siteAccess.test.ts
index 905a96650..bda5c788d 100644
--- a/client/src/app/settings/components/siteAccess.test.ts
+++ b/client/src/app/settings/components/siteAccess.test.ts
@@ -94,6 +94,19 @@ describe("accessBySite", () => {
expect(scoped(access, 1)).toEqual([]);
});
+ it("reads each direct grant's own role when a member's grants carry different roles", () => {
+ const sam = member("sam", "viewer", { siteIds: [1, 2] });
+ // The members endpoint reports siteRole null when grants differ, and lists each grant separately.
+ sam.siteAccess.siteGrants = [
+ { siteId: 1, role: "editor" },
+ { siteId: 2, role: "member" },
+ ];
+ const access = accessBySite(sites, [sam], []);
+
+ expect(scoped(access, 1)).toEqual([{ userId: "sam", role: "editor", sources: [{ type: "direct" }] }]);
+ expect(scoped(access, 2)).toEqual([{ userId: "sam", role: "member", sources: [{ type: "direct" }] }]);
+ });
+
it("ignores direct grants left on a member who is no longer restricted", () => {
const unrestricted = {
...member("sam", "viewer"),
diff --git a/client/src/app/settings/components/siteAccess.ts b/client/src/app/settings/components/siteAccess.ts
index 52c28c783..f40fcc866 100644
--- a/client/src/app/settings/components/siteAccess.ts
+++ b/client/src/app/settings/components/siteAccess.ts
@@ -90,7 +90,10 @@ export function accessBySite<T extends AccessTeam, M extends AccessMember>(
const grants: { source: AccessSource; role: string | null }[] = [];
// Direct grants only count while the member is restricted to specific sites, as on the server.
if (member.siteAccess.hasRestrictedSiteAccess && member.siteAccess.siteIds.includes(site.siteId)) {
- grants.push({ source: { type: "direct" }, role: member.siteAccess.siteRole });
+ // siteRole is only the role all of a member's grants share (null when they differ), so read this
+ // site's own grant when the members endpoint lists them.
+ const grant = member.siteAccess.siteGrants?.find(siteGrant => siteGrant.siteId === site.siteId);
+ grants.push({ source: { type: "direct" }, role: grant ? grant.role : member.siteAccess.siteRole });
}
for (const team of siteTeams) {
if (team.members.some(teamMember => teamMember.userId === member.userId)) {
diff --git a/client/src/app/settings/organization/components/Invitations.test.tsx b/client/src/app/settings/organization/components/Invitations.test.tsx
index a23a6b88d..be5bfa634 100644
--- a/client/src/app/settings/organization/components/Invitations.test.tsx
+++ b/client/src/app/settings/organization/components/Invitations.test.tsx
@@ -173,6 +173,41 @@ describe("InvitationRow", () => {
expect(mocks.refetch).toHaveBeenCalledTimes(1);
});
+ it("recreates an expired invitation with its team and site role, then cancels the expired one", async () => {
+ const expired = {
+ ...invitation,
+ expiresAt: new Date("2020-01-01T00:00:00.000Z"),
+ teamId: "team-1,team-2",
+ hasRestrictedSiteAccess: true,
+ siteIds: [3, 4],
+ siteRole: "editor",
+ } as Invitation;
+ renderRow({ invitation: expired });
+ fireEvent.click(screen.getByRole("button", { name: "Resend invitation to [email protected]" }));
+
+ await waitFor(() => expect(mocks.toastSuccess).toHaveBeenCalledWith("Invitation sent to [email protected]"));
+ expect(mocks.inviteMember).toHaveBeenCalledWith({
+ email: "[email protected]",
+ role: "member",
+ organizationId: "org-1",
+ hasRestrictedSiteAccess: true,
+ siteIds: [3, 4],
+ siteRole: "editor",
+ teamId: ["team-1", "team-2"],
+ resend: true,
+ });
+ expect(mocks.cancelInvitation).toHaveBeenCalledWith({ invitationId: "inv-1" });
+ expect(mocks.refetch).toHaveBeenCalledTimes(1);
+ });
+
+ it("leaves an unexpired invitation in place when resending it", async () => {
+ renderRow();
+ fireEvent.click(screen.getByRole("button", { name: "Resend invitation to [email protected]" }));
+
+ await waitFor(() => expect(mocks.toastSuccess).toHaveBeenCalled());
+ expect(mocks.cancelInvitation).not.toHaveBeenCalled();
+ });
+
it("reports a failed resend instead of claiming success", async () => {
mocks.inviteMember.mockResolvedValue({ data: null, error: { message: "Member limit reached" } });
renderRow();
diff --git a/client/src/app/settings/organization/components/Invitations.tsx b/client/src/app/settings/organization/components/Invitations.tsx
index a61497e18..b5aca23ce 100644
--- a/client/src/app/settings/organization/components/Invitations.tsx
+++ b/client/src/app/settings/organization/components/Invitations.tsx
@@ -107,21 +107,29 @@ function ResendInvitationButton({ invitation, onResent }: { invitation: Invitati
const handleResend = async () => {
setIsResending(true);
try {
- // better-auth emails the existing invitation again with a fresh expiry; its role, sites and team
- // stay as they were (the site fields are required by the client types, and ignored on a resend).
- // It reports failures in the result rather than throwing.
+ // better-auth only finds unexpired invitations to resend; for an expired one it creates a new
+ // invitation from the fields sent here. So send every field the original carries, and retire the
+ // expired row once its replacement exists. It reports failures in the result rather than throwing.
+ const isExpired = new Date(invitation.expiresAt) < new Date();
+ const teamIds = invitation.teamId?.split(",").filter(Boolean) ?? [];
+ const hasRestrictedSiteAccess = invitation.hasRestrictedSiteAccess ?? false;
const { error } = await authClient.organization.inviteMember({
email: invitation.email,
// better-auth's client types only know its default roles; the server's access control defines ours.
role: invitation.role as "owner" | "admin" | "member",
organizationId: invitation.organizationId,
- hasRestrictedSiteAccess: invitation.hasRestrictedSiteAccess ?? false,
+ hasRestrictedSiteAccess,
siteIds: invitation.siteIds ?? [],
+ ...(hasRestrictedSiteAccess && invitation.siteRole ? { siteRole: invitation.siteRole } : {}),
+ ...(teamIds.length > 0 ? { teamId: teamIds.length === 1 ? teamIds[0] : teamIds } : {}),
resend: true,
});
if (error) {
throw new Error(error.message || t("Failed to resend invitation"));
}
+ if (isExpired) {
+ await authClient.organization.cancelInvitation({ invitationId: invitation.id });
+ }
toast.success(t("Invitation sent to {email}", { email: invitation.email }));
onResent();
} catch (error) {
diff --git a/client/src/app/settings/organization/components/personAccess.test.ts b/client/src/app/settings/organization/components/personAccess.test.ts
index 88db13474..4b91f0c67 100644
--- a/client/src/app/settings/organization/components/personAccess.test.ts
+++ b/client/src/app/settings/organization/components/personAccess.test.ts
@@ -99,6 +99,25 @@ describe("accessForPeople", () => {
});
});
+ it("puts an invitation to several teams in each of them", () => {
+ // better-auth stores the team ids of a multi-team invitation comma-separated.
+ const invitation = {
+ id: "inv-2",
+ email: "[email protected]",
+ role: "viewer",
+ teamId: "growth,platform",
+ hasRestrictedSiteAccess: false,
+ siteIds: [],
+ } as unknown as Parameters<typeof accessForPeople>[2][number];
+ const teams = [team("growth", [], [1]), team("platform", [], [2]), team("docs", [], [3, 4])];
+ const access = accessForPeople(sites, [], [invitation], teams);
+ expect(access.get(invitationAccessKey(invitation))).toMatchObject({ reached: 2, total: 4 });
+ expect(access.get(invitationAccessKey(invitation))?.sources).toEqual([
+ { type: "team", teamId: "growth", teamName: "growth" },
+ { type: "team", teamId: "platform", teamName: "platform" },
+ ]);
+ });
+
it("keeps an invitation restricted to specific sites to those sites", () => {
const invitation = {
id: "inv-2",
diff --git a/client/src/app/settings/organization/components/personAccess.ts b/client/src/app/settings/organization/components/personAccess.ts
index 41044bfce..224077573 100644
--- a/client/src/app/settings/organization/components/personAccess.ts
+++ b/client/src/app/settings/organization/components/personAccess.ts
@@ -119,7 +119,8 @@ export function accessForPeople(
members: [
...team.members,
...invitations
- .filter(invitation => invitation.teamId === team.id)
+ // better-auth stores an invitation to several teams as comma-separated ids.
+ .filter(invitation => invitation.teamId?.split(",").includes(team.id))
.map(invitation => ({ userId: invitationAccessKey(invitation), userName: null, userEmail: invitation.email })),
],
}));
diff --git a/client/src/components/subscription/PaidPlain/PaidPlan.tsx b/client/src/components/subscription/PaidPlain/PaidPlan.tsx
index df06c9341..583b2bcda 100644
--- a/client/src/components/subscription/PaidPlain/PaidPlan.tsx
+++ b/client/src/components/subscription/PaidPlain/PaidPlan.tsx
@@ -128,8 +128,16 @@ export function PaidPlan() {
};
const getCancelConsequence = () => {
+ // Without another plan the organization drops to the legacy free tier, which only sites created
+ // before the free plan closed still get (FREE_PLAN_CUTOFF_DATE and DEFAULT_EVENT_LIMIT on the server).
const after = t(
- "After that this organization has no plan, and its sites stop collecting new events. Data already collected is kept."
+ "After that, unless the organization has another plan such as an AppSumo license, sites added since {cutoff} stop collecting new events and older sites drop to {limit} events a month. Data already collected is kept.",
+ {
+ cutoff: new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeZone: "UTC" }).format(
+ new Date("2026-02-13T00:00:00Z")
+ ),
+ limit: (3000).toLocaleString(locale),
+ }
);
if (!periodEnd) return after;
if (activeSubscription.cancelAtPeriodEnd) {
diff --git a/server/src/api/user/listOrganizationMembers.ts b/server/src/api/user/listOrganizationMembers.ts
index 9a8a197ec..b20bac5e1 100644
--- a/server/src/api/user/listOrganizationMembers.ts
+++ b/server/src/api/user/listOrganizationMembers.ts
@@ -63,11 +63,15 @@ export async function listOrganizationMembers(
// Create maps for quick lookup
const siteIdsMap = new Map<string, number[]>();
+ const siteGrantsMap = new Map<string, { siteId: number; role: string | null }[]>();
const siteRolesMap = new Map<string, Set<string | null>>();
for (const record of siteAccessRecords) {
const existing = siteIdsMap.get(record.memberId) || [];
existing.push(record.siteId);
siteIdsMap.set(record.memberId, existing);
+ const grants = siteGrantsMap.get(record.memberId) || [];
+ grants.push({ siteId: record.siteId, role: record.role });
+ siteGrantsMap.set(record.memberId, grants);
const roles = siteRolesMap.get(record.memberId) || new Set();
roles.add(record.role);
siteRolesMap.set(record.memberId, roles);
@@ -104,6 +108,8 @@ export async function listOrganizationMembers(
hasRestrictedSiteAccess: m.hasRestrictedSiteAccess,
siteIds: siteIdsMap.get(m.id) || [],
siteRole: sharedSiteRole(m.id),
+ // Each grant's own role, for callers that must resolve a member's role per site.
+ siteGrants: siteGrantsMap.get(m.id) || [],
},
teams: teamsMap.get(m.userId) || [],
})),