Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/34651-add-user-already-pending.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@objectstack/plugin-auth': patch
'@objectstack/platform-objects': patch
---

feat(identity): the Add User result says when the address was already pending

Clause-②: yes (widening)
Metadata-protocol: none

On a cloud-managed environment, Setup → Users → Add User now says when the address you added was already waiting for its first sign-in, including when you sent only an email. Before, that answer looked exactly like a fresh add.

- `POST /api/v1/auth/admin/add-sso-user` answers `pendingAgain: true` on a re-add of a person who is still pending, and leaves the key out on a fresh add. It never answers `false`. `alreadyPending` is unchanged and is still on every answer, so nothing an API reader reads today changes.
- The `sys_user.add_sso_user` result dialog gains an "Already pending" row that reads `pendingAgain`. The dialog skips a field whose path is absent from the answer, so the row is drawn only on a re-add; a fresh add shows no `false` row.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const arObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "تم",
fields: {
email: "البريد الإلكتروني",
pendingAgain: "معلّق بالفعل",
notApplied: "معلّق بالفعل، لذا لم يُطبَّق (عيّنه في السجل)",
managerError: "المدير",
"host.reason": "لم تُرسَل الدعوة"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const deObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "Fertig",
fields: {
email: "E-Mail",
pendingAgain: "Bereits ausstehend",
notApplied: "Bereits ausstehend, daher nicht übernommen (am Datensatz festlegen)",
managerError: "Führungskraft",
"host.reason": "Einladung nicht gesendet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const enObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "Done",
fields: {
email: "Email",
pendingAgain: "Already pending",
notApplied: "Already pending, so not applied (set these on the record)",
managerError: "Manager",
"host.reason": "Invitation not sent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const esESObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "Hecho",
fields: {
email: "Correo electrónico",
pendingAgain: "Ya pendiente",
notApplied: "Ya estaba pendiente, así que no se aplicó (configúralo en el registro)",
managerError: "Responsable",
"host.reason": "Invitación no enviada"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const frObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "Terminé",
fields: {
email: "E-mail",
pendingAgain: "Déjà en attente",
notApplied: "Déjà en attente, donc non appliqué (à définir sur l'enregistrement)",
managerError: "Responsable",
"host.reason": "Invitation non envoyée"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const jaJPObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "完了",
fields: {
email: "メールアドレス",
pendingAgain: "既に保留中",
notApplied: "保留中のため適用されませんでした(レコードで設定してください)",
managerError: "上司",
"host.reason": "招待は送信されませんでした"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const koObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "완료",
fields: {
email: "이메일",
pendingAgain: "이미 대기 중",
notApplied: "이미 대기 중이어서 적용되지 않음(레코드에서 설정하세요)",
managerError: "관리자",
"host.reason": "초대가 전송되지 않음"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const ptBRObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "Concluído",
fields: {
email: "E-mail",
pendingAgain: "Já pendente",
notApplied: "Já pendente, então não aplicado (defina no registro)",
managerError: "Gestor",
"host.reason": "Convite não enviado"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const ruObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "Готово",
fields: {
email: "Электронная почта",
pendingAgain: "Уже ожидает",
notApplied: "Уже ожидает входа, поэтому не применено (задайте в записи)",
managerError: "Руководитель",
"host.reason": "Приглашение не отправлено"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const zhCNObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "完成",
fields: {
email: "邮箱",
pendingAgain: "已在待激活中",
notApplied: "此人仍待激活,以下内容未生效(请在其记录上设置)",
managerError: "上级",
"host.reason": "邀请未发出"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const zhHantObjects: NonNullable<TranslationData['objects']> = {
acknowledge: "完成",
fields: {
email: "電子郵件",
pendingAgain: "已在待啟用中",
notApplied: "此人仍待啟用,以下內容未套用(請在其記錄上設定)",
managerError: "主管",
"host.reason": "邀請未送出"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,26 @@ describe('import_sso_users draws the per-row report as a table', () => {
]);
});
});

/**
* objectstack#34651: the add door answers `pendingAgain: true` only on a
* re-add of a person still pending, and never `false`. The result dialog
* skips a field whose path resolves to nothing, so a field reading that key
* draws its row exactly on a re-add; a field reading `alreadyPending`, which
* the door answers on every add, would draw a misleading `false` row on each
* fresh add (ruling A on objectstack#33187 turned that row down).
*/
describe('add_sso_user names an address that was already pending', () => {
const fields = () =>
((declared('add_sso_user').resultDialog as { fields?: Array<{ path: string; label?: unknown; format?: string }> }).fields ?? []);

it('declares one field reading `pendingAgain`, drawn as the boolean it is', () => {
const matching = fields().filter((field) => field.path === 'pendingAgain');
expect(matching).toHaveLength(1);
expect(matching[0]).toMatchObject({ label: 'Already pending', format: 'json' });
});

it('CONTROL: no field reads `alreadyPending`, which the door answers on every add', () => {
expect(fields().map((field) => field.path)).not.toContain('alreadyPending');
});
});
9 changes: 6 additions & 3 deletions packages/platform-objects/src/identity/sys-user.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,14 @@ export const SysUser = ObjectSchema.create({
title: 'User Added',
acknowledge: 'Done',
// Each field is skipped when its path is absent from the answer:
// `notApplied` only on a re-add of a person still pending, `managerError`
// only when no manager was linked, `host.reason` only when the hosting
// organisation was not told.
// `pendingAgain` only on a re-add of a person still pending (the door
// answers it only then, so no `false` row is drawn on a fresh add),
// `notApplied` only on such a re-add that sent grants or a manager,
// `managerError` only when no manager was linked, `host.reason` only
// when the hosting organisation was not told.
fields: [
{ path: 'email', label: 'Email', format: 'text' },
{ path: 'pendingAgain', label: 'Already pending', format: 'json' },
{ path: 'notApplied', label: 'Already pending, so not applied (set these on the record)', format: 'json' },
{ path: 'managerError', label: 'Manager', format: 'text' },
{ path: 'host.reason', label: 'Invitation not sent', format: 'text' },
Expand Down
73 changes: 73 additions & 0 deletions packages/plugins/plugin-auth/src/pending-sso-users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1869,3 +1869,76 @@ describe('[#34912] the SSO-user doors admit the stamped organizationId only when
expect(sessionReads.length).toBeGreaterThanOrEqual(2);
});
});

// ─────────────────────────────────────────────────────────────────────────────
// Setup → Users: what the result dialogs read is what the doors answer
// ─────────────────────────────────────────────────────────────────────────────

describe('[#34651] add-sso-user says a re-added address was already pending, and only then', () => {
it('an email-only re-add of a still-pending person answers pendingAgain: true', async () => {
const s = await managedStage();
const email = 'pending.again@example.com';
expect((await s.fire('/admin/add-sso-user', { email }, s.bearers.admin)).status).toBe(201);

const res = await s.fire('/admin/add-sso-user', { email }, s.bearers.admin);
const body: any = await res.json();

expect(res.status, JSON.stringify(body)).toBe(200);
expect(body.data.pendingAgain).toBe(true);
// Widening only: the key every answer carries is unchanged.
expect(body.data.alreadyPending).toBe(true);
});

it('CONTROL: a fresh add carries no pendingAgain at all, so the dialog draws no row for it', async () => {
const s = await managedStage();
const res = await s.fire('/admin/add-sso-user', { email: 'pending.fresh@example.com' }, s.bearers.admin);
const body: any = await res.json();

expect(res.status, JSON.stringify(body)).toBe(201);
expect(body.data).not.toHaveProperty('pendingAgain');
expect(body.data.alreadyPending).toBe(false);
});
});

describe('[#34651] the import result table reads members of a real row answer', () => {
/** The declared `table` field of `sys_user.import_sso_users`'s result dialog. */
function importTableColumns(): string[] {
const fields = (declaredAction('import_sso_users').resultDialog?.fields ?? []) as Array<{
path: string;
format?: string;
columns?: Array<{ path: string }>;
}>;
const table = fields.filter((field) => field.format === 'table');
expect(table, 'import_sso_users declares one table field').toHaveLength(1);
const columns = (table[0]!.columns ?? []).map((column) => column.path);
expect(columns.length, 'the table declares its columns').toBeGreaterThan(0);
return columns;
}

it('every column path\'s first segment is a member of a row the import door really answered', async () => {
const s = await managedStage();
// A person already pending, so one row of the file is a re-add.
expect((await s.fire('/admin/add-sso-user', { email: 'align.readd@example.com' }, s.bearers.admin)).status).toBe(201);
// Rows chosen so each member the door answers on some row is answered:
// a fresh add whose manager is unknown (`alreadyPending`, `host`,
// `managerError`), a malformed address (`error`), and a re-add that sends
// a column (`notApplied`).
const csv = [
'email,name,permission_sets,manager_id',
'align.fresh@example.com,Align Fresh,,nobody.align@example.com',
'not-an-address,Align Bad,,',
'align.readd@example.com,Align Readd,crm_user,',
].join('\n');

const res = await s.fire('/admin/import-sso-users', { csv }, s.bearers.admin);
const body: any = await res.json();
expect(res.status, JSON.stringify(body)).toBe(200);
const rows = body.data.rows as Array<Record<string, unknown>>;
expect(rows.map((r) => r.ok)).toEqual([true, false, true]);

const unanswered = importTableColumns()
.map((path) => path.split('.')[0]!)
.filter((member) => !rows.some((row) => Object.hasOwn(row, member)));
expect(unanswered, `row answers: ${JSON.stringify(rows)}`).toEqual([]);
});
});
6 changes: 6 additions & 0 deletions packages/plugins/plugin-auth/src/pending-sso-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ export async function runAddSsoUser(
email: person.email,
source: PENDING_SSO_SOURCE,
alreadyPending: outcome.alreadyPending,
// Present only on a re-add of a person still pending, so a reader
// (the `add_sso_user` result dialog, which skips a field whose path
// resolves to nothing) shows the fact exactly when it is true and
// draws no `false` row on a fresh add. `alreadyPending` stays on
// every answer for API readers.
...(outcome.alreadyPending ? { pendingAgain: true } : {}),
...(outcome.alreadyPending ? {} : { positions: person.positions, permissionSets: person.permissionSets }),
...(outcome.alreadyPending && notAppliedOn(person, ADD_FIELD_NAMES).length > 0
? { notApplied: notAppliedOn(person, ADD_FIELD_NAMES) }
Expand Down
Loading