@aglyn/plugins-data 1.13.0 → 1.14.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.
Files changed (26) hide show
  1. package/package.json +10 -10
  2. package/src/lib/artifact/dataset-schema-artifact.server.js +6 -3
  3. package/src/lib/artifact/dataset-schema-artifact.server.js.map +1 -1
  4. package/src/lib/components/dataset-schema-dialog.component.js +173 -128
  5. package/src/lib/components/dataset-schema-dialog.component.js.map +1 -1
  6. package/src/lib/components/host-datasets-card.component.js +1 -1
  7. package/src/lib/components/host-datasets-card.component.js.map +1 -1
  8. package/src/lib/components/use-dataset-writes-blocked.d.ts +5 -4
  9. package/src/lib/components/use-dataset-writes-blocked.js +11 -12
  10. package/src/lib/components/use-dataset-writes-blocked.js.map +1 -1
  11. package/src/lib/model/dataset-record.js +8 -3
  12. package/src/lib/model/dataset-record.js.map +1 -1
  13. package/src/lib/server/dataset-access.server.d.ts +4 -3
  14. package/src/lib/server/dataset-access.server.js +7 -5
  15. package/src/lib/server/dataset-access.server.js.map +1 -1
  16. package/src/lib/server/dataset-site-erasure.d.ts +2 -2
  17. package/src/lib/server/dataset-site-erasure.js +4 -26
  18. package/src/lib/server/dataset-site-erasure.js.map +1 -1
  19. package/src/lib/server/datasets-route.d.ts +2 -0
  20. package/src/lib/server/datasets-route.js +123 -18
  21. package/src/lib/server/datasets-route.js.map +1 -1
  22. package/src/lib/site-bundle/datasets-site-bundle.server.d.ts +4 -2
  23. package/src/lib/site-bundle/datasets-site-bundle.server.js +8 -4
  24. package/src/lib/site-bundle/datasets-site-bundle.server.js.map +1 -1
  25. package/src/lib/transfer/dataset-transfer-access.server.js +3 -3
  26. package/src/lib/transfer/dataset-transfer-access.server.js.map +1 -1
@@ -15,6 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { type AglynOrgCustomRole, type OrgPermission, resolveOrgPermissions } from '@aglyn/aglyn/app-utils/org-permissions';
18
+ import { type ScopePlaced } from '@aglyn/aglyn/app-utils/site-placement';
18
19
  import type { TransferInstanceImportAnswer, TransferInstanceImportSubject } from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources';
19
20
  /** What the doors read off a membership document. */
