Skip to content

Commit 07bdecd

Browse files
feat(plugin-security): translate the built-in permission sets' labels (#26145)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"} --> _Requested by **Leehom** · [project thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XB1tL9mxxeTxkG8bGaGBugq)_ Fixes #26094 Clause-②: no Metadata-protocol: none ## What changes Setup → Permission Sets showed the nine built-in permission sets with English labels under zh-CN (and ja-JP, es-ES), next to each app's translated sets and, since #26090, next to their own translated descriptions. Each built-in set's label is now translated through `permissions.NAME.label`, in the same hand-authored group as the descriptions (`packages/plugins/plugin-security/src/translations/permission-sets.ts`). `translatePermissionSet` already overlays that key on `GET /meta/permission`, so no wiring changed. | Set | en | zh-CN | ja-JP | es-ES | | --- | --- | --- | --- | --- | | `admin_full_access` | Administrator — Full Access | 管理员 — 完全访问 | 管理者 — フルアクセス | Administrador — Acceso total | | `organization_admin` | Organization Administrator | 组织管理员 | 組織管理者 | Administrador de organización | | `organization_admin_no_bypass` | Organization Administrator (no record bypass) | 组织管理员(不绕过记录权限) | 組織管理者(レコード権限のバイパスなし) | Administrador de organización (sin omitir permisos de registro) | | `member_default` | Member — Standard Access | 成员 — 标准访问 | メンバー — 標準アクセス | Miembro — Acceso estándar | | `viewer_readonly` | Viewer — Read-Only | 查看者 — 只读 | 閲覧者 — 読み取り専用 | Lector — Solo lectura | | `external_default` | External Member — Own Records | 外部成员 — 仅本人记录 | 外部メンバー — 自分のレコードのみ | Miembro externo — Solo sus registros | | `mcp_agent_data_read` | MCP Agent — Read Only | MCP AI 助手 — 只读 | MCP AI アシスタント — 読み取り専用 | Asistente de IA MCP — Solo lectura | | `mcp_agent_data_write` | MCP Agent — Read & Write | MCP AI 助手 — 读写 | MCP AI アシスタント — 読み書き | Asistente de IA MCP — Lectura y escritura | | `mcp_agent_restricted` | MCP Agent — No Data Access | MCP AI 助手 — 无数据权限 | MCP AI アシスタント — データ権限なし | Asistente de IA MCP — Sin acceso a datos | Each label keeps the English label's noun-phrase shape (the same " — " split) and reuses the terms its description in #26090 chose (for example "AI 助手" / "AI アシスタント" / "Asistente de IA" for the MCP agent sets, "无数据权限" / "データ権限なし" / "sin acceso a datos" for the restricted one), so a label and its description agree on one row. No set's grants, name, English label or description changed. **Files:** `translations/permission-sets.ts` (27 label entries and the header comment), `objects/permission-set-descriptions.test.ts` (the pin now covers labels and the served overlay), one `patch` changeset. ## Evidence Live read on `pnpm dev:crm -- --fresh` built from head `57b2effa`, signed in as the seeded admin: `GET /api/v1/meta/permission?scope=environment` with `Accept-Language: zh-CN` serves all nine built-in sets with the zh-CN label and zh-CN description, beside the app's own `CRM 销售用户` and `访客(公开表单)`: - `admin_full_access` · 管理员 — 完全访问 · 平台运维人员:可读取和修改所有组织中的每条记录… - `viewer_readonly` · 查看者 — 只读 · 只读用户:在共享允许的范围内查看所有对象的记录… - `mcp_agent_restricted` · MCP AI 助手 — 无数据权限 · 用户在无数据权限下连接的 AI 助手… With `Accept-Language: en` the same read serves the English labels unchanged. The CRM example declares only `en` and `zh-CN` (`GET /api/v1/i18n/locales`), so ja-JP was read on `pnpm dev:todo -- --fresh` (it declares ja-JP): all nine ja-JP labels were served. No example declares es-ES, so es-ES is pinned at unit level only, through the same resolver the REST boundary calls. I did not build the console here, so there is no browser screenshot; the REST read is the list the page renders. ## Tests (head `57b2effa`) - `pnpm --filter @objectstack/plugin-security test`: Test Files 224 passed (224), Tests 4798 passed, 45 skipped. `pnpm --filter @objectstack/plugin-security typecheck`: exit 0. - `permission-set-descriptions.test.ts` (99 tests): per translated locale, every built-in set carries a label (trimmed, at most 80 characters, no line break, no closing full stop, no code span or set id, the same " — " split as the English label, not an English copy), no two sets share a label, and `translateMetadataDocument('permission', set, SecurityTranslations, { locale })` serves exactly the set with that locale's label and description. The old assertion that the group carries no label is gone. - Ablation on the committed tree (`scripts/ablation-replace.mjs`, anchor hit 1 → 0, restored to the HEAD blob `97aad9a1`): deleting the zh-CN `viewer_readonly` label failed 2 tests ("carries a translated label" and "is served in this locale"). ## Gates `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 69 families on `57b2effa`; all 69 ran with exit 0. `--ran` reconciliation: 69 derived, 69 run, 0 NOT-MEASURED. Three first exited 3 on a missing prerequisite and were re-run: `check-plugin-teardown-shape --self-test` after fetching its positive-control commit, and `check:i18n` and `check:dual-build-cjs-loads` after a full `pnpm build` (`check:i18n`: all bundles in sync). Scoped `eslint --no-inline-config packages/plugins/plugin-security`: exit 0. CI runs everything else. ## Acceptance notes - **Still hand-authored, no provenance.** The labels share the descriptions' limitation: no source-hash table judges this group, so a changed English label leaves its three translations stale with no warning (the file header says so). The pin catches a missing or English-copy entry, not a stale one. Moving labels and descriptions onto a generated, provenance-checked path was out of scope; it is raised to the seat, not built. - `translations/index.ts` still says the hand-authored `permissions` group carries "description translations". The claim allowed that file only if the wiring needed it, and it did not, so the comment is left for the next change there. - The pin bounds a label at 80 characters, room above the longest translation (63, the es-ES no-bypass label) while refusing a sentence pasted as a label. - No other open PR touches `plugin-security/src/translations/`, `default-permission-sets.ts` or the pin (39 open PRs read before pr_create). --- _Generated by [Claude Code](https://claude.ai/code/session_01XpZzdGG7nKkYUhqd3reNzL)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3993793 commit 07bdecd

