@astram/identity 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/company-membership.object.d.ts.map +1 -1
- package/dist/company-membership.object.js +3 -2
- package/dist/company.object.d.ts.map +1 -1
- package/dist/company.object.js +8 -3
- package/dist/features/access/index.d.ts.map +1 -1
- package/dist/features/access/index.js +1 -5
- package/dist/features/audit/audit-read.service.d.ts.map +1 -1
- package/dist/features/audit/audit-read.service.js +13 -6
- package/dist/features/audit/audit.controller.d.ts.map +1 -1
- package/dist/features/audit/audit.controller.js +2 -0
- package/dist/features/audit/mariadb-audit-reader.d.ts.map +1 -1
- package/dist/features/authz/access-bundle-reconcile.job.d.ts.map +1 -1
- package/dist/features/authz/catalog-reconcile.job.d.ts.map +1 -1
- package/dist/features/authz/catalog-reconcile.job.js +1 -3
- package/dist/features/authz/db-permission-facts.adapter.d.ts +24 -4
- package/dist/features/authz/db-permission-facts.adapter.d.ts.map +1 -1
- package/dist/features/authz/db-permission-facts.adapter.js +92 -5
- package/dist/features/authz/grant-admin.controller.d.ts +8 -5
- package/dist/features/authz/grant-admin.controller.d.ts.map +1 -1
- package/dist/features/authz/grant-admin.controller.js +22 -15
- package/dist/features/authz/grant-admin.service.d.ts +57 -11
- package/dist/features/authz/grant-admin.service.d.ts.map +1 -1
- package/dist/features/authz/grant-admin.service.js +163 -85
- package/dist/features/authz/grant-ceiling.d.ts +111 -0
- package/dist/features/authz/grant-ceiling.d.ts.map +1 -0
- package/dist/features/authz/grant-ceiling.js +248 -0
- package/dist/features/authz/mariadb-catalog-store.d.ts.map +1 -1
- package/dist/features/authz/mariadb-catalog-store.js +15 -3
- package/dist/features/authz/permission-version.bumper.d.ts +45 -1
- package/dist/features/authz/permission-version.bumper.d.ts.map +1 -1
- package/dist/features/authz/permission-version.bumper.js +106 -16
- package/dist/features/authz/record-authorization.d.ts.map +1 -1
- package/dist/features/authz/role-binding.d.ts +36 -0
- package/dist/features/authz/role-binding.d.ts.map +1 -0
- package/dist/features/authz/role-binding.js +53 -0
- package/dist/features/company/company-hierarchy.service.d.ts +46 -0
- package/dist/features/company/company-hierarchy.service.d.ts.map +1 -0
- package/dist/features/company/company-hierarchy.service.js +100 -0
- package/dist/features/company/company.controller.d.ts +23 -5
- package/dist/features/company/company.controller.d.ts.map +1 -1
- package/dist/features/company/company.controller.js +47 -12
- package/dist/features/company/company.service.d.ts +28 -12
- package/dist/features/company/company.service.d.ts.map +1 -1
- package/dist/features/company/company.service.js +61 -14
- package/dist/features/cross-tenant/cross-tenant-grant.controller.d.ts.map +1 -1
- package/dist/features/cross-tenant/cross-tenant-grant.controller.js +2 -0
- package/dist/features/identity-feature.module.d.ts.map +1 -1
- package/dist/features/identity-feature.module.js +123 -6
- package/dist/features/membership/membership.controller.d.ts +6 -5
- package/dist/features/membership/membership.controller.d.ts.map +1 -1
- package/dist/features/membership/membership.controller.js +34 -22
- package/dist/features/membership/membership.service.d.ts +20 -14
- package/dist/features/membership/membership.service.d.ts.map +1 -1
- package/dist/features/membership/membership.service.js +62 -29
- package/dist/features/membership/posting-version-bump.d.ts +5 -0
- package/dist/features/membership/posting-version-bump.d.ts.map +1 -1
- package/dist/features/membership/posting.service.d.ts +20 -24
- package/dist/features/membership/posting.service.d.ts.map +1 -1
- package/dist/features/membership/posting.service.js +101 -64
- package/dist/features/org-structure/org-catalog.controller.d.ts.map +1 -1
- package/dist/features/org-structure/org-catalog.controller.js +2 -0
- package/dist/features/org-structure/org-catalog.service.d.ts.map +1 -1
- package/dist/features/org-structure/org-catalog.service.js +4 -1
- package/dist/features/policy/policy.controller.d.ts.map +1 -1
- package/dist/features/policy/policy.controller.js +2 -0
- package/dist/features/role/role.controller.d.ts +3 -2
- package/dist/features/role/role.controller.d.ts.map +1 -1
- package/dist/features/role/role.controller.js +15 -10
- package/dist/features/role/role.service.d.ts +16 -8
- package/dist/features/role/role.service.d.ts.map +1 -1
- package/dist/features/role/role.service.js +24 -10
- package/dist/features/scope/scope-closure.service.d.ts +44 -4
- package/dist/features/scope/scope-closure.service.d.ts.map +1 -1
- package/dist/features/scope/scope-closure.service.js +215 -82
- package/dist/features/service-account/service-account.controller.d.ts +63 -0
- package/dist/features/service-account/service-account.controller.d.ts.map +1 -0
- package/dist/features/service-account/service-account.controller.js +295 -0
- package/dist/features/service-account/service-account.service.d.ts +209 -0
- package/dist/features/service-account/service-account.service.d.ts.map +1 -0
- package/dist/features/service-account/service-account.service.js +528 -0
- package/dist/features/service-account/service-account.store.d.ts +91 -0
- package/dist/features/service-account/service-account.store.d.ts.map +1 -0
- package/dist/features/service-account/service-account.store.js +158 -0
- package/dist/features/share/share.controller.d.ts.map +1 -1
- package/dist/features/share/share.controller.js +2 -0
- package/dist/features/share/share.service.d.ts.map +1 -1
- package/dist/features/shared/identity-error.interceptor.d.ts +24 -0
- package/dist/features/shared/identity-error.interceptor.d.ts.map +1 -0
- package/dist/features/shared/identity-error.interceptor.js +82 -0
- package/dist/features/shared/identity-errors.d.ts +23 -0
- package/dist/features/shared/identity-errors.d.ts.map +1 -0
- package/dist/features/shared/identity-errors.js +41 -0
- package/dist/features/user/session-revocation-check.d.ts +11 -0
- package/dist/features/user/session-revocation-check.d.ts.map +1 -0
- package/dist/features/user/session-revocation-check.js +21 -0
- package/dist/features/user/user.controller.d.ts +11 -6
- package/dist/features/user/user.controller.d.ts.map +1 -1
- package/dist/features/user/user.controller.js +35 -17
- package/dist/features/user/user.service.d.ts +55 -14
- package/dist/features/user/user.service.d.ts.map +1 -1
- package/dist/features/user/user.service.js +143 -16
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/membership-posting.object.d.ts.map +1 -1
- package/dist/membership-posting.object.js +4 -2
- package/dist/objects.d.ts.map +1 -1
- package/dist/objects.js +14 -3
- package/dist/role.object.d.ts.map +1 -1
- package/dist/role.object.js +3 -0
- package/dist/service-account.object.d.ts +31 -0
- package/dist/service-account.object.d.ts.map +1 -0
- package/dist/service-account.object.js +75 -0
- package/dist/user.object.d.ts.map +1 -1
- package/dist/user.object.js +3 -0
- package/migrations/1710000000018-CreateServiceAccount.cjs +53 -0
- package/migrations/1710000000019-AddSessionMustReenroll.cjs +35 -0
- package/package.json +4 -4
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export interface PostingVersionBump {
|
|
7
7
|
bumpTenant(tenantUuid: string): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* OPTIONAL (security hardening Phase 3): bump every tenant the user has a membership in — after
|
|
10
|
+
* the account itself was disabled or re-enabled. Returns the bumped tenants; throws on failure.
|
|
11
|
+
*/
|
|
12
|
+
bumpForUser?(userUuid: string): Promise<string[]>;
|
|
8
13
|
}
|
|
9
14
|
export declare const POSTING_VERSION_BUMP: unique symbol;
|
|
10
15
|
//# sourceMappingURL=posting-version-bump.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posting-version-bump.d.ts","sourceRoot":"","sources":["../../../src/features/membership/posting-version-bump.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"posting-version-bump.d.ts","sourceRoot":"","sources":["../../../src/features/membership/posting-version-bump.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C;;;OAGG;IACH,WAAW,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACnD;AAED,eAAO,MAAM,oBAAoB,eAAiC,CAAC"}
|
|
@@ -6,21 +6,24 @@
|
|
|
6
6
|
* diffs current-vs-desired and applies the minimal change — delete only what's removed,
|
|
7
7
|
* create only what's added, keep the rest untouched.
|
|
8
8
|
*
|
|
9
|
-
* ──
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* the
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
9
|
+
* ── Authority (security hardening #11) ─────────────────────────────────────────────────
|
|
10
|
+
* A posting IS a role assignment, so before ANY write the actor (the request principal) must:
|
|
11
|
+
* - reach the membership (a walled `records.get` → null ⇒ 404; the engine's ADR-0034 create
|
|
12
|
+
* wall re-checks the posting's membership company inside the transaction);
|
|
13
|
+
* - for every ADDED role: the role is bound within the actor's subtree or not bound at all
|
|
14
|
+
* (`GrantCeiling.assertRoleAssignable` — a role also used elsewhere is never assignable),
|
|
15
|
+
* and the role's keys are all held by the actor (`assertCanAssignRoles`, ADR-0029 applied to
|
|
16
|
+
* assignment). Removals need no ceiling: self-demotion stays allowed.
|
|
17
|
+
*
|
|
18
|
+
* ── Atomicity (KI #16) ────────────────────────────────────────────────────────────────
|
|
19
|
+
* The diff runs inside ONE `records.transaction` (ADR-0034): creates FIRST, then deletes, so a
|
|
20
|
+
* failure at any point rolls back every posting write of the replace (no partial set, no
|
|
21
|
+
* window where a removed role is gone but its replacement was refused).
|
|
21
22
|
*/
|
|
22
23
|
import { RecordsService, type RecordView } from '@astram/engine';
|
|
24
|
+
import type { Principal } from '@astram/core';
|
|
23
25
|
import { type PostingVersionBump } from './posting-version-bump.js';
|
|
26
|
+
import { GrantCeiling } from '../authz/grant-ceiling.js';
|
|
24
27
|
/**
|
|
25
28
|
* The shape of one desired posting row submitted by the editor. The effective-window
|
|
26
29
|
* bounds arrive from the client as a bare `YYYY-MM-DD` date string (native `<input
|
|
@@ -36,24 +39,17 @@ export interface PostingInput {
|
|
|
36
39
|
}
|
|
37
40
|
export declare class PostingService {
|
|
38
41
|
private readonly records;
|
|
42
|
+
private readonly ceiling;
|
|
39
43
|
private readonly versionBump?;
|
|
40
|
-
constructor(records: RecordsService, versionBump?: (PostingVersionBump | null) | undefined);
|
|
44
|
+
constructor(records: RecordsService, ceiling: GrantCeiling, versionBump?: (PostingVersionBump | null) | undefined);
|
|
41
45
|
/** List a membership's postings (tenant-scoped by the pipe). */
|
|
42
46
|
listPostings(membershipUuid: string): Promise<readonly RecordView[]>;
|
|
43
47
|
/**
|
|
44
48
|
* Replace a membership's full posting set with `desired`, applying the minimal diff.
|
|
45
49
|
* Compares current vs desired by the natural key `roleUuid|departmentUuid|branchUuid`:
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* kept postings are never delete targets, so the membership never lands empty).
|
|
49
|
-
*/
|
|
50
|
-
replacePostings(membershipUuid: string, desired: readonly PostingInput[]): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Resolve the tenant (company uuid) a membership belongs to — the tenant whose permission
|
|
53
|
-
* version a posting change must bump. Reads the parent `company_membership` through the
|
|
54
|
-
* pipe (tenant-scoped, no raw SQL), returning `companyUuid` or `null` if unresolvable
|
|
55
|
-
* (then no bump — fail-safe; never guesses a tenant).
|
|
50
|
+
* creates added rows, deletes removed rows, leaves kept rows untouched. Every authority check
|
|
51
|
+
* runs BEFORE any write; the writes run in one transaction (see the file header).
|
|
56
52
|
*/
|
|
57
|
-
|
|
53
|
+
replacePostings(actor: Principal, membershipUuid: string, desired: readonly PostingInput[]): Promise<void>;
|
|
58
54
|
}
|
|
59
55
|
//# sourceMappingURL=posting.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posting.service.d.ts","sourceRoot":"","sources":["../../../src/features/membership/posting.service.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"posting.service.d.ts","sourceRoot":"","sources":["../../../src/features/membership/posting.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAwB,KAAK,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACvC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CACzC;AA0ED,qBACa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAGxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAKxB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;gBARZ,OAAO,EAAE,cAAc,EAGvB,OAAO,EAAE,YAAY,EAKrB,WAAW,CAAC,GAAE,kBAAkB,GAAG,IAAI,aAAA;IAG1D,gEAAgE;IAC1D,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,UAAU,EAAE,CAAC;IAK1E;;;;;OAKG;IACG,eAAe,CACnB,KAAK,EAAE,SAAS,EAChB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,SAAS,YAAY,EAAE,GAC/B,OAAO,CAAC,IAAI,CAAC;CAuGjB"}
|
|
@@ -7,18 +7,19 @@
|
|
|
7
7
|
* diffs current-vs-desired and applies the minimal change — delete only what's removed,
|
|
8
8
|
* create only what's added, keep the rest untouched.
|
|
9
9
|
*
|
|
10
|
-
* ──
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* the
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
10
|
+
* ── Authority (security hardening #11) ─────────────────────────────────────────────────
|
|
11
|
+
* A posting IS a role assignment, so before ANY write the actor (the request principal) must:
|
|
12
|
+
* - reach the membership (a walled `records.get` → null ⇒ 404; the engine's ADR-0034 create
|
|
13
|
+
* wall re-checks the posting's membership company inside the transaction);
|
|
14
|
+
* - for every ADDED role: the role is bound within the actor's subtree or not bound at all
|
|
15
|
+
* (`GrantCeiling.assertRoleAssignable` — a role also used elsewhere is never assignable),
|
|
16
|
+
* and the role's keys are all held by the actor (`assertCanAssignRoles`, ADR-0029 applied to
|
|
17
|
+
* assignment). Removals need no ceiling: self-demotion stays allowed.
|
|
18
|
+
*
|
|
19
|
+
* ── Atomicity (KI #16) ────────────────────────────────────────────────────────────────
|
|
20
|
+
* The diff runs inside ONE `records.transaction` (ADR-0034): creates FIRST, then deletes, so a
|
|
21
|
+
* failure at any point rolls back every posting write of the replace (no partial set, no
|
|
22
|
+
* window where a removed role is gone but its replacement was refused).
|
|
22
23
|
*/
|
|
23
24
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
24
25
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -37,8 +38,18 @@ exports.PostingService = void 0;
|
|
|
37
38
|
const common_1 = require("@nestjs/common");
|
|
38
39
|
const engine_1 = require("@astram/engine");
|
|
39
40
|
const posting_version_bump_js_1 = require("./posting-version-bump.js");
|
|
41
|
+
const grant_ceiling_js_1 = require("../authz/grant-ceiling.js");
|
|
42
|
+
const identity_errors_js_1 = require("../shared/identity-errors.js");
|
|
40
43
|
/** The field keys whose values are effective-window epoch-ms bounds (normalized on write). */
|
|
41
44
|
const WINDOW_KEYS = new Set(['effectiveFrom', 'effectiveUntil']);
|
|
45
|
+
/** The ONLY keys a client posting entry may set (review F4) — never `membershipUuid`. */
|
|
46
|
+
const POSTING_KEYS = [
|
|
47
|
+
'roleUuid',
|
|
48
|
+
'departmentUuid',
|
|
49
|
+
'branchUuid',
|
|
50
|
+
'effectiveFrom',
|
|
51
|
+
'effectiveUntil',
|
|
52
|
+
];
|
|
42
53
|
/**
|
|
43
54
|
* Normalize an effective-window bound to epoch-ms (a `number`), or `null` if empty/unparseable.
|
|
44
55
|
* The membership_posting object declares these fields as `number` (BIGINT epoch-ms) so the
|
|
@@ -79,7 +90,13 @@ function naturalKey(p) {
|
|
|
79
90
|
*/
|
|
80
91
|
function stripEmpty(input) {
|
|
81
92
|
const out = {};
|
|
82
|
-
|
|
93
|
+
// Security review F4: only the posting's own fields are taken from the client entry — a
|
|
94
|
+
// client `membershipUuid` (or `createdBy`, or any unknown key) never reaches the engine; the
|
|
95
|
+
// caller sets `membershipUuid` from the PATH.
|
|
96
|
+
for (const k of POSTING_KEYS) {
|
|
97
|
+
if (!(k in input))
|
|
98
|
+
continue;
|
|
99
|
+
const v = input[k];
|
|
83
100
|
if (WINDOW_KEYS.has(k)) {
|
|
84
101
|
const ms = toEpochMs(v);
|
|
85
102
|
if (ms !== null)
|
|
@@ -93,9 +110,14 @@ function stripEmpty(input) {
|
|
|
93
110
|
}
|
|
94
111
|
let PostingService = class PostingService {
|
|
95
112
|
records;
|
|
113
|
+
ceiling;
|
|
96
114
|
versionBump;
|
|
97
|
-
constructor(records,
|
|
115
|
+
constructor(records,
|
|
116
|
+
// The role-assignment ceiling + binding rule (security hardening #11). REQUIRED: a missing
|
|
117
|
+
// ceiling must fail DI at boot, never silently skip the check.
|
|
118
|
+
ceiling, versionBump) {
|
|
98
119
|
this.records = records;
|
|
120
|
+
this.ceiling = ceiling;
|
|
99
121
|
this.versionBump = versionBump;
|
|
100
122
|
}
|
|
101
123
|
/** List a membership's postings (tenant-scoped by the pipe). */
|
|
@@ -106,45 +128,75 @@ let PostingService = class PostingService {
|
|
|
106
128
|
/**
|
|
107
129
|
* Replace a membership's full posting set with `desired`, applying the minimal diff.
|
|
108
130
|
* Compares current vs desired by the natural key `roleUuid|departmentUuid|branchUuid`:
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* kept postings are never delete targets, so the membership never lands empty).
|
|
131
|
+
* creates added rows, deletes removed rows, leaves kept rows untouched. Every authority check
|
|
132
|
+
* runs BEFORE any write; the writes run in one transaction (see the file header).
|
|
112
133
|
*/
|
|
113
|
-
async replacePostings(membershipUuid, desired) {
|
|
114
|
-
|
|
134
|
+
async replacePostings(actor, membershipUuid, desired) {
|
|
135
|
+
for (const d of desired) {
|
|
136
|
+
if (typeof d?.roleUuid !== 'string' || d.roleUuid.length === 0) {
|
|
137
|
+
throw new identity_errors_js_1.IdentityBadRequestError('Every assignment needs a role.');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// 1) Reach: the membership must be visible through the subtree read wall (else 404).
|
|
141
|
+
const membership = await this.records.get('company_membership', membershipUuid);
|
|
142
|
+
if (membership === null)
|
|
143
|
+
throw new identity_errors_js_1.IdentityNotFoundError('Membership not found.');
|
|
144
|
+
const tenantUuid = typeof membership.fields?.companyUuid === 'string' && membership.fields.companyUuid.length > 0
|
|
145
|
+
? membership.fields.companyUuid
|
|
146
|
+
: null;
|
|
147
|
+
const current = (await this.records.list('membership_posting', { where: { membershipUuid } }))
|
|
148
|
+
.rows;
|
|
115
149
|
const desiredKeys = new Set(desired.map(naturalKey));
|
|
116
150
|
const currentKeys = new Set(current.map((r) => naturalKey(r.fields)));
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
151
|
+
const removed = current.filter((r) => !desiredKeys.has(naturalKey(r.fields)));
|
|
152
|
+
const seenAdded = new Set();
|
|
153
|
+
const added = desired.filter((d) => {
|
|
154
|
+
const k = naturalKey(d);
|
|
155
|
+
if (currentKeys.has(k) || seenAdded.has(k))
|
|
156
|
+
return false;
|
|
157
|
+
seenAdded.add(k);
|
|
158
|
+
return true;
|
|
159
|
+
});
|
|
160
|
+
// 2) Authority for every ADDED role, before any write: binding rule, then the ceiling.
|
|
161
|
+
const addedRoles = [...new Set(added.map((d) => d.roleUuid))];
|
|
162
|
+
for (const roleUuid of addedRoles) {
|
|
163
|
+
await this.ceiling.assertRoleAssignable(actor, roleUuid);
|
|
127
164
|
}
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
135
|
-
changed = true;
|
|
136
|
-
}
|
|
165
|
+
await this.ceiling.assertCanAssignRoles(actor, addedRoles);
|
|
166
|
+
// Removing a PEER's postings strips their authority: the actor must dominate the member
|
|
167
|
+
// (security review). Removing your OWN postings (self-demotion) stays allowed.
|
|
168
|
+
const memberUuid = typeof membership.fields?.userUuid === 'string' ? membership.fields.userUuid : '';
|
|
169
|
+
if (removed.length > 0 && memberUuid !== actor.id) {
|
|
170
|
+
await this.ceiling.assertDominates(actor, memberUuid);
|
|
137
171
|
}
|
|
172
|
+
if (added.length === 0 && removed.length === 0)
|
|
173
|
+
return; // no-op replace: no write, no bump
|
|
174
|
+
// 3) Write atomically: creates first, then deletes (KI #16). Only whitelisted fields are sent,
|
|
175
|
+
// and `membershipUuid` always comes from the path (review F4).
|
|
176
|
+
await this.records.transaction(async (tx) => {
|
|
177
|
+
// Review F2: serialise against a concurrent grant/posting of the same role. Lock each
|
|
178
|
+
// added role row on THIS transaction (grant administration locks the same row), then
|
|
179
|
+
// re-run the binding rule: a binding another tenant committed while we waited is now
|
|
180
|
+
// visible, and a role that became shared is refused before the INSERT (rolled back).
|
|
181
|
+
for (const roleUuid of addedRoles) {
|
|
182
|
+
await tx.lockForUpdate('role', roleUuid);
|
|
183
|
+
await this.ceiling.assertRoleAssignable(actor, roleUuid);
|
|
184
|
+
}
|
|
185
|
+
for (const d of added) {
|
|
186
|
+
await tx.create('membership_posting', { fields: { ...stripEmpty(d), membershipUuid } });
|
|
187
|
+
}
|
|
188
|
+
for (const r of removed) {
|
|
189
|
+
await tx.delete('membership_posting', r.id);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
138
192
|
// ADR-0011 STALENESS FIX: a posting add/remove changes the effective roles (→ coarse
|
|
139
193
|
// grants) of the membership's user in that company, so bump the tenant's permission
|
|
140
194
|
// version — every live session in that tenant then reloads its cached facts on the next
|
|
141
|
-
// request (a role gain/loss lands within the version bound). Only when
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
|
|
146
|
-
if (changed && this.versionBump) {
|
|
147
|
-
const tenantUuid = await this.resolveMembershipTenant(membershipUuid);
|
|
195
|
+
// request (a role gain/loss lands within the version bound). Only when the bump collaborator
|
|
196
|
+
// is wired (absent in unit tests → no-op). Best-effort + fail-safe: the posting write already
|
|
197
|
+
// committed, so a bump failure must NOT surface as a 500 that hides a successful assignment
|
|
198
|
+
// change — the cache is instead invalidated by the next legit bump / the facts' natural TTL.
|
|
199
|
+
if (this.versionBump) {
|
|
148
200
|
if (tenantUuid) {
|
|
149
201
|
try {
|
|
150
202
|
await this.versionBump.bumpTenant(tenantUuid);
|
|
@@ -155,27 +207,12 @@ let PostingService = class PostingService {
|
|
|
155
207
|
}
|
|
156
208
|
}
|
|
157
209
|
}
|
|
158
|
-
/**
|
|
159
|
-
* Resolve the tenant (company uuid) a membership belongs to — the tenant whose permission
|
|
160
|
-
* version a posting change must bump. Reads the parent `company_membership` through the
|
|
161
|
-
* pipe (tenant-scoped, no raw SQL), returning `companyUuid` or `null` if unresolvable
|
|
162
|
-
* (then no bump — fail-safe; never guesses a tenant).
|
|
163
|
-
*/
|
|
164
|
-
async resolveMembershipTenant(membershipUuid) {
|
|
165
|
-
try {
|
|
166
|
-
const m = await this.records.get('company_membership', membershipUuid);
|
|
167
|
-
const companyUuid = m?.fields?.companyUuid;
|
|
168
|
-
return typeof companyUuid === 'string' && companyUuid.length > 0 ? companyUuid : null;
|
|
169
|
-
}
|
|
170
|
-
catch {
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
210
|
};
|
|
175
211
|
exports.PostingService = PostingService;
|
|
176
212
|
exports.PostingService = PostingService = __decorate([
|
|
177
213
|
(0, common_1.Injectable)(),
|
|
178
|
-
__param(
|
|
179
|
-
__param(
|
|
180
|
-
__metadata("design:paramtypes", [engine_1.RecordsService,
|
|
214
|
+
__param(2, (0, common_1.Optional)()),
|
|
215
|
+
__param(2, (0, common_1.Inject)(posting_version_bump_js_1.POSTING_VERSION_BUMP)),
|
|
216
|
+
__metadata("design:paramtypes", [engine_1.RecordsService,
|
|
217
|
+
grant_ceiling_js_1.GrantCeiling, Object])
|
|
181
218
|
], PostingService);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"org-catalog.controller.d.ts","sourceRoot":"","sources":["../../../src/features/org-structure/org-catalog.controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"org-catalog.controller.d.ts","sourceRoot":"","sources":["../../../src/features/org-structure/org-catalog.controller.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAU7D,qBAEa,oBAAoB;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,iBAAiB;IAEvD,kFAAkF;IAG5E,sBAAsB,CAAuB,WAAW,EAAE,MAAM;;;IAKtE,+EAA+E;IAGzE,mBAAmB,CAAuB,WAAW,EAAE,MAAM;;;CAIpE"}
|
|
@@ -14,6 +14,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.OrgCatalogController = void 0;
|
|
16
16
|
const common_1 = require("@nestjs/common");
|
|
17
|
+
const identity_error_interceptor_js_1 = require("../shared/identity-error.interceptor.js");
|
|
17
18
|
const guard_1 = require("@astram/guard");
|
|
18
19
|
const org_catalog_service_js_1 = require("./org-catalog.service.js");
|
|
19
20
|
// ── Company-scoped catalogs (dept/branch option lists for the posting editor) ──
|
|
@@ -58,5 +59,6 @@ __decorate([
|
|
|
58
59
|
], OrgCatalogController.prototype, "listCompanyBranches", null);
|
|
59
60
|
exports.OrgCatalogController = OrgCatalogController = __decorate([
|
|
60
61
|
(0, common_1.Controller)('identity'),
|
|
62
|
+
(0, common_1.UseInterceptors)(identity_error_interceptor_js_1.IdentityErrorInterceptor),
|
|
61
63
|
__metadata("design:paramtypes", [org_catalog_service_js_1.OrgCatalogService])
|
|
62
64
|
], OrgCatalogController);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"org-catalog.service.d.ts","sourceRoot":"","sources":["../../../src/features/org-structure/org-catalog.service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,qBACa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,cAAc;IAEpD,kFAAkF;IAClF,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"org-catalog.service.d.ts","sourceRoot":"","sources":["../../../src/features/org-structure/org-catalog.service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,qBACa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,cAAc;IAEpD,kFAAkF;IAClF,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IASnE,+EAA+E;IAC/E,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIhE,qFAAqF;YACvE,kBAAkB;CAoBjC"}
|
|
@@ -41,7 +41,10 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
41
41
|
continue;
|
|
42
42
|
const view = await this.records.get(catalogTypeKey, refUuid);
|
|
43
43
|
const name = view?.fields?.name;
|
|
44
|
-
options.push({
|
|
44
|
+
options.push({
|
|
45
|
+
uuid: refUuid,
|
|
46
|
+
name: typeof name === 'string' && name.length > 0 ? name : '(unknown)',
|
|
47
|
+
});
|
|
45
48
|
}
|
|
46
49
|
return options;
|
|
47
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.controller.d.ts","sourceRoot":"","sources":["../../../src/features/policy/policy.controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"policy.controller.d.ts","sourceRoot":"","sources":["../../../src/features/policy/policy.controller.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,aAAa,EAId,MAAM,qBAAqB,CAAC;AAE7B,qFAAqF;AACrF,UAAU,aAAa;IACrB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,qBAEa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,aAAa;IAEpD;;;;;;;;OAQG;IAGG,MAAM,CAAmB,OAAO,CAAC,EAAE,MAAM;IAY/C;;;OAGG;IAGG,IAAI,CAAQ,GAAG,EAAE,aAAa,EAAoB,OAAO,CAAC,EAAE,MAAM;;;IAQxE;;;;;OAKG;IAGG,MAAM,CAAQ,GAAG,EAAE,aAAa,EAAU,IAAI,EAAE,YAAY;;;IAWlE;;;;OAIG;IAGG,MAAM,CAAQ,GAAG,EAAE,aAAa,EAAe,EAAE,EAAE,MAAM;;;CAShE"}
|
|
@@ -33,6 +33,7 @@ exports.PolicyController = void 0;
|
|
|
33
33
|
*/
|
|
34
34
|
const common_1 = require("@nestjs/common");
|
|
35
35
|
const guard_1 = require("@astram/guard");
|
|
36
|
+
const identity_error_interceptor_js_1 = require("../shared/identity-error.interceptor.js");
|
|
36
37
|
const policy_service_js_1 = require("./policy.service.js");
|
|
37
38
|
let PolicyController = class PolicyController {
|
|
38
39
|
policies;
|
|
@@ -146,5 +147,6 @@ __decorate([
|
|
|
146
147
|
], PolicyController.prototype, "delete", null);
|
|
147
148
|
exports.PolicyController = PolicyController = __decorate([
|
|
148
149
|
(0, common_1.Controller)('identity'),
|
|
150
|
+
(0, common_1.UseInterceptors)(identity_error_interceptor_js_1.IdentityErrorInterceptor),
|
|
149
151
|
__metadata("design:paramtypes", [policy_service_js_1.PolicyService])
|
|
150
152
|
], PolicyController);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RoleService } from './role.service.js';
|
|
2
2
|
import { type ListQueryDto } from '../shared/list-query.js';
|
|
3
|
+
import type { AuthedRequest } from '../shared/http.js';
|
|
3
4
|
export declare class RoleController {
|
|
4
5
|
private readonly roles;
|
|
5
6
|
constructor(roles: RoleService);
|
|
@@ -24,13 +25,13 @@ export declare class RoleController {
|
|
|
24
25
|
* administrator, may read roles). */
|
|
25
26
|
getRole(uuid: string): Promise<import("packages/engine/dist/types.js").RecordView | null>;
|
|
26
27
|
/** Update a role — gated on `identity:role:update`. */
|
|
27
|
-
updateRole(uuid: string, body: {
|
|
28
|
+
updateRole(req: AuthedRequest, uuid: string, body: {
|
|
28
29
|
name?: string;
|
|
29
30
|
}): Promise<{
|
|
30
31
|
success: boolean;
|
|
31
32
|
}>;
|
|
32
33
|
/** Delete a role — gated on `identity:role:delete`. */
|
|
33
|
-
deleteRole(uuid: string): Promise<{
|
|
34
|
+
deleteRole(req: AuthedRequest, uuid: string): Promise<{
|
|
34
35
|
success: boolean;
|
|
35
36
|
}>;
|
|
36
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.controller.d.ts","sourceRoot":"","sources":["../../../src/features/role/role.controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"role.controller.d.ts","sourceRoot":"","sources":["../../../src/features/role/role.controller.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAOvD,qBAEa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,WAAW;IAE/C;;;;OAIG;IAGG,SAAS,CAAU,KAAK,EAAE,YAAY;;;;;;IAM5C,uDAAuD;IAGjD,UAAU,CAAS,IAAI,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;;;IAKhD;0CACsC;IAGtC,OAAO,CAAgB,IAAI,EAAE,MAAM;IAInC,uDAAuD;IAGjD,UAAU,CACP,GAAG,EAAE,aAAa,EACV,IAAI,EAAE,MAAM,EACnB,IAAI,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;;;IAMjC,uDAAuD;IAGjD,UAAU,CAAQ,GAAG,EAAE,aAAa,EAAiB,IAAI,EAAE,MAAM;;;CAIxE"}
|
|
@@ -17,9 +17,11 @@ const common_1 = require("@nestjs/common");
|
|
|
17
17
|
const guard_1 = require("@astram/guard");
|
|
18
18
|
const role_service_js_1 = require("./role.service.js");
|
|
19
19
|
const list_query_js_1 = require("../shared/list-query.js");
|
|
20
|
+
const identity_error_interceptor_js_1 = require("../shared/identity-error.interceptor.js");
|
|
20
21
|
// Role management is gated on `identity:role:<action>` grants. `role` is CONTROL-plane
|
|
21
22
|
// for ALL actions — including read: the capped root is the identity administrator (the
|
|
22
|
-
// identity-administrator model), so it may list/read roles AND manage them.
|
|
23
|
+
// identity-administrator model), so it may list/read roles AND manage them. Update/delete
|
|
24
|
+
// also pass the role-binding rule (a role used outside the caller's subtree is root-only).
|
|
23
25
|
let RoleController = class RoleController {
|
|
24
26
|
roles;
|
|
25
27
|
constructor(roles) {
|
|
@@ -46,13 +48,13 @@ let RoleController = class RoleController {
|
|
|
46
48
|
return this.roles.getRole(uuid);
|
|
47
49
|
}
|
|
48
50
|
/** Update a role — gated on `identity:role:update`. */
|
|
49
|
-
async updateRole(uuid, body) {
|
|
50
|
-
await this.roles.updateRole(uuid, body
|
|
51
|
+
async updateRole(req, uuid, body) {
|
|
52
|
+
await this.roles.updateRole(req.principal, uuid, { name: body?.name });
|
|
51
53
|
return { success: true };
|
|
52
54
|
}
|
|
53
55
|
/** Delete a role — gated on `identity:role:delete`. */
|
|
54
|
-
async deleteRole(uuid) {
|
|
55
|
-
await this.roles.deleteRole(uuid);
|
|
56
|
+
async deleteRole(req, uuid) {
|
|
57
|
+
await this.roles.deleteRole(req.principal, uuid);
|
|
56
58
|
return { success: true };
|
|
57
59
|
}
|
|
58
60
|
};
|
|
@@ -84,21 +86,24 @@ __decorate([
|
|
|
84
86
|
__decorate([
|
|
85
87
|
(0, common_1.Put)('roles/:uuid'),
|
|
86
88
|
(0, guard_1.Classified)({ typeKey: 'role', action: 'update' }),
|
|
87
|
-
__param(0, (0, common_1.
|
|
88
|
-
__param(1, (0, common_1.
|
|
89
|
+
__param(0, (0, common_1.Req)()),
|
|
90
|
+
__param(1, (0, common_1.Param)('uuid')),
|
|
91
|
+
__param(2, (0, common_1.Body)()),
|
|
89
92
|
__metadata("design:type", Function),
|
|
90
|
-
__metadata("design:paramtypes", [String, Object]),
|
|
93
|
+
__metadata("design:paramtypes", [Object, String, Object]),
|
|
91
94
|
__metadata("design:returntype", Promise)
|
|
92
95
|
], RoleController.prototype, "updateRole", null);
|
|
93
96
|
__decorate([
|
|
94
97
|
(0, common_1.Delete)('roles/:uuid'),
|
|
95
98
|
(0, guard_1.Classified)({ typeKey: 'role', action: 'delete' }),
|
|
96
|
-
__param(0, (0, common_1.
|
|
99
|
+
__param(0, (0, common_1.Req)()),
|
|
100
|
+
__param(1, (0, common_1.Param)('uuid')),
|
|
97
101
|
__metadata("design:type", Function),
|
|
98
|
-
__metadata("design:paramtypes", [String]),
|
|
102
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
99
103
|
__metadata("design:returntype", Promise)
|
|
100
104
|
], RoleController.prototype, "deleteRole", null);
|
|
101
105
|
exports.RoleController = RoleController = __decorate([
|
|
102
106
|
(0, common_1.Controller)('identity'),
|
|
107
|
+
(0, common_1.UseInterceptors)(identity_error_interceptor_js_1.IdentityErrorInterceptor),
|
|
103
108
|
__metadata("design:paramtypes", [role_service_js_1.RoleService])
|
|
104
109
|
], RoleController);
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
import { RecordsService, type RecordId } from '@astram/engine';
|
|
2
|
+
import type { Principal } from '@astram/core';
|
|
2
3
|
import { type ListParams } from '../shared/list-query.js';
|
|
4
|
+
import { GrantCeiling } from '../authz/grant-ceiling.js';
|
|
3
5
|
/**
|
|
4
6
|
* RoleService — role CRUD on the paved road, via the framework's RecordsService
|
|
5
|
-
* facade. The facade supplies the acting identity (the request principal)
|
|
6
|
-
*
|
|
7
|
+
* facade. The facade supplies the acting identity (the request principal) for the pipe;
|
|
8
|
+
* no raw SQL, no RECORD_ENGINE.
|
|
9
|
+
*
|
|
10
|
+
* Roles are a GLOBAL catalog, so renaming or deleting one changes every tenant that uses it (a
|
|
11
|
+
* delete cascades its postings). Security hardening #1 (D1 interim rule): update/delete first pass
|
|
12
|
+
* `GrantCeiling.assertRoleAdministrable` — the role must be bound inside the actor's subtree and
|
|
13
|
+
* nowhere outside it (a shared role is root-only). The engine's write wall still applies after.
|
|
7
14
|
*/
|
|
8
15
|
export declare class RoleService {
|
|
9
16
|
private readonly records;
|
|
10
|
-
|
|
17
|
+
private readonly ceiling;
|
|
18
|
+
constructor(records: RecordsService, ceiling: GrantCeiling);
|
|
11
19
|
/** Create a role. */
|
|
12
20
|
createRole(name: string): Promise<RecordId>;
|
|
13
21
|
/** List roles (tenant-scoped by the pipe), with paging/search/sort. */
|
|
14
22
|
listRoles(params?: ListParams): Promise<import("@astram/engine").RecordPage>;
|
|
15
23
|
/** Read a single role. */
|
|
16
24
|
getRole(uuid: string): Promise<import("@astram/engine").RecordView | null>;
|
|
17
|
-
/**
|
|
18
|
-
updateRole(uuid: string, patch: {
|
|
19
|
-
name?:
|
|
25
|
+
/** Rename a role — only a role the actor may administer (binding rule). Patch whitelisted. */
|
|
26
|
+
updateRole(actor: Principal, uuid: string, patch: {
|
|
27
|
+
name?: unknown;
|
|
20
28
|
}): Promise<void>;
|
|
21
|
-
/** Delete a role. */
|
|
22
|
-
deleteRole(uuid: string): Promise<void>;
|
|
29
|
+
/** Delete a role — only a role the actor may administer (binding rule). */
|
|
30
|
+
deleteRole(actor: Principal, uuid: string): Promise<void>;
|
|
23
31
|
}
|
|
24
32
|
//# sourceMappingURL=role.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"role.service.d.ts","sourceRoot":"","sources":["../../../src/features/role/role.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"role.service.d.ts","sourceRoot":"","sources":["../../../src/features/role/role.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAKzD;;;;;;;;;GASG;AACH,qBACa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,YAAY;IAGxC,qBAAqB;IACrB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI3C,uEAAuE;IACvE,SAAS,CAAC,MAAM,CAAC,EAAE,UAAU;IAI7B,0BAA0B;IAC1B,OAAO,CAAC,IAAI,EAAE,MAAM;IAIpB,8FAA8F;IACxF,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1F,2EAA2E;IACrE,UAAU,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAIhE"}
|
|
@@ -13,17 +13,25 @@ exports.RoleService = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const engine_1 = require("@astram/engine");
|
|
15
15
|
const list_query_js_1 = require("../shared/list-query.js");
|
|
16
|
+
const grant_ceiling_js_1 = require("../authz/grant-ceiling.js");
|
|
16
17
|
const ROLE_SEARCH_FIELDS = ['name'];
|
|
17
18
|
const ROLE_SORT_FIELDS = ['name', 'createdAt'];
|
|
18
19
|
/**
|
|
19
20
|
* RoleService — role CRUD on the paved road, via the framework's RecordsService
|
|
20
|
-
* facade. The facade supplies the acting identity (the request principal)
|
|
21
|
-
*
|
|
21
|
+
* facade. The facade supplies the acting identity (the request principal) for the pipe;
|
|
22
|
+
* no raw SQL, no RECORD_ENGINE.
|
|
23
|
+
*
|
|
24
|
+
* Roles are a GLOBAL catalog, so renaming or deleting one changes every tenant that uses it (a
|
|
25
|
+
* delete cascades its postings). Security hardening #1 (D1 interim rule): update/delete first pass
|
|
26
|
+
* `GrantCeiling.assertRoleAdministrable` — the role must be bound inside the actor's subtree and
|
|
27
|
+
* nowhere outside it (a shared role is root-only). The engine's write wall still applies after.
|
|
22
28
|
*/
|
|
23
29
|
let RoleService = class RoleService {
|
|
24
30
|
records;
|
|
25
|
-
|
|
31
|
+
ceiling;
|
|
32
|
+
constructor(records, ceiling) {
|
|
26
33
|
this.records = records;
|
|
34
|
+
this.ceiling = ceiling;
|
|
27
35
|
}
|
|
28
36
|
/** Create a role. */
|
|
29
37
|
createRole(name) {
|
|
@@ -37,17 +45,23 @@ let RoleService = class RoleService {
|
|
|
37
45
|
getRole(uuid) {
|
|
38
46
|
return this.records.get('role', uuid);
|
|
39
47
|
}
|
|
40
|
-
/**
|
|
41
|
-
updateRole(uuid, patch) {
|
|
42
|
-
|
|
48
|
+
/** Rename a role — only a role the actor may administer (binding rule). Patch whitelisted. */
|
|
49
|
+
async updateRole(actor, uuid, patch) {
|
|
50
|
+
await this.ceiling.assertRoleAdministrable(actor, uuid);
|
|
51
|
+
const fields = {};
|
|
52
|
+
if (typeof patch?.name === 'string')
|
|
53
|
+
fields.name = patch.name;
|
|
54
|
+
await this.records.update('role', uuid, { fields });
|
|
43
55
|
}
|
|
44
|
-
/** Delete a role. */
|
|
45
|
-
deleteRole(uuid) {
|
|
46
|
-
|
|
56
|
+
/** Delete a role — only a role the actor may administer (binding rule). */
|
|
57
|
+
async deleteRole(actor, uuid) {
|
|
58
|
+
await this.ceiling.assertRoleAdministrable(actor, uuid);
|
|
59
|
+
await this.records.delete('role', uuid);
|
|
47
60
|
}
|
|
48
61
|
};
|
|
49
62
|
exports.RoleService = RoleService;
|
|
50
63
|
exports.RoleService = RoleService = __decorate([
|
|
51
64
|
(0, common_1.Injectable)(),
|
|
52
|
-
__metadata("design:paramtypes", [engine_1.RecordsService
|
|
65
|
+
__metadata("design:paramtypes", [engine_1.RecordsService,
|
|
66
|
+
grant_ceiling_js_1.GrantCeiling])
|
|
53
67
|
], RoleService);
|