20
21
  type DatasetWriter = NonNullable<Parameters<typeof resolveOrgPermissions>[0]> & {
@@ -60,12 +61,12 @@ export interface DatasetAccessBlocked {
60
61
  exports: boolean;
61
62
  }
62
63
  /**
63
- * The verdict for a member and a dataset placed at `visibleTo`, as the rule's
64
+ * The verdict for a member and a dataset, as its document places it, as the rule's
64
65
  * `canWriteDatasetOn` and the routes' `memberMayActOnDataset` give it, resolved
65
66
  * from what the site's stamp is written from. `customRole` is the member's custom
66
67
  * role when they carry one and it was read.
67
68
  */
68
- export declare function datasetAccessBlocked(member: DatasetWriter, visibleTo: unknown, customRole?: AglynOrgCustomRole | null): DatasetAccessBlocked;
69
+ export declare function datasetAccessBlocked(member: DatasetWriter, placed: ScopePlaced | null | undefined, customRole?: AglynOrgCustomRole | null): DatasetAccessBlocked;
69
70
  /**
70
71
  * Importing into one dataset, for the Import & export hub's row (AGL-4047): the
71
72
  * same verdict the Data page's Import reads, and the transfer routes' `importAccess`.
@@ -73,12 +74,12 @@ export declare function datasetAccessBlocked(member: DatasetWriter, visibleTo: u
73
74
  export declare function datasetInstanceImportAccess(subject: TransferInstanceImportSubject): TransferInstanceImportAnswer;
74
75
  /**
75
76
  * Which dataset controls switch off with the reason named rather than failing on
76
- * save, for the dataset placed at `visibleTo`. Nothing is blocked until the reads
77
+ * save, for this dataset, as its document places it. Nothing is blocked until the reads
77
78
  * land, nor for a reader with no membership, who is staff. Not a security
78
79
  * boundary: the rules and routes refuse regardless.
79
80
  *
80
81
  * Costs the membership the page already reads, and one read of a custom role
81
82
  * only for a member of the whole workspace whom the site decides.
82
83
  */
83
- export declare function useDatasetWritesBlocked(orgId: string | null | undefined, visibleTo?: unknown): DatasetAccessBlocked;
84
+ export declare function useDatasetWritesBlocked(orgId: string | null | undefined, placed?: ScopePlaced | null): DatasetAccessBlocked;
84
85
  export {};
@@ -50,26 +50,26 @@ const NOTHING_BLOCKED = {
50
50
  exports: false
51
51
  };
52
52
  /**
53
- * The verdict for a member and a dataset placed at `visibleTo`, as the rule's
53
+ * The verdict for a member and a dataset, as its document places it, as the rule's
54
54
  * `canWriteDatasetOn` and the routes' `memberMayActOnDataset` give it, resolved
55
55
  * from what the site's stamp is written from. `customRole` is the member's custom
56
56
  * role when they carry one and it was read.
57
- */ export function datasetAccessBlocked(member, visibleTo, customRole) {
57
+ */ export function datasetAccessBlocked(member, placed, customRole) {
58
58
  const seat = member;
59
- const site = oneSitePlacement(visibleTo);
59
+ const site = oneSitePlacement(placed);
60
60
  const writes = placementVerdict({
61
61
  member: seat,
62
- visibleTo,
62
+ placed,
63
63
  workspace: holdsDatasetPermission(member, DATA_MANAGE_PERMISSION),
64
64
  site: (hostId)=>resolvedPlacementKey(seat, hostId, DATA_SITE_MANAGE_PERMISSION, customRole)
65
65
  });
66
66
  const deletes = placementVerdict({
67
67
  member: seat,
68
- visibleTo,
68
+ placed,
69
69
  workspace: holdsDatasetPermission(member, DATA_ERASE_PERMISSION),
70
70
  site: (hostId)=>resolvedPlacementKey(seat, hostId, DATA_SITE_DELETE_PERMISSION, customRole)
71
71
  });
72
- const beyond = deleteBeyondReach(seat, visibleTo);
72
+ const beyond = deleteBeyondReach(seat, placed);
73
73
  const holdsManage = holdsDatasetPermission(member, DATA_MANAGE_PERMISSION);
74
74
  return {
75
75
  known: true,
@@ -87,8 +87,7 @@ const NOTHING_BLOCKED = {
87
87
  * Importing into one dataset, for the Import & export hub's row (AGL-4047): the
88
88
  * same verdict the Data page's Import reads, and the transfer routes' `importAccess`.
89
89
  */ export function datasetInstanceImportAccess(subject) {
90
- var _subject_record_facts;
91
- const blocked = datasetAccessBlocked(subject.member, (_subject_record_facts = subject.record.facts) == null ? void 0 : _subject_record_facts['visibleTo'], subject.customRole);
90
+ const blocked = datasetAccessBlocked(subject.member, subject.record.facts, subject.customRole);
92
91
  return {
93
92
  allowed: !blocked.writes,
94
93
  reason: blocked.writesReason
@@ -96,13 +95,13 @@ const NOTHING_BLOCKED = {
96
95
  }
97
96
  /**
98
97
  * Which dataset controls switch off with the reason named rather than failing on
99
- * save, for the dataset placed at `visibleTo`. Nothing is blocked until the reads
98
+ * save, for this dataset, as its document places it. Nothing is blocked until the reads
100
99
  * land, nor for a reader with no membership, who is staff. Not a security
101
100
  * boundary: the rules and routes refuse regardless.
102
101
  *
103
102
  * Costs the membership the page already reads, and one read of a custom role
104
103
  * only for a member of the whole workspace whom the site decides.
105
- */ export function useDatasetWritesBlocked(orgId, visibleTo) {
104
+ */ export function useDatasetWritesBlocked(orgId, placed) {
106
105
  var _ref, _role_data;
107
106
  const firestore = useFirestore();
108
107
  const { data: user } = useUser();
@@ -113,7 +112,7 @@ const NOTHING_BLOCKED = {
113
112
  uid
114
113
  ]);
115
114
  const seat = status === 'success' ? member : null;
116
- const site = oneSitePlacement(visibleTo);
115
+ const site = oneSitePlacement(placed);
117
116
  // Only someone the site decides: narrowed on it, or on a role wider or narrower here.
118
117
  const siteDecides = Boolean(seat && site) && isOrgWideMember(seat) && (Boolean(siteMayNarrow(seat, site)) || !holdsDatasetPermission(seat, DATA_MANAGE_PERMISSION));
119
118
  const roleId = siteDecides && typeof (seat == null ? void 0 : seat.roleId) === 'string' ? seat.roleId : '';
@@ -123,7 +122,7 @@ const NOTHING_BLOCKED = {
123
122
  roleId
124
123
  ]);
125
124
  if (!seat || roleId && role.status === 'loading') return NOTHING_BLOCKED;
126
- return datasetAccessBlocked(seat, visibleTo, roleId && role.status === 'success' ? (_role_data = role.data) != null ? _role_data : null : null);
125
+ return datasetAccessBlocked(seat, placed, roleId && role.status === 'success' ? (_role_data = role.data) != null ? _role_data : null : null);
127
126
  }
128
127
 
129
128
  //# sourceMappingURL=use-dataset-writes-blocked.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/components/use-dataset-writes-blocked.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type AglynOrgCustomRole,\n type OrgPermission,\n permissionRefusalText,\n resolveOrgPermissions,\n} from '@aglyn/aglyn/app-utils/org-permissions'\nimport { siteMayNarrow } from '@aglyn/aglyn/app-utils/host-permissions'\nimport { isOrgWideMember } from '@aglyn/aglyn/app-utils/organizations'\nimport {\n deleteBeyondReach,\n deleteBeyondReachRefusal,\n oneSitePlacement,\n placementVerdict,\n resolvedPlacementKey,\n} from '@aglyn/aglyn/app-utils/site-placement'\nimport type { AglynOrgMember } from '@aglyn/aglyn/foundation/definitions/organization.types'\nimport type {\n TransferInstanceImportAnswer,\n TransferInstanceImportSubject,\n} from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources'\nimport { useFirestore, useFirestoreDoc, useUser } from '@aglyn/tenant-feature-instance'\nimport { doc } from 'firebase/firestore'\nimport {\n DATA_ERASE_PERMISSION,\n DATA_EXPORT_PERMISSION,\n DATA_MANAGE_PERMISSION,\n DATA_SITE_DELETE_PERMISSION,\n DATA_SITE_MANAGE_PERMISSION,\n DATA_VIEW_RECORDS_PERMISSION,\n dataPermissionRefusal,\n} from '../model/dataset-access'\n\n/** What the doors read off a membership document. */\ntype DatasetWriter = NonNullable<Parameters<typeof resolveOrgPermissions>[0]> & {\n resolvedPermissions?: Readonly<Record<string, unknown>>\n permissions?: Readonly<Record<string, unknown>>\n}\n\n/** Creating, editing and sharing datasets, and every record write. */\nexport const DATASETS_WRITE_PERMISSION: OrgPermission = DATA_MANAGE_PERMISSION\n/** Deleting a whole dataset, which the erase route asks. */\nexport const DATASETS_DELETE_PERMISSION: OrgPermission = DATA_ERASE_PERMISSION\n\nexport const DATASETS_WRITE_REFUSAL = permissionRefusalText(DATASETS_WRITE_PERMISSION)\nexport const DATASETS_DELETE_REFUSAL = permissionRefusalText(DATASETS_DELETE_PERMISSION)\nexport const DATASETS_VIEW_RECORDS_REFUSAL = dataPermissionRefusal(DATA_VIEW_RECORDS_PERMISSION)\nexport const DATASETS_EXPORT_REFUSAL = dataPermissionRefusal(DATA_EXPORT_PERMISSION)\n\n/**\n * A member's answer for a dataset key (AGL-4047), as the rules' `memberKeyOrOverride`\n * and the routes' `memberHasOrgPermission` read it: the decision written on\n * `resolvedPermissions`, or, for a member the projection never stamped, on their\n * own `permissions`; else their workspace role's default.\n */\nexport function holdsDatasetPermission(member: DatasetWriter, permission: OrgPermission): boolean {\n const stamped = (member.resolvedPermissions ?? member.permissions)?.[permission]\n if (typeof stamped === 'boolean') return stamped\n return resolveOrgPermissions(member)[permission] === true\n}\n\n/** What the signed-in member is known not to be able to do with a dataset, and why. */\nexport interface DatasetAccessBlocked {\n /** Whether these answers rest on the member's reads, rather than on their not having landed. */\n known: boolean\n /** Making a new dataset: \"Manage data\". */\n creates: boolean\n /** Changing this dataset's schema or records, or importing into it. */\n writes: boolean\n writesReason: string\n /**\n * The writes are off, and changing who it is shared with stays this member's:\n * they hold \"Manage data\" across every site, and a site narrows them on the one\n * this dataset sits on. Sharing is not among what a narrowing takes.\n */\n sharingOnly: boolean\n /** Deleting this dataset. */\n deletes: boolean\n deletesReason: string\n /** Reading this dataset's records. */\n records: boolean\n /** Taking this dataset's records out as a file. */\n exports: boolean\n}\n\nconst NOTHING_BLOCKED: DatasetAccessBlocked = {\n known: false,\n creates: false,\n writes: false,\n writesReason: DATASETS_WRITE_REFUSAL,\n sharingOnly: false,\n deletes: false,\n deletesReason: DATASETS_DELETE_REFUSAL,\n records: false,\n exports: false,\n}\n\n/**\n * The verdict for a member and a dataset placed at `visibleTo`, as the rule's\n * `canWriteDatasetOn` and the routes' `memberMayActOnDataset` give it, resolved\n * from what the site's stamp is written from. `customRole` is the member's custom\n * role when they carry one and it was read.\n */\nexport function datasetAccessBlocked(\n member: DatasetWriter,\n visibleTo: unknown,\n customRole?: AglynOrgCustomRole | null,\n): DatasetAccessBlocked {\n const seat = member as Partial<AglynOrgMember>\n const site = oneSitePlacement(visibleTo)\n const writes = placementVerdict<boolean>({\n member: seat,\n visibleTo,\n workspace: holdsDatasetPermission(member, DATA_MANAGE_PERMISSION),\n site: (hostId) => resolvedPlacementKey(seat, hostId, DATA_SITE_MANAGE_PERMISSION, customRole),\n })\n const deletes = placementVerdict<boolean>({\n member: seat,\n visibleTo,\n workspace: holdsDatasetPermission(member, DATA_ERASE_PERMISSION),\n site: (hostId) => resolvedPlacementKey(seat, hostId, DATA_SITE_DELETE_PERMISSION, customRole),\n })\n const beyond = deleteBeyondReach(seat, visibleTo)\n const holdsManage = holdsDatasetPermission(member, DATA_MANAGE_PERMISSION)\n return {\n known: true,\n creates: !holdsManage,\n writes: !writes,\n sharingOnly: !writes && holdsManage && isOrgWideMember(seat),\n writesReason: site ? dataPermissionRefusal(DATA_SITE_MANAGE_PERMISSION) : DATASETS_WRITE_REFUSAL,\n deletes: beyond || !deletes,\n deletesReason: beyond\n ? deleteBeyondReachRefusal('dataset')\n : site\n ? dataPermissionRefusal(DATA_SITE_DELETE_PERMISSION)\n : DATASETS_DELETE_REFUSAL,\n records: !holdsDatasetPermission(member, DATA_VIEW_RECORDS_PERMISSION),\n exports: !holdsDatasetPermission(member, DATA_EXPORT_PERMISSION),\n }\n}\n\n/**\n * Importing into one dataset, for the Import & export hub's row (AGL-4047): the\n * same verdict the Data page's Import reads, and the transfer routes' `importAccess`.\n */\nexport function datasetInstanceImportAccess(subject: TransferInstanceImportSubject): TransferInstanceImportAnswer {\n const blocked = datasetAccessBlocked(\n subject.member as DatasetWriter,\n subject.record.facts?.['visibleTo'],\n subject.customRole as AglynOrgCustomRole | null,\n )\n return { allowed: !blocked.writes, reason: blocked.writesReason }\n}\n\n/**\n * Which dataset controls switch off with the reason named rather than failing on\n * save, for the dataset placed at `visibleTo`. Nothing is blocked until the reads\n * land, nor for a reader with no membership, who is staff. Not a security\n * boundary: the rules and routes refuse regardless.\n *\n * Costs the membership the page already reads, and one read of a custom role\n * only for a member of the whole workspace whom the site decides.\n */\nexport function useDatasetWritesBlocked(\n orgId: string | null | undefined,\n visibleTo?: unknown,\n): DatasetAccessBlocked {\n const firestore = useFirestore()\n const { data: user } = useUser()\n const uid = (user as { uid?: string } | undefined)?.uid ?? ''\n const { data: member, status } = useFirestoreDoc<DatasetWriter>(\n () => (orgId && uid ? doc(firestore, 'orgs', orgId, 'members', uid) : null),\n [firestore, orgId, uid],\n )\n const seat = (status === 'success' ? member : null) as (DatasetWriter & { roleId?: unknown }) | null | undefined\n const site = oneSitePlacement(visibleTo)\n // Only someone the site decides: narrowed on it, or on a role wider or narrower here.\n const siteDecides =\n Boolean(seat && site) &&\n isOrgWideMember(seat as Partial<AglynOrgMember>) &&\n (Boolean(siteMayNarrow(seat as Partial<AglynOrgMember>, site)) || !holdsDatasetPermission(seat as DatasetWriter, DATA_MANAGE_PERMISSION))\n const roleId = siteDecides && typeof seat?.roleId === 'string' ? seat.roleId : ''\n const role = useFirestoreDoc<AglynOrgCustomRole>(\n () => (orgId && roleId ? doc(firestore, 'orgs', orgId, 'roles', roleId) : null),\n [firestore, orgId, roleId],\n )\n if (!seat || (roleId && role.status === 'loading')) return NOTHING_BLOCKED\n return datasetAccessBlocked(seat, visibleTo, roleId && role.status === 'success' ? (role.data ?? null) : null)\n}\n"],"names":["permissionRefusalText","resolveOrgPermissions","siteMayNarrow","isOrgWideMember","deleteBeyondReach","deleteBeyondReachRefusal","oneSitePlacement","placementVerdict","resolvedPlacementKey","useFirestore","useFirestoreDoc","useUser","doc","DATA_ERASE_PERMISSION","DATA_EXPORT_PERMISSION","DATA_MANAGE_PERMISSION","DATA_SITE_DELETE_PERMISSION","DATA_SITE_MANAGE_PERMISSION","DATA_VIEW_RECORDS_PERMISSION","dataPermissionRefusal","DATASETS_WRITE_PERMISSION","DATASETS_DELETE_PERMISSION","DATASETS_WRITE_REFUSAL","DATASETS_DELETE_REFUSAL","DATASETS_VIEW_RECORDS_REFUSAL","DATASETS_EXPORT_REFUSAL","holdsDatasetPermission","member","permission","stamped","resolvedPermissions","permissions","NOTHING_BLOCKED","known","creates","writes","writesReason","sharingOnly","deletes","deletesReason","records","exports","datasetAccessBlocked","visibleTo","customRole","seat","site","workspace","hostId","beyond","holdsManage","datasetInstanceImportAccess","subject","blocked","record","facts","allowed","reason","useDatasetWritesBlocked","orgId","role","firestore","data","user","uid","status","siteDecides","Boolean","roleId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAGEA,qBAAqB,EACrBC,qBAAqB,QAChB,yCAAwC;AAC/C,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,eAAe,QAAQ,uCAAsC;AACtE,SACEC,iBAAiB,EACjBC,wBAAwB,EACxBC,gBAAgB,EAChBC,gBAAgB,EAChBC,oBAAoB,QACf,wCAAuC;AAM9C,SAASC,YAAY,EAAEC,eAAe,EAAEC,OAAO,QAAQ,iCAAgC;AACvF,SAASC,GAAG,QAAQ,qBAAoB;AACxC,SACEC,qBAAqB,EACrBC,sBAAsB,EACtBC,sBAAsB,EACtBC,2BAA2B,EAC3BC,2BAA2B,EAC3BC,4BAA4B,EAC5BC,qBAAqB,QAChB,6BAAyB;AAQhC,oEAAoE,GACpE,OAAO,MAAMC,4BAA2CL,uBAAsB;AAC9E,0DAA0D,GAC1D,OAAO,MAAMM,6BAA4CR,sBAAqB;AAE9E,OAAO,MAAMS,yBAAyBtB,sBAAsBoB,2BAA0B;AACtF,OAAO,MAAMG,0BAA0BvB,sBAAsBqB,4BAA2B;AACxF,OAAO,MAAMG,gCAAgCL,sBAAsBD,8BAA6B;AAChG,OAAO,MAAMO,0BAA0BN,sBA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,OAAOjC;IAC3D,OAAOU,qBAAqBG,MAAMF,WAAWyB,UAAUR,KAAKK,MAAM,KAAK,aAAaL,aAAAA,KAAKE,IAAI,YAATF,aAAa,OAAQ;AAC3G"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/components/use-dataset-writes-blocked.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type AglynOrgCustomRole,\n type OrgPermission,\n permissionRefusalText,\n resolveOrgPermissions,\n} from '@aglyn/aglyn/app-utils/org-permissions'\nimport { siteMayNarrow } from '@aglyn/aglyn/app-utils/host-permissions'\nimport { isOrgWideMember } from '@aglyn/aglyn/app-utils/organizations'\nimport {\n deleteBeyondReach,\n deleteBeyondReachRefusal,\n oneSitePlacement,\n placementVerdict,\n resolvedPlacementKey,\n type ScopePlaced,\n} from '@aglyn/aglyn/app-utils/site-placement'\nimport type { AglynOrgMember } from '@aglyn/aglyn/foundation/definitions/organization.types'\nimport type {\n TransferInstanceImportAnswer,\n TransferInstanceImportSubject,\n} from '@aglyn/aglyn/plugin-manager/plugin-transfer-resources'\nimport { useFirestore, useFirestoreDoc, useUser } from '@aglyn/tenant-feature-instance'\nimport { doc } from 'firebase/firestore'\nimport {\n DATA_ERASE_PERMISSION,\n DATA_EXPORT_PERMISSION,\n DATA_MANAGE_PERMISSION,\n DATA_SITE_DELETE_PERMISSION,\n DATA_SITE_MANAGE_PERMISSION,\n DATA_VIEW_RECORDS_PERMISSION,\n dataPermissionRefusal,\n} from '../model/dataset-access'\n\n/** What the doors read off a membership document. */\ntype DatasetWriter = NonNullable<Parameters<typeof resolveOrgPermissions>[0]> & {\n resolvedPermissions?: Readonly<Record<string, unknown>>\n permissions?: Readonly<Record<string, unknown>>\n}\n\n/** Creating, editing and sharing datasets, and every record write. */\nexport const DATASETS_WRITE_PERMISSION: OrgPermission = DATA_MANAGE_PERMISSION\n/** Deleting a whole dataset, which the erase route asks. */\nexport const DATASETS_DELETE_PERMISSION: OrgPermission = DATA_ERASE_PERMISSION\n\nexport const DATASETS_WRITE_REFUSAL = permissionRefusalText(DATASETS_WRITE_PERMISSION)\nexport const DATASETS_DELETE_REFUSAL = permissionRefusalText(DATASETS_DELETE_PERMISSION)\nexport const DATASETS_VIEW_RECORDS_REFUSAL = dataPermissionRefusal(DATA_VIEW_RECORDS_PERMISSION)\nexport const DATASETS_EXPORT_REFUSAL = dataPermissionRefusal(DATA_EXPORT_PERMISSION)\n\n/**\n * A member's answer for a dataset key (AGL-4047), as the rules' `memberKeyOrOverride`\n * and the routes' `memberHasOrgPermission` read it: the decision written on\n * `resolvedPermissions`, or, for a member the projection never stamped, on their\n * own `permissions`; else their workspace role's default.\n */\nexport function holdsDatasetPermission(member: DatasetWriter, permission: OrgPermission): boolean {\n const stamped = (member.resolvedPermissions ?? member.permissions)?.[permission]\n if (typeof stamped === 'boolean') return stamped\n return resolveOrgPermissions(member)[permission] === true\n}\n\n/** What the signed-in member is known not to be able to do with a dataset, and why. */\nexport interface DatasetAccessBlocked {\n /** Whether these answers rest on the member's reads, rather than on their not having landed. */\n known: boolean\n /** Making a new dataset: \"Manage data\". */\n creates: boolean\n /** Changing this dataset's schema or records, or importing into it. */\n writes: boolean\n writesReason: string\n /**\n * The writes are off, and changing who it is shared with stays this member's:\n * they hold \"Manage data\" across every site, and a site narrows them on the one\n * this dataset sits on. Sharing is not among what a narrowing takes.\n */\n sharingOnly: boolean\n /** Deleting this dataset. */\n deletes: boolean\n deletesReason: string\n /** Reading this dataset's records. */\n records: boolean\n /** Taking this dataset's records out as a file. */\n exports: boolean\n}\n\nconst NOTHING_BLOCKED: DatasetAccessBlocked = {\n known: false,\n creates: false,\n writes: false,\n writesReason: DATASETS_WRITE_REFUSAL,\n sharingOnly: false,\n deletes: false,\n deletesReason: DATASETS_DELETE_REFUSAL,\n records: false,\n exports: false,\n}\n\n/**\n * The verdict for a member and a dataset, as its document places it, as the rule's\n * `canWriteDatasetOn` and the routes' `memberMayActOnDataset` give it, resolved\n * from what the site's stamp is written from. `customRole` is the member's custom\n * role when they carry one and it was read.\n */\nexport function datasetAccessBlocked(\n member: DatasetWriter,\n placed: ScopePlaced | null | undefined,\n customRole?: AglynOrgCustomRole | null,\n): DatasetAccessBlocked {\n const seat = member as Partial<AglynOrgMember>\n const site = oneSitePlacement(placed)\n const writes = placementVerdict<boolean>({\n member: seat,\n placed,\n workspace: holdsDatasetPermission(member, DATA_MANAGE_PERMISSION),\n site: (hostId) => resolvedPlacementKey(seat, hostId, DATA_SITE_MANAGE_PERMISSION, customRole),\n })\n const deletes = placementVerdict<boolean>({\n member: seat,\n placed,\n workspace: holdsDatasetPermission(member, DATA_ERASE_PERMISSION),\n site: (hostId) => resolvedPlacementKey(seat, hostId, DATA_SITE_DELETE_PERMISSION, customRole),\n })\n const beyond = deleteBeyondReach(seat, placed)\n const holdsManage = holdsDatasetPermission(member, DATA_MANAGE_PERMISSION)\n return {\n known: true,\n creates: !holdsManage,\n writes: !writes,\n sharingOnly: !writes && holdsManage && isOrgWideMember(seat),\n writesReason: site ? dataPermissionRefusal(DATA_SITE_MANAGE_PERMISSION) : DATASETS_WRITE_REFUSAL,\n deletes: beyond || !deletes,\n deletesReason: beyond\n ? deleteBeyondReachRefusal('dataset')\n : site\n ? dataPermissionRefusal(DATA_SITE_DELETE_PERMISSION)\n : DATASETS_DELETE_REFUSAL,\n records: !holdsDatasetPermission(member, DATA_VIEW_RECORDS_PERMISSION),\n exports: !holdsDatasetPermission(member, DATA_EXPORT_PERMISSION),\n }\n}\n\n/**\n * Importing into one dataset, for the Import & export hub's row (AGL-4047): the\n * same verdict the Data page's Import reads, and the transfer routes' `importAccess`.\n */\nexport function datasetInstanceImportAccess(subject: TransferInstanceImportSubject): TransferInstanceImportAnswer {\n const blocked = datasetAccessBlocked(\n subject.member as DatasetWriter,\n subject.record.facts,\n subject.customRole as AglynOrgCustomRole | null,\n )\n return { allowed: !blocked.writes, reason: blocked.writesReason }\n}\n\n/**\n * Which dataset controls switch off with the reason named rather than failing on\n * save, for this dataset, as its document places it. Nothing is blocked until the reads\n * land, nor for a reader with no membership, who is staff. Not a security\n * boundary: the rules and routes refuse regardless.\n *\n * Costs the membership the page already reads, and one read of a custom role\n * only for a member of the whole workspace whom the site decides.\n */\nexport function useDatasetWritesBlocked(\n orgId: string | null | undefined,\n placed?: ScopePlaced | null,\n): DatasetAccessBlocked {\n const firestore = useFirestore()\n const { data: user } = useUser()\n const uid = (user as { uid?: string } | undefined)?.uid ?? ''\n const { data: member, status } = useFirestoreDoc<DatasetWriter>(\n () => (orgId && uid ? doc(firestore, 'orgs', orgId, 'members', uid) : null),\n [firestore, orgId, uid],\n )\n const seat = (status === 'success' ? member : null) as (DatasetWriter & { roleId?: unknown }) | null | undefined\n const site = oneSitePlacement(placed)\n // Only someone the site decides: narrowed on it, or on a role wider or narrower here.\n const siteDecides =\n Boolean(seat && site) &&\n isOrgWideMember(seat as Partial<AglynOrgMember>) &&\n (Boolean(siteMayNarrow(seat as Partial<AglynOrgMember>, site)) || !holdsDatasetPermission(seat as DatasetWriter, DATA_MANAGE_PERMISSION))\n const roleId = siteDecides && typeof seat?.roleId === 'string' ? seat.roleId : ''\n const role = useFirestoreDoc<AglynOrgCustomRole>(\n () => (orgId && roleId ? doc(firestore, 'orgs', orgId, 'roles', roleId) : null),\n [firestore, orgId, roleId],\n )\n if (!seat || (roleId && role.status === 'loading')) return NOTHING_BLOCKED\n return datasetAccessBlocked(seat, placed, roleId && role.status === 'success' ? (role.data ?? null) : null)\n}\n"],"names":["permissionRefusalText","resolveOrgPermissions","siteMayNarrow","isOrgWideMember","deleteBeyondReach","deleteBeyondReachRefusal","oneSitePlacement","placementVerdict","resolvedPlacementKey","useFirestore","useFirestoreDoc","useUser","doc","DATA_ERASE_PERMISSION","DATA_EXPORT_PERMISSION","DATA_MANAGE_PERMISSION","DATA_SITE_DELETE_PERMISSION","DATA_SITE_MANAGE_PERMISSION","DATA_VIEW_RECORDS_PERMISSION","dataPermissionRefusal","DATASETS_WRITE_PERMISSION","DATASETS_DELETE_PERMISSION","DATASETS_WRITE_REFUSAL","DATASETS_DELETE_REFUSAL","DATASETS_VIEW_RECORDS_REFUSAL","DATASETS_EXPORT_REFUSAL","holdsDatasetPermission","member","permission","stamped","resolvedPermissions","permissions","NOTHING_BLOCKED","known","creates","writes","writesReason","sharingOnly","deletes","deletesReason","records","exports","datasetAccessBlocked","placed","customRole","seat","site","workspace","hostId","beyond","holdsManage","datasetInstanceImportAccess","subject","blocked","record","facts","allowed","reason","useDatasetWritesBlocked","orgId","role","firestore","data","user","uid","status","siteDecides","Boolean","roleId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAGEA,qBAAqB,EACrBC,qBAAqB,QAChB,yCAAwC;AAC/C,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,eAAe,QAAQ,uCAAsC;AACtE,SACEC,iBAAiB,EACjBC,wBAAwB,EACxBC,gBAAgB,EAChBC,gBAAgB,EAChBC,oBAAoB,QAEf,wCAAuC;AAM9C,SAASC,YAAY,EAAEC,eAAe,EAAEC,OAAO,QAAQ,iCAAgC;AACvF,SAASC,GAAG,QAAQ,qBAAoB;AACxC,SACEC,qBAAqB,EACrBC,sBAAsB,EACtBC,sBAAsB,EACtBC,2BAA2B,EAC3BC,2BAA2B,EAC3BC,4BAA4B,EAC5BC,qBAAqB,QAChB,6BAAyB;AAQhC,oEAAoE,GACpE,OAAO,MAAMC,4BAA2CL,uBAAsB;AAC9E,0DAA0D,GAC1D,OAAO,MAAMM,6BAA4CR,sBAAqB;AAE9E,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D,WAAW,QAAQF,OAAO,SAASS,UAAU,MAC1E;QAACP;QAAWF;QAAOS;KAAO;IAE5B,IAAI,CAACvB,QAASuB,UAAUR,KAAKK,MAAM,KAAK,WAAY,OAAOjC;IAC3D,OAAOU,qBAAqBG,MAAMF,QAAQyB,UAAUR,KAAKK,MAAM,KAAK,aAAaL,aAAAA,KAAKE,IAAI,YAATF,aAAa,OAAQ;AACxG"}
@@ -37,7 +37,7 @@ import { datasetDisplayName } from "./datasets.js";
37
37
  return {
38
38
  id,
39
39
  name: datasetDisplayName(data) || id,
40
- facts: {
40
+ facts: _extends({
41
41
  fields: model.order.map((fieldId)=>{
42
42
  var _ref;
43
43
  var _model_fields_fieldId, _model_fields_fieldId1, _model_fields_fieldId2, _model_fields_fieldId3;
@@ -49,9 +49,14 @@ import { datasetDisplayName } from "./datasets.js";
49
49
  customType: String((_model_fields_fieldId3 = model.fields[fieldId]) == null ? void 0 : _model_fields_fieldId3.customType)
50
50
  } : {});
51
51
  }),
52
- visibleTo: Array.isArray(data['visibleTo']) ? data['visibleTo'] : [],
52
+ visibleTo: Array.isArray(data['visibleTo']) ? data['visibleTo'] : []
53
+ }, data['scopeMode'] !== undefined ? {
54
+ scopeMode: data['scopeMode']
55
+ } : {}, data['scopeExcept'] !== undefined ? {
56
+ scopeExcept: data['scopeExcept']
57
+ } : {}, {
53
58
  installedFrom: installedFrom(data['source'])
54
- }
59
+ })
55
60
  };
56
61
  }
57
62
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/model/dataset-record.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PluginIndexedRecord } from '@aglyn/aglyn/plugin-manager/plugin-record-index'\nimport { type DatasetModel, effectiveDatasetModel } from './dataset-models'\nimport { datasetDisplayName } from './datasets'\n\n/**\n * One stored dataset as this plugin shares it with another (AGL-3080) — the\n * one shape its server index (`dataset-record-index.ts`) and its console list\n * source (`dataset-record-list.ts`) both answer, so a reader on either side\n * reads the same record.\n *\n * `null` for a deleted dataset. Otherwise its id, its name as the Data page\n * shows it, and `facts`:\n * `fields` — its fields in the dataset page's order, each\n * `{ id, name, type }`; `visibleTo` — the scope tokens it is shared\n * with, so a reader acting for a member can apply the platform's own\n * visibility rule to them; and `installedFrom` — `{ listingId, version }`\n * for a dataset installed from a listing (`version` as the install\n * stamped it), `null` for one the workspace made. Never a record of it.\n */\nexport function datasetIndexedRecord(\n id: string,\n data: Readonly<Record<string, unknown>> | undefined,\n): PluginIndexedRecord | null {\n if (!data || data['deletedAt'] != null) return null\n const model = effectiveDatasetModel(data as { model?: DatasetModel; fields?: string[] })\n const text = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')\n return {\n id,\n name: datasetDisplayName(data) || id,\n facts: {\n fields: model.order.map((fieldId) => ({\n id: fieldId,\n name: text(model.fields[fieldId]?.name) || fieldId,\n type: String(model.fields[fieldId]?.type ?? 'text'),\n // A named type riding the storage one: a record's photo is `image` (AGL-3616).\n ...(model.fields[fieldId]?.customType ? { customType: String(model.fields[fieldId]?.customType) } : {}),\n })),\n visibleTo: Array.isArray(data['visibleTo']) ? (data['visibleTo'] as string[]) : [],\n installedFrom: installedFrom(data['source']),\n },\n }\n}\n\n/**\n * Where an installed dataset came from. Read from its `source` stamp, which\n * every dataset install has written — the ones from before install\n * provenance (AGL-1015) included, which carry no `installedFrom`.\n */\nfunction installedFrom(source: unknown): { listingId: string; version: unknown } | null {\n const stamp = (source ?? {}) as Record<string, unknown>\n const listingId = typeof stamp['listingId'] === 'string' ? stamp['listingId'] : ''\n return listingId ? { listingId, version: stamp['version'] ?? null } : null\n}\n"],"names":["effectiveDatasetModel","datasetDisplayName","datasetIndexedRecord","id","data","model","text","value","trim","name","facts","fields","order","map","fieldId","type","String","customType","visibleTo","Array","isArray","installedFrom","source","stamp","listingId","version"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAA4BA,qBAAqB,QAAQ,sBAAkB;AAC3E,SAASC,kBAAkB,QAAQ,gBAAY;AAE/C;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,qBACdC,EAAU,EACVC,IAAmD;IAEnD,IAAI,CAACA,QAAQA,IAAI,CAAC,YAAY,IAAI,MAAM,OAAO;IAC/C,MAAMC,QAAQL,sBAAsBI;IACpC,MAAME,OAAO,CAACC,QAA4B,OAAOA,UAAU,WAAWA,MAAMC,IAAI,KAAK;IACrF,OAAO;QACLL;QACAM,MAAMR,mBAAmBG,SAASD;QAClCO,OAAO;YACLC,QAAQN,MAAMO,KAAK,CAACC,GAAG,CAAC,CAACC;;oBAEZT,uBACEA,wBAETA,wBAAyDA;uBALzB;oBACpCF,IAAIW;oBACJL,MAAMH,MAAKD,wBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,sBAAuBI,IAAI,KAAKK;oBAC3CC,MAAMC,gBAAOX,yBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,uBAAuBU,IAAI,mBAAI;mBAExCV,EAAAA,yBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,uBAAuBY,UAAU,IAAG;oBAAEA,YAAYD,QAAOX,yBAAAA,MAAMM,MAAM,CAACG,QAAQ,qBAArBT,uBAAuBY,UAAU;gBAAE,IAAI,CAAC;;YAEvGC,WAAWC,MAAMC,OAAO,CAAChB,IAAI,CAAC,YAAY,IAAKA,IAAI,CAAC,YAAY,GAAgB,EAAE;YAClFiB,eAAeA,cAAcjB,IAAI,CAAC,SAAS;QAC7C;IACF;AACF;AAEA;;;;CAIC,GACD,SAASiB,cAAcC,MAAe;QAGKC;IAFzC,MAAMA,QAASD,iBAAAA,SAAU,CAAC;IAC1B,MAAME,YAAY,OAAOD,KAAK,CAAC,YAAY,KAAK,WAAWA,KAAK,CAAC,YAAY,GAAG;IAChF,OAAOC,YAAY;QAAEA;QAAWC,OAAO,GAAEF,iBAAAA,KAAK,CAAC,UAAU,YAAhBA,iBAAoB;IAAK,IAAI;AACxE"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/model/dataset-record.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PluginIndexedRecord } from '@aglyn/aglyn/plugin-manager/plugin-record-index'\nimport { type DatasetModel, effectiveDatasetModel } from './dataset-models'\nimport { datasetDisplayName } from './datasets'\n\n/**\n * One stored dataset as this plugin shares it with another (AGL-3080) — the\n * one shape its server index (`dataset-record-index.ts`) and its console list\n * source (`dataset-record-list.ts`) both answer, so a reader on either side\n * reads the same record.\n *\n * `null` for a deleted dataset. Otherwise its id, its name as the Data page\n * shows it, and `facts`:\n * `fields` — its fields in the dataset page's order, each\n * `{ id, name, type }`; `visibleTo` — the scope tokens it is shared\n * with, so a reader acting for a member can apply the platform's own\n * visibility rule to them; and `installedFrom` — `{ listingId, version }`\n * for a dataset installed from a listing (`version` as the install\n * stamped it), `null` for one the workspace made. Never a record of it.\n */\nexport function datasetIndexedRecord(\n id: string,\n data: Readonly<Record<string, unknown>> | undefined,\n): PluginIndexedRecord | null {\n if (!data || data['deletedAt'] != null) return null\n const model = effectiveDatasetModel(data as { model?: DatasetModel; fields?: string[] })\n const text = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')\n return {\n id,\n name: datasetDisplayName(data) || id,\n facts: {\n fields: model.order.map((fieldId) => ({\n id: fieldId,\n name: text(model.fields[fieldId]?.name) || fieldId,\n type: String(model.fields[fieldId]?.type ?? 'text'),\n // A named type riding the storage one: a record's photo is `image` (AGL-3616).\n ...(model.fields[fieldId]?.customType ? { customType: String(model.fields[fieldId]?.customType) } : {}),\n })),\n visibleTo: Array.isArray(data['visibleTo']) ? (data['visibleTo'] as string[]) : [],\n // Shared with all sites except some: what a reader of `visibleTo` needs in\n // order not to take it for a dataset on those sites alone (AGL-4047).\n ...(data['scopeMode'] !== undefined ? { scopeMode: data['scopeMode'] } : {}),\n ...(data['scopeExcept'] !== undefined ? { scopeExcept: data['scopeExcept'] } : {}),\n installedFrom: installedFrom(data['source']),\n },\n }\n}\n\n/**\n * Where an installed dataset came from. Read from its `source` stamp, which\n * every dataset install has written — the ones from before install\n * provenance (AGL-1015) included, which carry no `installedFrom`.\n */\nfunction installedFrom(source: unknown): { listingId: string; version: unknown } | null {\n const stamp = (source ?? {}) as Record<string, unknown>\n const listingId = typeof stamp['listingId'] === 'string' ? stamp['listingId'] : ''\n return listingId ? { listingId, version: stamp['version'] ?? null } : null\n}\n"],"names":["effectiveDatasetModel","datasetDisplayName","datasetIndexedRecord","id","data","model","text","value","trim","name","facts","fields","order","map","fieldId","type","String","customType","visibleTo","Array","isArray","undefined","scopeMode","scopeExcept","installedFrom","source","stamp","listingId","version"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAA4BA,qBAAqB,QAAQ,sBAAkB;AAC3E,SAASC,kBAAkB,QAAQ,gBAAY;AAE/C;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,qBACdC,EAAU,EACVC,IAAmD;IAEnD,IAAI,CAACA,QAAQA,IAAI,CAAC,YAAY,IAAI,MAAM,OAAO;IAC/C,MAAMC,QAAQL,sBAAsBI;IACpC,MAAME,OAA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language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import type { ScopePlaced } from '@aglyn/aglyn/app-utils/site-placement';
17
18
  import type { AglynOrgMember } from '@aglyn/aglyn/foundation/definitions/organization.types';