3 files changed

Lines changed: 103 additions & 14 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@objectstack/plugin-security': patch
3+
---
4+
5+
The built-in permission sets' names are shown in Chinese, Japanese and Spanish
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Setup → Permission Sets showed the platform's own permission sets with English names (*Administrator — Full Access*, *Member — Standard Access* …) under zh-CN, ja-JP and es-ES, next to each app's translated sets and next to their own translated descriptions. Each built-in set's label is now translated through the permission-set group of the translation bundle (`permissions.NAME.label`), beside its description, so a row reads in one language. For example, under zh-CN *Administrator — Full Access* reads 「管理员 — 完全访问」 and *Viewer — Read-Only* reads 「查看者 — 只读」.
11+
12+
No set's grants, name, English label or description changed. This changes only the text shown for each set, not its permissions.

‎packages/plugins/plugin-security/src/objects/permission-set-descriptions.test.ts‎

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
import { describe, it, expect } from 'vitest';
44
import { PermissionSetSchema } from '@objectstack/spec/security';
5+
import { translateMetadataDocument } from '@objectstack/spec/system';
56
import { defaultPermissionSets } from './default-permission-sets.js';
67
import { SecurityTranslations } from '../translations/index.js';
78

89
/**
9-
* Every built-in permission set says who holds it.
10+
* Every built-in permission set says who holds it, in every shipped locale.
1011
*
1112
* Setup → Permission Sets lists the platform's own sets beside every app's,
1213
* with each set's `description`. Five of them showed none and the no-bypass
@@ -15,18 +16,25 @@ import { SecurityTranslations } from '../translations/index.js';
1516
* member set. This pins the business fact that every set in
1617
* `defaultPermissionSets` carries ONE plain sentence of at most 160
1718
* characters, and that every translated locale of this plugin's bundle
18-
* carries that sentence for it. It is deliberately not a copy of the wording,
19+
* carries that sentence and the set's label for it, so no row of the list
20+
* reads half English. It is deliberately not a copy of the wording,
1921
* which `default-permission-sets.ts` and `../translations/permission-sets.ts`
2022
* own.
2123
*
2224
* A sentence: non-empty, no line break, at most 160 characters, ends with one
2325
* full stop (`.`, or `。` in Chinese and Japanese) and holds no other sentence
2426
* break. Engineering terms stay in the code comments beside each set, so the
2527
* copy names no permission-set id and no code span.
28+
*
29+
* A label: a short noun phrase (at most 80 characters, no line break, no
30+
* closing full stop) split by ` — ` exactly as often as the English label, so
31+
* a translation keeps the "who — what access" shape the list reads by.
2632
*/
2733
type AnyRec = Record<string, any>;
2834

