Skip to content

Commit 686e50a

Browse files
committed
feat(platform-objects): Add Member on a team binds that team
Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016g7nYP9wdNx1GDa5XDr7Uy
1 parent 830a63a commit 686e50a

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// Add Member opened from a team carries that team.
4+
//
5+
// `sys_team_member.add_team_member` sits on the membership list's toolbar,
6+
// where no team is in hand, so its dialog asks for the team as well as the
7+
// user. The team-side copy on `sys_team` binds the team from the row it is
8+
// opened on (`recordIdParam: 'teamId'`), so the dialog asks for the user
9+
// alone. Both copies call the same endpoint behind the same gates; this file
10+
// pins that the two agree on everything except where the team comes from.
11+
import { describe, expect, it } from 'vitest';
12+
import { SysTeam } from './sys-team.object.js';
13+
import { SysTeamMember } from './sys-team-member.object.js';
14+
15+
interface ParamLike {
16+
name?: string;
17+
field?: string;
18+
objectOverride?: string;
19+
required?: boolean;
20+
defaultFromRow?: boolean;
21+
}
22+
23+
interface ActionLike {
24+
name?: string;
25+
type?: string;
26+
target?: string;
27+
recordIdParam?: string;
28+
locations?: string[];
29+
visible?: { source?: string };
30+
params?: ParamLike[];
31+
}
32+
33+
function action(object: { actions?: unknown[] }, name: string): ActionLike {
34+
const found = ((object.actions ?? []) as ActionLike[]).find((a) => a.name === name);
35+
expect(found, `${name} is declared`).toBeDefined();
36+
return found as ActionLike;
37+
}
38+
39+
describe('sys_team.add_team_member — Add Member opened from a team', () => {
40+
const fromTeam = action(SysTeam, 'add_team_member');
41+
const fromList = action(SysTeamMember, 'add_team_member');
42+
43+
it('is offered on the team row and the team record header', () => {
44+
expect(fromTeam.locations).toEqual(['list_item', 'record_header']);
45+
});
46+
47+
it('binds the team from the row it is opened on, as teamId', () => {
48+
expect(fromTeam.recordIdParam).toBe('teamId');
49+
// The team is not asked for: no dialog param submits teamId.
50+
expect((fromTeam.params ?? []).map((p) => p.name)).not.toContain('teamId');
51+
});
52+
53+
it('asks only for the user, through the membership row\'s sys_user lookup', () => {
54+
expect(fromTeam.params).toEqual([
55+
{ name: 'userId', field: 'user_id', objectOverride: 'sys_team_member', required: true },
56+
]);
57+
});
58+
59+
it('calls the same endpoint behind the same gate as the membership-list copy', () => {
60+
expect(fromTeam.type).toBe('api');
61+
expect(fromTeam.target).toBe('/api/v1/auth/organization/add-team-member');
62+
expect(fromTeam.target).toBe(fromList.target);
63+
expect(fromTeam.visible?.source).toBeDefined();
64+
expect(fromTeam.visible?.source).toBe(fromList.visible?.source);
65+
});
66+
67+
it('leaves the membership-list copy asking for the team, where none is in hand', () => {
68+
expect(fromList.locations).toEqual(['list_toolbar']);
69+
expect(fromList.recordIdParam).toBeUndefined();
70+
expect((fromList.params ?? []).map((p) => p.name)).toEqual(['teamId', 'userId']);
71+
});
72+
});

‎packages/platform-objects/src/identity/sys-team.object.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,31 @@ export const SysTeam = ObjectSchema.create({
7878
{ field: 'name', required: true, defaultFromRow: true },
7979
],
8080
},
81+
{
82+
// Better-auth: `organization/add-team-member { teamId, userId }` — the
83+
// team-side mirror of `sys_team_member.add_team_member`. That one sits on
84+
// the membership list's toolbar, where no team is in hand, so it asks for
85+
// one. Opened from a team, the record IS the team: its id rides as
86+
// `teamId` (the `sys_organization.invite_user` shape), and the dialog
87+
// asks only for the user.
88+
name: 'add_team_member',
89+
label: 'Add Member',
90+
icon: 'user-plus',
91+
locations: ['list_item', 'record_header'],
92+
type: 'api',
93+
target: '/api/v1/auth/organization/add-team-member',
94+
recordIdParam: 'teamId',
95+
// Same gates as the membership-list copy.
96+
requiresFeature: 'organization',
97+
requiresMembershipReach: 'add_team_member',
98+
successMessage: 'Team member added',
99+
refreshAfter: true,
100+
params: [
101+
// `user_id` is not a field of sys_team, so the param names its owner
102+
// through `objectOverride` — the sys_user lookup on the membership row.
103+
{ name: 'userId', field: 'user_id', objectOverride: 'sys_team_member', required: true },
104+
],
105+
},
81106
{
82107
// Better-auth: `organization/remove-team { teamId, organizationId? }`.
83108
// organizationId defaults to the caller's active org when omitted.

‎packages/platform-objects/src/platform-objects.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ describe('feature-gate lowering matrix (#2874)', () => {
731731
['SysTeam', SysTeam, 'create_team', `${ADMINS} && ${ORG}`],
732732
['SysTeam', SysTeam, 'update_team', `${ADMINS} && ${ORG}`],
733733
['SysTeam', SysTeam, 'remove_team', `${ADMINS} && ${ORG}`],
734+
['SysTeam', SysTeam, 'add_team_member', `${ADMINS} && ${ORG}`],
734735
['SysTeamMember', SysTeamMember, 'add_team_member', `${ADMINS} && ${ORG}`],
735736
['SysTeamMember', SysTeamMember, 'remove_team_member', `${ADMINS} && ${ORG}`],
736737
// #2874 P2b — audit gates: capability-dependent actions that previously

0 commit comments

Comments
 (0)