18
19
  /** A dataset act and the two keys that decide it. */
19
20
  declare const ACTS: {
@@ -27,14 +28,14 @@ declare const ACTS: {
27
28
  };
28
29
  };
29
30
  /** The key a refusal names: the site's on a one-site dataset, else the workspace's. */
30
- export declare function datasetRefusalPermission(act: keyof typeof ACTS, visibleTo: unknown): string;
31
- /** May this member write or delete a dataset placed at `visibleTo`? The routes' `canWriteDatasetOn`. */
31
+ export declare function datasetRefusalPermission(act: keyof typeof ACTS, dataset: ScopePlaced | null | undefined): string;
32
+ /** May this member write or delete this dataset, as its document places it? The routes' `canWriteDatasetOn`. */
32
33
  export declare function memberMayActOnDataset(input: {
33
34
  firestore: FirebaseFirestore.Firestore;
34
35
  orgId: string;
35
36
  uid: string;
36
37
  member: Partial<AglynOrgMember>;
37
- visibleTo: unknown;
38
+ dataset: ScopePlaced | null | undefined;
38
39
  act: keyof typeof ACTS;
39
40
  }): Promise<boolean>;
40
41
  export {};
@@ -28,15 +28,17 @@ import { DATA_ERASE_PERMISSION, DATA_MANAGE_PERMISSION, DATA_SITE_DELETE_PERMISS
28
28
  siteKey: DATA_SITE_DELETE_PERMISSION
29
29
  }