2935
const MAX_LENGTH = 160;
36+
const MAX_LABEL_LENGTH = 80;
37+
const LABEL_SPLIT = ' — ';
3038
const TRANSLATED_LOCALES = Object.keys(SecurityTranslations).filter((l) => l !== 'en');
3139
const SET_NAMES = defaultPermissionSets.map((ps) => ps.name);
3240

@@ -45,6 +53,21 @@ function expectOneSentence(text: unknown, where: string): void {
4553
for (const name of SET_NAMES) expect(value, `${where}: names ${name}`).not.toContain(name);
4654
}
4755

56+
function expectLabel(text: unknown, english: string, where: string): void {
57+
expect(typeof text, `${where}: label missing`).toBe('string');
58+
const value = String(text);
59+
expect(value, `${where}: padded`).toBe(value.trim());
60+
expect(value.length, `${where}: empty`).toBeGreaterThan(0);
61+
expect([...value].length, `${where}: over ${MAX_LABEL_LENGTH} characters`).toBeLessThanOrEqual(MAX_LABEL_LENGTH);
62+
expect(value, `${where}: line break`).not.toMatch(/[\r\n]/);
63+
expect(value, `${where}: ends with a full stop`).not.toMatch(/[.。]$/);
64+
expect(value, `${where}: code span`).not.toMatch(/`/);
65+
for (const name of SET_NAMES) expect(value, `${where}: names ${name}`).not.toContain(name);
66+
expect(value.split(LABEL_SPLIT).length, `${where}: not in the English label's shape`).toBe(
67+
english.split(LABEL_SPLIT).length,
68+
);
69+
}
70+
4871
describe('built-in permission set descriptions', () => {
4972
it('ships the nine built-in sets', () => {
5073
expect(SET_NAMES).toEqual([
@@ -91,8 +114,32 @@ describe('built-in permission set descriptions', () => {
91114
const entry = group[name] as AnyRec | undefined;
92115
expectOneSentence(entry?.description, `${locale} ${name}`);
93116
expect(entry?.description, `${locale} ${name}: an English copy, not a translation`).not.toBe(set.description);
94-
// Descriptions only: the labels are not translated here.
95-
expect(entry && 'label' in entry, `${locale} ${name}: carries a label`).toBe(false);
117+
},
118+
);
119+
120+
it.each(defaultPermissionSets.map((ps) => [ps.name, ps] as const))(
121+
'%s carries a translated label',
122+
(name, set) => {
123+
const entry = group[name] as AnyRec | undefined;
124+
expectLabel(entry?.label, String(set.label), `${locale} ${name}`);
125+
expect(entry?.label, `${locale} ${name}: an English copy, not a translation`).not.toBe(set.label);
126+
},
127+
);
128+
129+
it('gives no two sets the same label', () => {
130+
const labels = SET_NAMES.map((name) => (group[name] as AnyRec | undefined)?.label);
131+
expect(new Set(labels).size).toBe(labels.length);
132+
});
133+
134+
// The overlay `GET /meta/permission` applies at the REST boundary, read
135+
// through the bundle this plugin loads: the served set's label and
136+
// description are this locale's, nothing else of the set changes.
137+
it.each(defaultPermissionSets.map((ps) => [ps.name, ps] as const))(
138+
'%s is served in this locale',
139+
(name, set) => {
140+
const served = translateMetadataDocument('permission', set, SecurityTranslations, { locale });
141+
const entry = group[name] as AnyRec;
142+
expect(served).toEqual({ ...set, label: entry.label, description: entry.description });
96143
},
97144
);
98145
});
Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
22

33
/**
4-
* Translations of the built-in permission sets' descriptions — the
5-
* `permissions.<name>.description` group of the translation bundle, which
6-
* `translatePermissionSet` overlays on every served `permission` document
4+
* Translations of the built-in permission sets' labels and descriptions — the
5+
* `permissions.<name>.label` / `.description` group of the translation bundle,
6+
* which `translatePermissionSet` overlays on every served `permission` document
77
* (`GET /meta/permission`, the list Setup → Permission Sets shows).
88
*
99
* HAND-AUTHORED, not generated: this package's extract runs objects-only, so
1010
* `os i18n extract` writes no `permissions` group here. The English source is
11-
* each set's own `description` in `../objects/default-permission-sets.ts`;
12-
* `en` needs no entry, because an untranslated locale serves the set's own
13-
* text. When a source sentence changes, re-translate its three entries here in
14-
* the same change: nothing marks a translation stale (no provenance table
15-
* judges this section). `permission-set-descriptions.test.ts` pins one entry
16-
* per built-in set per locale.
11+
* each set's own `label` and `description` in
12+
* `../objects/default-permission-sets.ts`; `en` needs no entry, because an
13+
* untranslated locale serves the set's own text. When a source label or
14+
* sentence changes, re-translate its three entries here in the same change:
15+
* nothing marks a translation stale (no provenance table judges this section).
16+
* `permission-set-descriptions.test.ts` pins one label and one description per
17+
* built-in set per locale.
1718
*
18-
* Labels are deliberately absent: this group carries the descriptions only.
19+
* A label is a short noun phrase in the English label's shape (the same
20+
* ` — ` split), using the terms its description chose, so the two agree on one
21+
* row of the list.
1922
*/
2023

2124
import type { TranslationData } from '@objectstack/spec/system';
@@ -24,90 +27,117 @@ type PermissionSetTranslations = NonNullable<TranslationData['permissions']>;
2427

2528
export const zhCNPermissionSets: PermissionSetTranslations = {
2629
admin_full_access: {
30+
label: '管理员 — 完全访问',
2731
description: '平台运维人员:可读取和修改所有组织中的每条记录,管理全部用户与设置,并在 Studio 中构建应用。',
2832
},
2933
organization_admin: {
34+
label: '组织管理员',
3035
description: '组织的所有者和管理员:在设置中全面管理本组织的记录和成员,但不能构建应用或修改平台级设置。',
3136
},
3237
organization_admin_no_bypass: {
38+
label: '组织管理员(不绕过记录权限)',
3339
description: '组织之间未设隔离墙的部署中的组织管理员:管理权限相同,但只能访问其所有权和共享范围内的记录。',
3440
},
3541
member_default: {
42+
label: '成员 — 标准访问',
3643
description: '每位已登录成员的基础权限:本人的资料、密钥、收件箱和成员目录;业务记录的访问来自其他权限集。',
3744
},
3845
viewer_readonly: {
46+
label: '查看者 — 只读',
3947
description: '只读用户:在共享允许的范围内查看所有对象的记录,但不能新建、编辑或删除任何内容。',
4048
},
4149
external_default: {
50+
label: '外部成员 — 仅本人记录',
4251
description: '组织外部人员(如客户或供应商):仅限本人的资料和记录,以及与其共享的内容。',
4352
},
4453
mcp_agent_data_read: {
54+
label: 'MCP AI 助手 — 只读',
4555
description: '用户以只读权限连接的 AI 助手:可读取该用户能读取的内容,不做任何修改。',
4656
},
4757
mcp_agent_data_write: {
58+
label: 'MCP AI 助手 — 读写',
4859
description: '用户以读写权限连接的 AI 助手:可读取和修改该用户能访问的内容,但用户与登录数据除外。',
4960
},
5061
mcp_agent_restricted: {
62+
label: 'MCP AI 助手 — 无数据权限',
5163
description: '用户在无数据权限下连接的 AI 助手:可执行已获准的操作,但不能读取或修改任何记录。',
5264
},
5365
};
5466

5567
export const jaJPPermissionSets: PermissionSetTranslations = {
5668
admin_full_access: {
69+
label: '管理者 — フルアクセス',
5770
description: 'プラットフォーム運用者:すべての組織のすべてのレコードを参照・変更し、全ユーザーと設定を管理し、Studio でアプリを作成できます。',
5871
},
5972
organization_admin: {
73+
label: '組織管理者',
6074
description: '組織のオーナーと管理者:設定画面で自組織のレコードとメンバーを全面的に管理できますが、アプリ作成やプラットフォーム全体の設定はできません。',
6175
},
6276
organization_admin_no_bypass: {
77+
label: '組織管理者(レコード権限のバイパスなし)',
6378
description: '組織間に壁のないデプロイの組織管理者:管理権限は同じですが、所有権と共有で開かれたレコードだけを扱えます。',
6479
},
6580
member_default: {
81+
label: 'メンバー — 標準アクセス',
6682
description: 'サインインしたすべてのメンバーの基本権限:自分のプロフィール・キー・受信箱とメンバー一覧のみで、業務レコードは他の権限セットで付与されます。',
6783
},
6884
viewer_readonly: {
85+
label: '閲覧者 — 読み取り専用',
6986
description: '閲覧専用ユーザー:共有で許される範囲ですべてのオブジェクトのレコードを参照できますが、作成・編集・削除はできません。',
7087
},
7188
external_default: {
89+
label: '外部メンバー — 自分のレコードのみ',
7290
description: '顧客や仕入先など組織外の人:自分のプロフィールとレコード、および共有されたものだけを扱えます。',
7391
},
7492
mcp_agent_data_read: {
93+
label: 'MCP AI アシスタント — 読み取り専用',
7594
description: 'ユーザーが読み取り権限で接続した AI アシスタント:そのユーザーが参照できるものを参照し、何も変更しません。',
7695
},
7796
mcp_agent_data_write: {
97+
label: 'MCP AI アシスタント — 読み書き',
7898
description: 'ユーザーが読み書き権限で接続した AI アシスタント:そのユーザーが扱えるものを参照・変更できますが、ユーザーとサインインのデータは除きます。',
7999
},
80100
mcp_agent_restricted: {
101+
label: 'MCP AI アシスタント — データ権限なし',
81102
description: 'ユーザーがデータ権限なしで接続した AI アシスタント:許可されたアクションは実行できますが、レコードの参照や変更はできません。',
82103
},
83104
};
84105

85106
export const esESPermissionSets: PermissionSetTranslations = {
86107
admin_full_access: {
108+
label: 'Administrador — Acceso total',
87109
description: 'Operadores de la plataforma: leen y cambian todos los registros de todas las organizaciones, gestionan usuarios y ajustes y crean apps en Studio.',
88110
},
89111
organization_admin: {
112+
label: 'Administrador de organización',
90113
description: 'Propietarios y administradores de una organización: control total de sus registros y miembros en Configuración, sin crear apps ni cambiar ajustes globales.',
91114
},
92115
organization_admin_no_bypass: {
116+
label: 'Administrador de organización (sin omitir permisos de registro)',
93117
description: 'Administradores de organización sin muro entre organizaciones: la misma administración, pero solo los registros que abren su propiedad y el uso compartido.',
94118
},
95119
member_default: {
120+
label: 'Miembro — Acceso estándar',
96121
description: 'Base de todo miembro con sesión: su perfil, claves, bandeja de entrada y el directorio de miembros; los registros de negocio llegan por otros conjuntos.',
97122
},
98123
viewer_readonly: {
124+
label: 'Lector — Solo lectura',
99125
description: 'Usuarios de solo lectura: leen registros de todos los objetos, hasta donde lo permite el uso compartido, pero no crean, editan ni eliminan nada.',
100126
},
101127
external_default: {
128+
label: 'Miembro externo — Solo sus registros',
102129
description: 'Personas ajenas a la organización, como clientes o proveedores: su propio perfil y registros, y solo lo que se comparte con ellas.',
103130
},
104131
mcp_agent_data_read: {
132+
label: 'Asistente de IA MCP — Solo lectura',
105133
description: 'Asistentes de IA que un usuario conecta con acceso de lectura: leen lo que ese usuario puede leer y no cambian nada.',
106134
},
107135
mcp_agent_data_write: {
136+
label: 'Asistente de IA MCP — Lectura y escritura',
108137
description: 'Asistentes de IA que un usuario conecta con lectura y escritura: leen y cambian lo que ese usuario puede, salvo datos de usuario y de inicio de sesión.',
109138
},
110139
mcp_agent_restricted: {
140+
label: 'Asistente de IA MCP — Sin acceso a datos',
111141
description: 'Asistentes de IA que un usuario conecta sin acceso a datos: ejecutan las acciones permitidas, pero no leen ni cambian ningún registro.',
112142
},
113143
};

0 commit comments

Comments
 (0)