30
30
  };
31
- /** The key a refusal names: the site's on a one-site dataset, else the workspace's. */ export function datasetRefusalPermission(act, visibleTo) {
32
- return placedRefusalPermission(visibleTo, ACTS[act].workspaceKey, ACTS[act].siteKey);
31
+ /** The key a refusal names: the site's on a one-site dataset, else the workspace's. */ export function datasetRefusalPermission(act, dataset) {
32
+ return placedRefusalPermission(dataset, ACTS[act].workspaceKey, ACTS[act].siteKey);
33
33
  }
34
- /** May this member write or delete a dataset placed at `visibleTo`? The routes' `canWriteDatasetOn`. */ export async function memberMayActOnDataset(input) {
35
- const { act } = input, rest = _object_without_properties_loose(input, [
36
- "act"
34
+ /** May this member write or delete this dataset, as its document places it? The routes' `canWriteDatasetOn`. */ export async function memberMayActOnDataset(input) {
35
+ const { act, dataset } = input, rest = _object_without_properties_loose(input, [
36
+ "act",
37
+ "dataset"
37
38
  ]);
38
39
  const { workspaceKey, siteKey } = ACTS[act];
39
40
  return memberMayActOnPlaced(_extends({}, rest, {
41
+ placed: dataset,
40
42
  workspace: await memberHasOrgPermission(input.orgId, input.member, workspaceKey),
41
43
  workspaceKey,
42
44
  siteKey,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/server/dataset-access.server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AglynOrgMember } from '@aglyn/aglyn/foundation/definitions/organization.types'\nimport { memberHasOrgPermission } from '@aglyn/tenant-data-admin'\nimport { memberMayActOnPlaced, placedRefusalPermission } from '@aglyn/tenant-data-admin/server/placement-access'\nimport {\n DATA_ERASE_PERMISSION,\n DATA_MANAGE_PERMISSION,\n DATA_SITE_DELETE_PERMISSION,\n DATA_SITE_MANAGE_PERMISSION,\n DATA_SITE_ROLE_PRESET,\n} from '../model/dataset-access'\n\n/** A dataset act and the two keys that decide it. */\nconst ACTS = {\n write: { workspaceKey: DATA_MANAGE_PERMISSION, siteKey: DATA_SITE_MANAGE_PERMISSION },\n delete: { workspaceKey: DATA_ERASE_PERMISSION, siteKey: DATA_SITE_DELETE_PERMISSION },\n} as const\n\n/** The key a refusal names: the site's on a one-site dataset, else the workspace's. */\nexport function datasetRefusalPermission(act: keyof typeof ACTS, visibleTo: unknown): string {\n return placedRefusalPermission(visibleTo, ACTS[act].workspaceKey, ACTS[act].siteKey)\n}\n\n/** May this member write or delete a dataset placed at `visibleTo`? The routes' `canWriteDatasetOn`. */\nexport async function memberMayActOnDataset(input: {\n firestore: FirebaseFirestore.Firestore\n orgId: string\n uid: string\n member: Partial<AglynOrgMember>\n visibleTo: unknown\n act: keyof typeof ACTS\n}): Promise<boolean> {\n const { act, ...rest } = input\n const { workspaceKey, siteKey } = ACTS[act]\n return memberMayActOnPlaced({\n ...rest,\n workspace: await memberHasOrgPermission(input.orgId, input.member, workspaceKey as never),\n workspaceKey,\n siteKey,\n sitePreset: DATA_SITE_ROLE_PRESET,\n })\n}\n"],"names":["memberHasOrgPermission","memberMayActOnPlaced","placedRefusalPermission","DATA_ERASE_PERMISSION","DATA_MANAGE_PERMISSION","DATA_SITE_DELETE_PERMISSION","DATA_SITE_MANAGE_PERMISSION","DATA_SITE_ROLE_PRESET","ACTS","write","workspaceKey","siteKey","delete","datasetRefusalPermission","act","visibleTo","memberMayActOnDataset","input","rest","workspace","orgId","member","sitePreset"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;;AAGD,SAASA,sBAAsB,QAAQ,2BAA0B;AACjE,SAASC,oBAAoB,EAAEC,uBAAuB,QAAQ,mDAAkD;AAChH,SACEC,qBAAqB,EACrBC,sBAAsB,EACtBC,2BAA2B,EAC3BC,2BAA2B,EAC3BC,qBAAqB,QAChB,6BAAyB;AAEhC,mDAAmD,GACnD,MAAMC,OAAO;IACXC,OAAO;QAAEC,cAAcN;QAAwBO,SAASL;IAA4B;IACpFM,QAAQ;QAAEF,cAAcP;QAAuBQ,SAASN;IAA4B;AACtF;AAEA,qFAAqF,GACrF,OAAO,SAASQ,yBAAyBC,GAAsB,EAAEC,SAAkB;IACjF,OAAOb,wBAAwBa,WAAWP,IAAI,CAACM,IAAI,CAACJ,YAAY,EAAEF,IAAI,CAACM,IAAI,CAACH,OAAO;AACrF;AAEA,sGAAsG,GACtG,OAAO,eAAeK,sBAAsBC,KAO3C;IACC,MAAM,EAAEH,GAAG,EAAW,GAAGG,OAATC,wCAASD;;;IACzB,MAAM,EAAEP,YAAY,EAAEC,OAAO,EAAE,GAAGH,IAAI,CAACM,IAAI;IAC3C,OAAOb,qBAAqB,aACvBiB;QACHC,WAAW,MAAMnB,uBAAuBiB,MAAMG,KAAK,EAAEH,MAAMI,MAAM,EAAEX;QACnEA;QACAC;QACAW,YAAYf;;AAEhB"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/server/dataset-access.server.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ScopePlaced } from '@aglyn/aglyn/app-utils/site-placement'\nimport type { AglynOrgMember } from '@aglyn/aglyn/foundation/definitions/organization.types'\nimport { memberHasOrgPermission } from '@aglyn/tenant-data-admin'\nimport { memberMayActOnPlaced, placedRefusalPermission } from '@aglyn/tenant-data-admin/server/placement-access'\nimport {\n DATA_ERASE_PERMISSION,\n DATA_MANAGE_PERMISSION,\n DATA_SITE_DELETE_PERMISSION,\n DATA_SITE_MANAGE_PERMISSION,\n DATA_SITE_ROLE_PRESET,\n} from '../model/dataset-access'\n\n/** A dataset act and the two keys that decide it. */\nconst ACTS = {\n write: { workspaceKey: DATA_MANAGE_PERMISSION, siteKey: DATA_SITE_MANAGE_PERMISSION },\n delete: { workspaceKey: DATA_ERASE_PERMISSION, siteKey: DATA_SITE_DELETE_PERMISSION },\n} as const\n\n/** The key a refusal names: the site's on a one-site dataset, else the workspace's. */\nexport function datasetRefusalPermission(act: keyof typeof ACTS, dataset: ScopePlaced | null | undefined): string {\n return placedRefusalPermission(dataset, ACTS[act].workspaceKey, ACTS[act].siteKey)\n}\n\n/** May this member write or delete this dataset, as its document places it? The routes' `canWriteDatasetOn`. */\nexport async function memberMayActOnDataset(input: {\n firestore: FirebaseFirestore.Firestore\n orgId: string\n uid: string\n member: Partial<AglynOrgMember>\n dataset: ScopePlaced | null | undefined\n act: keyof typeof ACTS\n}): Promise<boolean> {\n const { act, dataset, ...rest } = input\n const { workspaceKey, siteKey } = ACTS[act]\n return memberMayActOnPlaced({\n ...rest,\n placed: dataset,\n workspace: await memberHasOrgPermission(input.orgId, input.member, workspaceKey as never),\n workspaceKey,\n siteKey,\n sitePreset: DATA_SITE_ROLE_PRESET,\n })\n}\n"],"names":["memberHasOrgPermission","memberMayActOnPlaced","placedRefusalPermission","DATA_ERASE_PERMISSION","DATA_MANAGE_PERMISSION","DATA_SITE_DELETE_PERMISSION","DATA_SITE_MANAGE_PERMISSION","DATA_SITE_ROLE_PRESET","ACTS","write","workspaceKey","siteKey","delete","datasetRefusalPermission","act","dataset","memberMayActOnDataset","input","rest","placed","workspace","orgId","member","sitePreset"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;;AAID,SAASA,sBAAsB,QAAQ,2BAA0B;AACjE,SAASC,oBAAoB,EAAEC,uBAAuB,QAAQ,mDAAkD;AAChH,SACEC,qBAAqB,EACrBC,sBAAsB,EACtBC,2BAA2B,EAC3BC,2BAA2B,EAC3BC,qBAAqB,QAChB,6BAAyB;AAEhC,mDAAmD,GACnD,MAAMC,OAAO;IACXC,OAAO;QAAEC,cAAcN;QAAwBO,SAASL;IAA4B;IACpFM,QAAQ;QAAEF,cAAcP;QAAuBQ,SAASN;IAA4B;AACtF;AAEA,qFAAqF,GACrF,OAAO,SAASQ,yBAAyBC,GAAsB,EAAEC,OAAuC;IACtG,OAAOb,wBAAwBa,SAASP,IAAI,CAACM,IAAI,CAACJ,YAAY,EAAEF,IAAI,CAACM,IAAI,CAACH,OAAO;AACnF;AAEA,8GAA8G,GAC9G,OAAO,eAAeK,sBAAsBC,KAO3C;IACC,MAAM,EAAEH,GAAG,EAAEC,OAAO,EAAW,GAAGE,OAATC,wCAASD;;;;IAClC,MAAM,EAAEP,YAAY,EAAEC,OAAO,EAAE,GAAGH,IAAI,CAACM,IAAI;IAC3C,OAAOb,qBAAqB,aACvBiB;QACHC,QAAQJ;QACRK,WAAW,MAAMpB,uBAAuBiB,MAAMI,KAAK,EAAEJ,MAAMK,MAAM,EAAEZ;QACnEA;QACAC;QACAY,YAAYhB;;AAEhB"}
@@ -29,6 +29,8 @@ import type { PluginSiteResourcePreview, PluginSiteResourceRequest } from '@agly
29
29
  * admits exactly this case);
30
30
  * - shared with this site and others, it stays, and this site comes off its
31
31
  * sharing so it names no site that is gone;
32
+ * - shared with all sites except some, it stays even when this site is the last
33
+ * it reaches: it is the workspace's, and the next new site joins it;
32
34
  * - shared with every site (`['org']`), it does not name the site and is not
33
35
  * read.
34
36
  *
@@ -36,8 +38,6 @@ import type { PluginSiteResourcePreview, PluginSiteResourceRequest } from '@agly
36
38
  * (`plugin-site-resources.ts`): the delete asks, the Delete site card shows
37
39
  * the preview first.
38
40
  */
39
- /** Whether a dataset's sharing names this site and nothing else. */
40
- export declare function datasetIsSiteOnly(visibleTo: unknown, hostId: string): boolean;
41
41
  export interface DatasetSiteErasureDeps {
42
42
  /** The Admin SDK handle; specs hand in a double. */
43
43
  firestore?: () => Firestore;
@@ -14,36 +14,14 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */ import { FieldValue } from "firebase-admin/firestore";
17
- import { hostScopeToken } from "@aglyn/aglyn/app-utils/scope-tokens";
17
+ import { hostScopeToken, isSiteOnlyScope } from "@aglyn/aglyn/app-utils/scope-tokens";
18
18
  import { firebaseAdmin } from "@aglyn/tenant-data-admin";
19
- /**
20
- * A SITE'S OWN DATASETS GO WITH IT (AGL-4003).
21
- *
22
- * Datasets belong to the organization and name no site, so for a long time a
23
- * deleted site left behind every list it was given: a guided start makes its
24
- * site's datasets, and 53 of them outlived their test sites in one workspace
25
- * (2026-10-20). The sharing says whose a dataset is:
26
- *
27
- * - shared with this site alone, it is the site's, and is erased with its
28
- * records, as the site's own Delete dataset would (`eraseScopeDenial`
29
- * admits exactly this case);
30
- * - shared with this site and others, it stays, and this site comes off its
31
- * sharing so it names no site that is gone;
32
- * - shared with every site (`['org']`), it does not name the site and is not
33
- * read.
34
- *
35
- * Core reaches this through the site-resource seam
36
- * (`plugin-site-resources.ts`): the delete asks, the Delete site card shows
37
- * the preview first.
38
- */ /** Whether a dataset's sharing names this site and nothing else. */ export function datasetIsSiteOnly(visibleTo, hostId) {
39
- const token = hostScopeToken(hostId);
40
- return Array.isArray(visibleTo) && visibleTo.length > 0 && visibleTo.every((entry)=>entry === token);
41
- }
42
19
  const platformFirestore = ()=>firebaseAdmin.app().firestore();
43
20
  /** The datasets whose sharing names the site: its own, and the ones it shares. */ async function siteDatasets(request, firestore) {
44
21
  const rows = await firestore.collection('orgs').doc(request.orgId).collection('datasets').where('visibleTo', 'array-contains', hostScopeToken(request.hostId)).get();
45
- const only = rows.docs.filter((doc)=>datasetIsSiteOnly(doc.get('visibleTo'), request.hostId));
46
- const shared = rows.docs.filter((doc)=>!datasetIsSiteOnly(doc.get('visibleTo'), request.hostId));
22
+ const siteOnly = (doc)=>isSiteOnlyScope(doc.data(), request.hostId);
23
+ const only = rows.docs.filter(siteOnly);
24
+ const shared = rows.docs.filter((doc)=>!siteOnly(doc));
47
25
  return {
48
26
  only,
49
27
  shared
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/server/dataset-site-erasure.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Firestore, QueryDocumentSnapshot } from 'firebase-admin/firestore'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport { hostScopeToken } from '@aglyn/aglyn/app-utils/scope-tokens'\nimport type {\n PluginSiteResourceGoing,\n PluginSiteResourcePreview,\n PluginSiteResourceRequest,\n} from '@aglyn/aglyn/plugin-manager/plugin-site-resources'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin'\n\n/**\n * A SITE'S OWN DATASETS GO WITH IT (AGL-4003).\n *\n * Datasets belong to the organization and name no site, so for a long time a\n * deleted site left behind every list it was given: a guided start makes its\n * site's datasets, and 53 of them outlived their test sites in one workspace\n * (2026-10-20). The sharing says whose a dataset is:\n *\n * - shared with this site alone, it is the site's, and is erased with its\n * records, as the site's own Delete dataset would (`eraseScopeDenial`\n * admits exactly this case);\n * - shared with this site and others, it stays, and this site comes off its\n * sharing so it names no site that is gone;\n * - shared with every site (`['org']`), it does not name the site and is not\n * read.\n *\n * Core reaches this through the site-resource seam\n * (`plugin-site-resources.ts`): the delete asks, the Delete site card shows\n * the preview first.\n */\n\n/** Whether a dataset's sharing names this site and nothing else. */\nexport function datasetIsSiteOnly(visibleTo: unknown, hostId: string): boolean {\n const token = hostScopeToken(hostId)\n return (\n Array.isArray(visibleTo) &&\n visibleTo.length > 0 &&\n visibleTo.every((entry) => entry === token)\n )\n}\n\nexport interface DatasetSiteErasureDeps {\n /** The Admin SDK handle; specs hand in a double. */\n firestore?: () => Firestore\n}\n\nconst platformFirestore = () => firebaseAdmin.app().firestore() as unknown as Firestore\n\n/** The datasets whose sharing names the site: its own, and the ones it shares. */\nasync function siteDatasets(\n request: PluginSiteResourceRequest,\n firestore: Firestore,\n): Promise<{ only: QueryDocumentSnapshot[]; shared: QueryDocumentSnapshot[] }> {\n const rows = await firestore\n .collection('orgs')\n .doc(request.orgId)\n .collection('datasets')\n .where('visibleTo', 'array-contains', hostScopeToken(request.hostId))\n .get()\n const only = rows.docs.filter((doc) => datasetIsSiteOnly(doc.get('visibleTo'), request.hostId))\n const shared = rows.docs.filter((doc) => !datasetIsSiteOnly(doc.get('visibleTo'), request.hostId))\n return { only, shared }\n}\n\n/**\n * What deleting the site would do to its workspace's datasets: the ones\n * shared with it alone, each with its record count, by name, and how many\n * it shares with other sites. Reads only.\n */\nexport async function previewSiteDatasets(\n request: PluginSiteResourceRequest,\n deps: DatasetSiteErasureDeps = {},\n): Promise<PluginSiteResourcePreview> {\n const { only, shared } = await siteDatasets(request, (deps.firestore ?? platformFirestore)())\n const going = await Promise.all(\n only.map(async (doc): Promise<PluginSiteResourceGoing> => {\n const items = await doc.ref\n .collection('records')\n .count()\n .get()\n .then((counted) => Number(counted.data().count) || 0)\n .catch(() => null)\n return { id: doc.id, name: String(doc.get('displayName') ?? '') || doc.id, items }\n }),\n )\n going.sort((a, b) => a.name.localeCompare(b.name))\n return {\n noun: ['dataset', 'datasets'],\n itemNoun: ['record', 'records'],\n going,\n staying: shared.length,\n }\n}\n\n/**\n * Erases the datasets shared with the site alone, records included, and\n * takes the site off the sharing of the ones it shares with others. Per\n * dataset, so one failure leaves the rest done. Answers how many it erased.\n */\nexport async function eraseSiteDatasets(\n request: PluginSiteResourceRequest,\n deps: DatasetSiteErasureDeps = {},\n): Promise<number> {\n const firestore = (deps.firestore ?? platformFirestore)()\n const { only, shared } = await siteDatasets(request, firestore)\n let erased = 0\n for (const doc of only) {\n try {\n await firestore.recursiveDelete(doc.ref)\n erased += 1\n } catch (error) {\n console.error(`[data] dataset ${doc.id} was not erased with site ${request.hostId}`, error)\n }\n }\n for (const doc of shared) {\n await doc.ref\n .update({ visibleTo: FieldValue.arrayRemove(hostScopeToken(request.hostId)) })\n .catch((error: unknown) => {\n console.error(`[data] dataset ${doc.id} still names deleted site ${request.hostId}`, error)\n })\n }\n return erased\n}\n"],"names":["FieldValue","hostScopeToken","firebaseAdmin","datasetIsSiteOnly","visibleTo","hostId","token","Array","isArray","length","every","entry","platformFirestore","app","firestore","siteDatasets","request","rows","collection","doc","orgId","where","get","only","docs","filter","shared","previewSiteDatasets","deps","going","Promise","all","map","items","ref","count","then","counted","Number","data","catch","id","name","String","sort","a","b","localeCompare","noun","itemNoun","staying","eraseSiteDatasets","erased","recursiveDelete","error","console","update","arrayRemove"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,UAAU,QAAQ,2BAA0B;AACrD,SAASC,cAAc,QAAQ,sCAAqC;AAMpE,SAASC,aAAa,QAAQ,2BAA0B;AAExD;;;;;;;;;;;;;;;;;;;CAmBC,GAED,kEAAkE,GAClE,OAAO,SAASC,kBAAkBC,SAAkB,EAAEC,MAAc;IAClE,MAAMC,QAAQL,eAAeI;IAC7B,OACEE,MAAMC,OAAO,CAACJ,cACdA,UAAUK,MAAM,GAAG,KACnBL,UAAUM,KAAK,CAAC,CAACC,QAAUA,UAAUL;AAEzC;AAOA,MAAMM,oBAAoB,IAAMV,cAAcW,GAAG,GAAGC,SAAS;AAE7D,gFAAgF,GAChF,eAAeC,aACbC,OAAkC,EAClCF,SAAoB;IAEpB,MAAMG,OAAO,MAAMH,UAChBI,UAAU,CAAC,QACXC,GAAG,CAACH,QAAQI,KAAK,EACjBF,UAAU,CAAC,YACXG,KAAK,CAAC,aAAa,kBAAkBpB,eAAee,QAAQX,MAAM,GAClEiB,GAAG;IACN,MAAMC,OAAON,KAAKO,IAAI,CAACC,MAAM,CAAC,CAACN,MAAQhB,kBAAkBgB,IAAIG,GAAG,CAAC,cAAcN,QAAQX,MAAM;IAC7F,MAAMqB,SAAST,KAAKO,IAAI,CAACC,MAAM,CAAC,CAACN,MAAQ,CAAChB,kBAAkBgB,IAAIG,GAAG,CAAC,cAAcN,QAAQX,MAAM;IAChG,OAAO;QAAEkB;QAAMG;IAAO;AACxB;AAEA;;;;CAIC,GACD,OAA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IsB,EAAE,CAAC,0BAA0B,EAAEzB,QAAQX,MAAM,EAAE,EAAEiD;QACvF;IACF;IACA,KAAK,MAAMnC,OAAOO,OAAQ;QACxB,MAAMP,IAAIe,GAAG,CACVsB,MAAM,CAAC;YAAEpD,WAAWJ,WAAWyD,WAAW,CAACxD,eAAee,QAAQX,MAAM;QAAG,GAC3EmC,KAAK,CAAC,CAACc;YACNC,QAAQD,KAAK,CAAC,CAAC,eAAe,EAAEnC,IAAIsB,EAAE,CAAC,0BAA0B,EAAEzB,QAAQX,MAAM,EAAE,EAAEiD;QACvF;IACJ;IACA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/data/src/lib/server/dataset-site-erasure.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Firestore, QueryDocumentSnapshot } from 'firebase-admin/firestore'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport { hostScopeToken, isSiteOnlyScope } from '@aglyn/aglyn/app-utils/scope-tokens'\nimport type {\n PluginSiteResourceGoing,\n PluginSiteResourcePreview,\n PluginSiteResourceRequest,\n} from '@aglyn/aglyn/plugin-manager/plugin-site-resources'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin'\n\n/**\n * A SITE'S OWN DATASETS GO WITH IT (AGL-4003).\n *\n * Datasets belong to the organization and name no site, so for a long time a\n * deleted site left behind every list it was given: a guided start makes its\n * site's datasets, and 53 of them outlived their test sites in one workspace\n * (2026-10-20). The sharing says whose a dataset is:\n *\n * - shared with this site alone, it is the site's, and is erased with its\n * records, as the site's own Delete dataset would (`eraseScopeDenial`\n * admits exactly this case);\n * - shared with this site and others, it stays, and this site comes off its\n * sharing so it names no site that is gone;\n * - shared with all sites except some, it stays even when this site is the last\n * it reaches: it is the workspace's, and the next new site joins it;\n * - shared with every site (`['org']`), it does not name the site and is not\n * read.\n *\n * Core reaches this through the site-resource seam\n * (`plugin-site-resources.ts`): the delete asks, the Delete site card shows\n * the preview first.\n */\n\nexport interface DatasetSiteErasureDeps {\n /** The Admin SDK handle; specs hand in a double. */\n firestore?: () => Firestore\n}\n\nconst platformFirestore = () => firebaseAdmin.app().firestore() as unknown as Firestore\n\n/** The datasets whose sharing names the site: its own, and the ones it shares. */\nasync function siteDatasets(\n request: PluginSiteResourceRequest,\n firestore: Firestore,\n): Promise<{ only: QueryDocumentSnapshot[]; shared: QueryDocumentSnapshot[] }> {\n const rows = await firestore\n .collection('orgs')\n .doc(request.orgId)\n .collection('datasets')\n .where('visibleTo', 'array-contains', hostScopeToken(request.hostId))\n .get()\n const siteOnly = (doc: QueryDocumentSnapshot) => isSiteOnlyScope(doc.data(), request.hostId)\n const only = rows.docs.filter(siteOnly)\n const shared = rows.docs.filter((doc) => !siteOnly(doc))\n return { only, shared }\n}\n\n/**\n * What deleting the site would do to its workspace's datasets: the ones\n * shared with it alone, each with its record count, by name, and how many\n * it shares with other sites. Reads only.\n */\nexport async function previewSiteDatasets(\n request: PluginSiteResourceRequest,\n deps: DatasetSiteErasureDeps = {},\n): Promise<PluginSiteResourcePreview> {\n const { only, shared } = await siteDatasets(request, (deps.firestore ?? platformFirestore)())\n const going = await Promise.all(\n only.map(async (doc): Promise<PluginSiteResourceGoing> => {\n const items = await doc.ref\n .collection('records')\n .count()\n .get()\n .then((counted) => Number(counted.data().count) || 0)\n .catch(() => null)\n return { id: doc.id, name: String(doc.get('displayName') ?? '') || doc.id, items }\n }),\n )\n going.sort((a, b) => a.name.localeCompare(b.name))\n return {\n noun: ['dataset', 'datasets'],\n itemNoun: ['record', 'records'],\n going,\n staying: shared.length,\n }\n}\n\n/**\n * Erases the datasets shared with the site alone, records included, and\n * takes the site off the sharing of the ones it shares with others. Per\n * dataset, so one failure leaves the rest done. Answers how many it erased.\n */\nexport async function eraseSiteDatasets(\n request: PluginSiteResourceRequest,\n deps: DatasetSiteErasureDeps = {},\n): Promise<number> {\n const firestore = (deps.firestore ?? platformFirestore)()\n const { only, shared } = await siteDatasets(request, firestore)\n let erased = 0\n for (const doc of only) {\n try {\n await firestore.recursiveDelete(doc.ref)\n erased += 1\n } catch (error) {\n console.error(`[data] dataset ${doc.id} was not erased with site ${request.hostId}`, error)\n }\n }\n for (const doc of shared) {\n await doc.ref\n .update({ visibleTo: FieldValue.arrayRemove(hostScopeToken(request.hostId)) })\n .catch((error: unknown) => {\n console.error(`[data] dataset ${doc.id} still names deleted site ${request.hostId}`, error)\n })\n }\n return erased\n}\n"],"names":["FieldValue","hostScopeToken","isSiteOnlyScope","firebaseAdmin","platformFirestore","app","firestore","siteDatasets","request","rows","collection","doc","orgId","where","hostId","get","siteOnly","data","only","docs","filter","shared","previewSiteDatasets","deps","going","Promise","all","map","items","ref","count","then","counted","Number","catch","id","name","String","sort","a","b","localeCompare","noun","itemNoun","staying","length","eraseSiteDatasets","erased","recursiveDelete","error","console","update","visibleTo","arrayRemove"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,UAAU,QAAQ,2BAA0B;AACrD,SAASC,cAAc,EAAEC,eAAe,QAAQ,sCAAqC;AAMrF,SAASC,aAAa,QAAQ,2BAA0B;AA8BxD,MAAMC,oBAAoB,IAAMD,cAAcE,GAAG,GAAGC,SAAS;AAE7D,gFAAgF,GAChF,eAAeC,aACbC,OAAkC,EAClCF,SAAoB;IAEpB,MAAMG,OAAO,MAAMH,UAChBI,UAAU,CAAC,QACXC,GAAG,CAACH,QAAQI,KAAK,EACjBF,UAAU,CAAC,YACXG,KAAK,CAAC,aAAa,kBAAkBZ,eAAeO,QAAQM,MAAM,GAClEC,GAAG;IACN,M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kBnB;IACrC,MAAM,EAAEc,IAAI,EAAEG,MAAM,EAAE,GAAG,MAAMd,aAAaC,SAASF;IACrD,IAAIyC,SAAS;IACb,KAAK,MAAMpC,OAAOO,KAAM;QACtB,IAAI;YACF,MAAMZ,UAAU0C,eAAe,CAACrC,IAAIkB,GAAG;YACvCkB,UAAU;QACZ,EAAE,OAAOE,OAAO;YACdC,QAAQD,KAAK,CAAC,CAAC,eAAe,EAAEtC,IAAIwB,EAAE,CAAC,0BAA0B,EAAE3B,QAAQM,MAAM,EAAE,EAAEmC;QACvF;IACF;IACA,KAAK,MAAMtC,OAAOU,OAAQ;QACxB,MAAMV,IAAIkB,GAAG,CACVsB,MAAM,CAAC;YAAEC,WAAWpD,WAAWqD,WAAW,CAACpD,eAAeO,QAAQM,MAAM;QAAG,GAC3EoB,KAAK,CAAC,CAACe;YACNC,QAAQD,KAAK,CAAC,CAAC,eAAe,EAAEtC,IAAIwB,EAAE,CAAC,0BAA0B,EAAE3B,QAAQM,MAAM,EAAE,EAAEmC;QACvF;IACJ;IACA,OAAOF;AACT"}
@@ -33,6 +33,8 @@ import { type PluginWebApiHandler } from '@aglyn/aglyn/server';
33
33
  * - `update-record` / `delete-record`: the Data card's record edit and
34
34
  * delete (with its reference integrity) for the native apps, which have no
35
35
  * browser to write from (AGL-3668).
36
+ * - `set-sharing`: who a dataset is shared with: all sites, the sites chosen, or
37
+ * all sites except some (AGL-4047).
36
38
  *
37
39
  * Since AGL-2163 both record actions ALSO enforce `checkDataStorageQuota`.
38
40
  * See {@link refuseIfDataStorageBlocked}: that check's `allowed` field had no