@opengeni/db 1.0.1 → 3.2.0-canary.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/attached-browser-devices.d.ts +7 -0
- package/dist/automations.d.ts +154 -0
- package/dist/canonical-human-identities.js +3 -3
- package/dist/capability-integrations.d.ts +13 -0
- package/dist/child-lifecycle-notices.d.ts +68 -0
- package/dist/{chunk-4SR4HKKA.js → chunk-2EH4WRHL.js} +19 -11
- package/dist/chunk-2EH4WRHL.js.map +1 -0
- package/dist/{chunk-CUPM3FGB.js → chunk-2PRS4J5Q.js} +3 -3
- package/dist/chunk-6HMM2R5T.js +390 -0
- package/dist/chunk-6HMM2R5T.js.map +1 -0
- package/dist/{chunk-ZWREYEWA.js → chunk-AZHW7R5V.js} +56 -11
- package/dist/chunk-AZHW7R5V.js.map +1 -0
- package/dist/{chunk-LTG3S6ZY.js → chunk-E6CLMKEE.js} +2 -2
- package/dist/{chunk-6ZYKCRFO.js → chunk-KRLPEMLH.js} +7591 -4417
- package/dist/chunk-KRLPEMLH.js.map +1 -0
- package/dist/chunk-NAB6FKFN.js +516 -0
- package/dist/chunk-NAB6FKFN.js.map +1 -0
- package/dist/{chunk-SK7YYHBI.js → chunk-SIBYBA2D.js} +46 -1
- package/dist/chunk-SIBYBA2D.js.map +1 -0
- package/dist/chunk-UZNXG44K.js +4508 -0
- package/dist/chunk-UZNXG44K.js.map +1 -0
- package/dist/codemode-operations.d.ts +1 -6
- package/dist/company-brain-context-selection-schema.d.ts +705 -0
- package/dist/company-brain-context-selection.d.ts +94 -0
- package/dist/company-brain-governed-writes.d.ts +24 -0
- package/dist/company-brain.d.ts +55 -0
- package/dist/company-profile-agent-admin.d.ts +15 -0
- package/dist/company-profile-schema.d.ts +619 -2
- package/dist/company-profile.d.ts +9 -4
- package/dist/connection-authority.d.ts +95 -0
- package/dist/connection-scopes.d.ts +8 -0
- package/dist/connection-tenancy-backfill.d.ts +85 -0
- package/dist/connection-token-resolver.d.ts +30 -1
- package/dist/database.d.ts +23 -4
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.d.ts +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/governed-learning-activation-schema.d.ts +984 -0
- package/dist/governed-learning-activation.d.ts +98 -0
- package/dist/governed-learning-evaluator-schema.d.ts +633 -0
- package/dist/governed-learning-evaluator.d.ts +28 -0
- package/dist/index.d.ts +1606 -81
- package/dist/index.js +21898 -8147
- package/dist/index.js.map +1 -1
- package/dist/insights.d.ts +18 -0
- package/dist/integration-bindings.d.ts +1 -0
- package/dist/integration-facets.d.ts +30 -0
- package/dist/interaction-placement-loss.d.ts +22 -0
- package/dist/managed-human-provisioning.d.ts +25 -0
- package/dist/memory-domain.d.ts +3 -3
- package/dist/migrate.d.ts +11 -1
- package/dist/migrate.js +1 -1
- package/dist/new-session-drafts.d.ts +43 -5
- package/dist/organization-membership-backfill.d.ts +174 -0
- package/dist/organization-membership-lifecycle.d.ts +162 -0
- package/dist/pr-review.d.ts +107 -0
- package/dist/preference-registry-schema.d.ts +2 -0
- package/dist/preference-registry.d.ts +2 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +29 -8
- package/dist/schema.d.ts +24914 -13703
- package/dist/schema.js +99 -1
- package/dist/scoped-knowledge-schema.d.ts +52 -1
- package/dist/session-background-commands.d.ts +125 -0
- package/dist/session-background-commands.js +34 -0
- package/dist/session-background-commands.js.map +1 -0
- package/dist/session-control.d.ts +156 -3
- package/dist/session-goal-pacing.d.ts +68 -0
- package/dist/session-queue-commands.d.ts +43 -4
- package/dist/session-realtime-ledger.d.ts +2 -0
- package/dist/session-tenancy.d.ts +71 -1
- package/dist/session-tenancy.js +25 -3
- package/dist/session-tool-call-settlement.d.ts +9 -4
- package/dist/slack-routing-personal-workspace.d.ts +23 -0
- package/dist/slack-routing.d.ts +268 -0
- package/dist/slack-task-policy-schema.d.ts +34 -0
- package/dist/slack-task-policy.d.ts +8 -0
- package/dist/slack-user-link-access.d.ts +28 -0
- package/dist/task-notes-schema.d.ts +594 -0
- package/dist/task-notes.d.ts +39 -0
- package/dist/turn-initiator.d.ts +2 -0
- package/dist/user-resource-authority.d.ts +109 -0
- package/dist/video-generation.js +3 -3
- package/dist/workspace-authority.d.ts +81 -0
- package/dist/workspace-instruction-policies-schema.d.ts +279 -0
- package/dist/workspace-instruction-policies.d.ts +62 -0
- package/dist/workspace-learning-policy.d.ts +1 -0
- package/dist/workspace-membership-permissions.d.ts +2 -0
- package/drizzle/0240_enrollment_connection_authority.sql +39 -0
- package/drizzle/0241_atomic_personal_resource_delegation.sql +1000 -0
- package/drizzle/0241_enrollment_agent_runtime.sql +70 -0
- package/drizzle/0244_slack_app_home_refresh_queue.sql +120 -0
- package/drizzle/0245_model_context_contribution_facts.sql +88 -0
- package/drizzle/0246_integration_personal_instance_authority.sql +70 -0
- package/drizzle/0247_terraform_stacks_provenance_repair.sql +428 -0
- package/drizzle/0248_terraform_stacks_component_resolution_fence.sql +83 -0
- package/drizzle/0249_personal_resource_delegation_authority_correction.sql +662 -0
- package/drizzle/0250_direct_retained_process_owner_liveness.sql +199 -0
- package/drizzle/0251_connected_machine_operation_policy.sql +45 -0
- package/drizzle/0252_scheduled_personal_resource_delegation.sql +1867 -0
- package/drizzle/0253_common_user_resource_authority_lifecycle.sql +1555 -0
- package/drizzle/0254_scoped_variable_set_authority.sql +1255 -0
- package/drizzle/0255_company_brain_governed_write_proposals.sql +524 -0
- package/drizzle/0256_connection_authority_delegation.sql +703 -0
- package/drizzle/0257_goal_revision_decisions_and_root_constraints.sql +436 -0
- package/drizzle/0258_three_scope_document_knowledge_authority.sql +1273 -0
- package/drizzle/0259_company_brain_context_selection_receipts.sql +869 -0
- package/drizzle/0260_task_note_knowledge_promotion.sql +820 -0
- package/drizzle/0261_preference_knowledge_proposal_actor_binding.sql +471 -0
- package/drizzle/0262_scoped_connected_machines_and_rigs.sql +1700 -0
- package/drizzle/0263_organization_membership_lifecycle.sql +3284 -0
- package/drizzle/0264_connection_authority_runtime_activation.sql +1084 -0
- package/drizzle/0266_company_brain_context_receipt_inspection.sql +156 -0
- package/drizzle/0268_governed_learning_decision_receipts.sql +825 -0
- package/drizzle/0269_governed_learning_activation_controller.sql +1874 -0
- package/drizzle/0270_governed_learning_history_inspection.sql +170 -0
- package/drizzle/0271_company_brain_retrieval_only_default.sql +524 -0
- package/drizzle/0272_human_confirmed_learning_activation.sql +591 -0
- package/drizzle/0273_scheduled_variable_set_materialization.sql +268 -0
- package/drizzle/0274_human_confirmed_knowledge_review.sql +310 -0
- package/drizzle/0275_scheduled_connection_authority.sql +5527 -0
- package/drizzle/0276_onboarding_proposal_initiating_human_guc.sql +198 -0
- package/drizzle/0277_workspace_writer_authority_attribution.sql +393 -0
- package/drizzle/0278_workspace_membership_removal_fencing.sql +1174 -0
- package/drizzle/0279_workspace_connection_use_lane.sql +343 -0
- package/drizzle/0280_connection_and_variable_set_audit_attribution.sql +773 -0
- package/drizzle/0281_viewer_holder_authority_claims.sql +52 -0
- package/drizzle/0282_variable_set_session_attach_attribution.sql +178 -0
- package/drizzle/0283_editable_spreadsheet_authored_state.sql +82 -0
- package/drizzle/0284_truthful_human_confirmed_review_reason.sql +930 -0
- package/drizzle/0285_organization_tenancy_inventory.sql +329 -0
- package/drizzle/0286_widen_task_note_expiry_ceiling.sql +391 -0
- package/drizzle/0287_open_suffix_pending_tool_calls.sql +18 -0
- package/drizzle/0288_attached_browser_reenrollment.sql +64 -0
- package/drizzle/0289_session_composer_policy_authority.sql +597 -0
- package/drizzle/0290_organization_membership_backfill.sql +268 -0
- package/drizzle/0291_resource_authority_classification_assertion.sql +371 -0
- package/drizzle/0292_truthful_tenancy_inventory_counters.sql +291 -0
- package/drizzle/0293_confirm_time_rule_rebaseline.sql +615 -0
- package/drizzle/0294_preference_activation_authority.sql +237 -0
- package/drizzle/0295_retire_legacy_standing_memory_mode.sql +476 -0
- package/drizzle/0296_force_rls_backfill_noop_repair.sql +215 -0
- package/drizzle/0297_session_ownership_classification_and_backfill.sql +752 -0
- package/drizzle/0298_organization_tenancy_parity.sql +609 -0
- package/drizzle/0299_organization_membership_lock_order.sql +291 -0
- package/drizzle/0300_tenancy_backfill_ledger.sql +459 -0
- package/drizzle/0301_session_snapshot_and_pin_visibility.sql +181 -0
- package/drizzle/0302_personal_workspace_session_ownership.sql +303 -0
- package/drizzle/0303_session_tenancy_product_activation.sql +919 -0
- package/drizzle/0304_personal_workspace_private_session_reads.sql +97 -0
- package/drizzle/0305_personal_resource_grant_management.sql +584 -0
- package/drizzle/0306_atomic_personal_resource_attachments.sql +1374 -0
- package/drizzle/0307_session_attention_state.sql +51 -0
- package/drizzle/0308_session_archives.sql +35 -0
- package/drizzle/0309_channel_project_pins.sql +6 -0
- package/drizzle/0310_channel_project_order.sql +27 -0
- package/drizzle/0311_company_scope_and_private_session_create.sql +656 -0
- package/drizzle/0312_quiescent_session_tree_deletion.sql +39 -0
- package/drizzle/0313_private_child_session_authority.sql +365 -0
- package/drizzle/0314_unregistered_organization_invitations.sql +606 -0
- package/drizzle/0315_personal_github_repository_selection.sql +624 -0
- package/drizzle/0316_human_confirmed_activation_resumed_generation.sql +869 -0
- package/drizzle/0317_session_goal_continuation_hold.sql +64 -0
- package/drizzle/0318_session_turn_startup_milestones.sql +115 -0
- package/drizzle/0319_event_triggered_automations.sql +254 -0
- package/drizzle/0320_pr_review_pack.sql +113 -0
- package/drizzle/0321_slack_bot_environment_display_name.sql +15 -0
- package/drizzle/0322_session_turns_unclaimed_prompt_trigger_index.sql +5 -0
- package/drizzle/0323_organization_private_session_enablement.sql +489 -0
- package/drizzle/0324_human_confirmed_company_profile_agent_admin.sql +856 -0
- package/drizzle/0325_child_lifecycle_notices.sql +44 -0
- package/drizzle/0326_interaction_operation_error_codes.sql +62 -0
- package/drizzle/0327_slack_first_task_hint.sql +29 -0
- package/drizzle/0328_session_background_commands.sql +590 -0
- package/drizzle/0329_slack_orchestration_delivery_events.sql +91 -0
- package/drizzle/0330_api_key_descriptions.sql +20 -0
- package/drizzle/0331_managed_organization_creation.sql +163 -0
- package/drizzle/0332_organization_shared_workspace_control_plane.sql +539 -0
- package/drizzle/0333_session_turn_prompt_routing.sql +45 -0
- package/drizzle/0334_connected_machine_workspace_root.sql +99 -0
- package/drizzle/0335_slack_workspace_routing.sql +460 -0
- package/drizzle/0336_atomic_session_fork_visibility.sql +667 -0
- package/drizzle/0337_slack_routed_action_handles.sql +189 -0
- package/drizzle/0338_atomic_connected_machine_attachments.sql +410 -0
- package/drizzle/0339_document_authority_reclassification.sql +1153 -0
- package/drizzle/0340_tenancy_backfill_activation_evidence.sql +1347 -0
- package/drizzle/0341_slack_routing_probe_organization_fence.sql +109 -0
- package/drizzle/0342_slack_route_prompt_single_pending.sql +32 -0
- package/drizzle/0343_personal_document_force_rls_lock_repair.sql +146 -0
- package/drizzle/0344_private_session_visibility_transition_gate.sql +85 -0
- package/drizzle/0345_tenant_scoped_session_tenancy_fence.sql +2839 -0
- package/drizzle/0346_document_migration_audit_surface.sql +454 -0
- package/drizzle/0347_connection_authority_convergence_evidence.sql +396 -0
- package/package.json +10 -6
- package/src/attached-browser-devices.ts +233 -5
- package/src/automations.ts +911 -0
- package/src/browser-sessions.ts +10 -0
- package/src/capability-integrations.ts +175 -1
- package/src/child-lifecycle-notices.ts +241 -0
- package/src/codemode-operations.ts +1 -35
- package/src/company-brain-context-selection-schema.ts +100 -0
- package/src/company-brain-context-selection.ts +359 -0
- package/src/company-brain-governed-writes.ts +1170 -0
- package/src/company-brain.ts +309 -0
- package/src/company-profile-agent-admin.ts +225 -0
- package/src/company-profile-schema.ts +121 -1
- package/src/company-profile.ts +21 -0
- package/src/computer-sessions.ts +10 -1
- package/src/connection-authority.ts +290 -0
- package/src/connection-scopes.ts +20 -0
- package/src/connection-tenancy-backfill.ts +167 -0
- package/src/connection-token-resolver.ts +263 -31
- package/src/database.ts +87 -2
- package/src/editable-artifacts-schema.ts +10 -5
- package/src/editable-artifacts.ts +21 -11
- package/src/governed-learning-activation-schema.ts +121 -0
- package/src/governed-learning-activation.ts +588 -0
- package/src/governed-learning-evaluator-schema.ts +72 -0
- package/src/governed-learning-evaluator.ts +217 -0
- package/src/index.ts +11676 -1550
- package/src/insights.ts +107 -0
- package/src/integration-bindings.ts +88 -6
- package/src/integration-facets.ts +287 -84
- package/src/interaction-placement-loss.ts +234 -0
- package/src/managed-human-provisioning.ts +116 -0
- package/src/memory-domain.ts +27 -32
- package/src/migrate.ts +77 -1
- package/src/new-session-drafts.ts +229 -35
- package/src/organization-membership-backfill.ts +735 -0
- package/src/organization-membership-lifecycle.ts +995 -0
- package/src/pr-review.ts +890 -0
- package/src/preference-registry.ts +31 -1
- package/src/provision-roles.ts +905 -6
- package/src/runtime-posture-cli.ts +2 -0
- package/src/runtime-posture.ts +1317 -72
- package/src/schema.ts +3316 -428
- package/src/scoped-knowledge-schema.ts +16 -8
- package/src/scoped-knowledge.ts +1 -1
- package/src/session-background-commands.ts +759 -0
- package/src/session-control.ts +640 -74
- package/src/session-goal-pacing.ts +126 -0
- package/src/session-queue-commands.ts +441 -85
- package/src/session-realtime-context.ts +4 -6
- package/src/session-realtime-ledger.ts +28 -14
- package/src/session-realtime-mirror.ts +1 -1
- package/src/session-tenancy.ts +410 -49
- package/src/session-tool-call-settlement.ts +38 -29
- package/src/slack-routing-personal-workspace.ts +67 -0
- package/src/slack-routing.ts +867 -0
- package/src/slack-task-policy-schema.ts +5 -0
- package/src/slack-task-policy.ts +18 -0
- package/src/slack-user-link-access.ts +138 -11
- package/src/task-notes-schema.ts +74 -0
- package/src/task-notes.ts +124 -2
- package/src/turn-initiator.ts +8 -0
- package/src/user-resource-authority.ts +377 -0
- package/src/workspace-authority.ts +160 -0
- package/src/workspace-instruction-policies-schema.ts +53 -1
- package/src/workspace-instruction-policies.ts +528 -77
- package/src/workspace-learning-policy.ts +21 -5
- package/src/workspace-membership-permissions.ts +9 -0
- package/dist/chunk-4SR4HKKA.js.map +0 -1
- package/dist/chunk-6ZYKCRFO.js.map +0 -1
- package/dist/chunk-NXAFLCQX.js +0 -2468
- package/dist/chunk-NXAFLCQX.js.map +0 -1
- package/dist/chunk-SK7YYHBI.js.map +0 -1
- package/dist/chunk-WD5ROSLL.js +0 -117
- package/dist/chunk-WD5ROSLL.js.map +0 -1
- package/dist/chunk-ZWREYEWA.js.map +0 -1
- /package/dist/{chunk-CUPM3FGB.js.map → chunk-2PRS4J5Q.js.map} +0 -0
- /package/dist/{chunk-LTG3S6ZY.js.map → chunk-E6CLMKEE.js.map} +0 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
-- Migration 0285: read-only organization tenancy inventory seam.
|
|
3
|
+
--
|
|
4
|
+
-- The tenancy backfill/parity program needs one authoritative, content-free
|
|
5
|
+
-- count of every legacy-attribution population before any backfill or cutover
|
|
6
|
+
-- gate can be stated: sessions without a canonical owner, resources without an
|
|
7
|
+
-- explicit authority classification, connections per authority lane, humans
|
|
8
|
+
-- with workspace access but no organization-membership anchor, active
|
|
9
|
+
-- memberships without a personal workspace, unattributed workspace writers,
|
|
10
|
+
-- and the two linked-input gates (documents without common authority; Codex
|
|
11
|
+
-- credentials without a recorded connecting human - both owned by their own
|
|
12
|
+
-- issues and only COUNTED here).
|
|
13
|
+
--
|
|
14
|
+
-- The seam is strictly read-only and returns integers only: no identities, no
|
|
15
|
+
-- names, no keys, no values. It validates the caller's account RLS context
|
|
16
|
+
-- against the requested organization exactly like the other tenancy seams and
|
|
17
|
+
-- is executable only by the application role. Nothing here changes runtime
|
|
18
|
+
-- authority, RLS posture, or any write path.
|
|
19
|
+
--
|
|
20
|
+
-- FORCE RLS + SECURITY DEFINER note: every counted table is FORCE ROW LEVEL
|
|
21
|
+
-- SECURITY, which applies even to the function owner unless that owner has
|
|
22
|
+
-- BYPASSRLS - and OpenGeni's documented non-superuser migration-owner posture
|
|
23
|
+
-- (docs/deployment.md) means it usually does not. Most of these tables'
|
|
24
|
+
-- ordinary policies gate on an EXACT single workspace_id match
|
|
25
|
+
-- (workspace_rls_visible), which an org-wide, workspace-less read can never
|
|
26
|
+
-- satisfy, and connections/documents additionally gate personal rows on the
|
|
27
|
+
-- current subject GUC. Rather than widen those policies (which would grant
|
|
28
|
+
-- ordinary application queries org-wide visibility), this migration follows
|
|
29
|
+
-- the established capability-row pattern (0254's
|
|
30
|
+
-- variable_set_authority_capabilities): a transaction-scoped, migration-
|
|
31
|
+
-- owner-only capability that the inventory function claims immediately
|
|
32
|
+
-- before reading and releases immediately after, so the widened visibility
|
|
33
|
+
-- exists only inside this one definer call and only for the migration
|
|
34
|
+
-- owner. Account scoping is still enforced entirely by this function's own
|
|
35
|
+
-- `account_id = p_organization_id` predicates, not by the capability.
|
|
36
|
+
|
|
37
|
+
SET LOCAL lock_timeout = '5s';
|
|
38
|
+
SET LOCAL statement_timeout = '5min';
|
|
39
|
+
|
|
40
|
+
CREATE TABLE opengeni_private.organization_tenancy_inventory_capabilities (
|
|
41
|
+
"backend_pid" integer NOT NULL,
|
|
42
|
+
"transaction_id" xid8 NOT NULL,
|
|
43
|
+
CONSTRAINT "organization_tenancy_inventory_capabilities_pk" PRIMARY KEY (
|
|
44
|
+
"backend_pid", "transaction_id"
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
REVOKE ALL ON TABLE opengeni_private.organization_tenancy_inventory_capabilities FROM PUBLIC;
|
|
48
|
+
|
|
49
|
+
CREATE OR REPLACE FUNCTION opengeni_private.organization_tenancy_inventory_capability_active()
|
|
50
|
+
RETURNS boolean
|
|
51
|
+
LANGUAGE sql
|
|
52
|
+
STABLE
|
|
53
|
+
SECURITY DEFINER
|
|
54
|
+
SET search_path = pg_catalog
|
|
55
|
+
AS $capability_active$
|
|
56
|
+
SELECT EXISTS (
|
|
57
|
+
SELECT 1
|
|
58
|
+
FROM opengeni_private.organization_tenancy_inventory_capabilities capability
|
|
59
|
+
WHERE capability.backend_pid = pg_catalog.pg_backend_pid()
|
|
60
|
+
AND capability.transaction_id = pg_catalog.pg_current_xact_id_if_assigned()
|
|
61
|
+
)
|
|
62
|
+
$capability_active$;
|
|
63
|
+
REVOKE ALL ON FUNCTION
|
|
64
|
+
opengeni_private.organization_tenancy_inventory_capability_active() FROM PUBLIC;
|
|
65
|
+
|
|
66
|
+
DO $organization_tenancy_inventory_capability_policies$
|
|
67
|
+
DECLARE
|
|
68
|
+
data_schema text := current_schema();
|
|
69
|
+
migration_owner text := current_user;
|
|
70
|
+
table_name text;
|
|
71
|
+
BEGIN
|
|
72
|
+
FOREACH table_name IN ARRAY ARRAY[
|
|
73
|
+
'sessions',
|
|
74
|
+
'workspace_variable_sets',
|
|
75
|
+
'rigs',
|
|
76
|
+
'enrollments',
|
|
77
|
+
'connections',
|
|
78
|
+
'documents',
|
|
79
|
+
'codex_subscription_credentials',
|
|
80
|
+
'sandbox_workspace_mutation_admissions',
|
|
81
|
+
'sandbox_retained_processes',
|
|
82
|
+
'organization_memberships'
|
|
83
|
+
] LOOP
|
|
84
|
+
EXECUTE format(
|
|
85
|
+
'CREATE POLICY organization_tenancy_inventory_capability_read ON %I.%I '
|
|
86
|
+
|| 'FOR SELECT USING (current_user = %L AND '
|
|
87
|
+
|| 'opengeni_private.organization_tenancy_inventory_capability_active())',
|
|
88
|
+
data_schema,
|
|
89
|
+
table_name,
|
|
90
|
+
migration_owner
|
|
91
|
+
);
|
|
92
|
+
END LOOP;
|
|
93
|
+
END
|
|
94
|
+
$organization_tenancy_inventory_capability_policies$;
|
|
95
|
+
|
|
96
|
+
CREATE OR REPLACE FUNCTION inventory_organization_tenancy(
|
|
97
|
+
p_organization_id uuid
|
|
98
|
+
) RETURNS jsonb
|
|
99
|
+
LANGUAGE plpgsql
|
|
100
|
+
SECURITY DEFINER
|
|
101
|
+
SET search_path FROM CURRENT
|
|
102
|
+
SET statement_timeout = '30s'
|
|
103
|
+
AS $$
|
|
104
|
+
DECLARE
|
|
105
|
+
result jsonb;
|
|
106
|
+
BEGIN
|
|
107
|
+
IF p_organization_id IS NULL THEN
|
|
108
|
+
RAISE EXCEPTION 'tenancy inventory requires an organization id'
|
|
109
|
+
USING ERRCODE = '22004';
|
|
110
|
+
END IF;
|
|
111
|
+
IF p_organization_id IS DISTINCT FROM nullif(
|
|
112
|
+
pg_catalog.current_setting('opengeni.account_id', true), ''
|
|
113
|
+
)::uuid
|
|
114
|
+
THEN
|
|
115
|
+
RAISE EXCEPTION 'tenancy inventory scope mismatch'
|
|
116
|
+
USING ERRCODE = '42501';
|
|
117
|
+
END IF;
|
|
118
|
+
|
|
119
|
+
INSERT INTO opengeni_private.organization_tenancy_inventory_capabilities (
|
|
120
|
+
backend_pid, transaction_id
|
|
121
|
+
) VALUES (pg_catalog.pg_backend_pid(), pg_catalog.pg_current_xact_id())
|
|
122
|
+
ON CONFLICT DO NOTHING;
|
|
123
|
+
|
|
124
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
125
|
+
'schemaVersion', 1,
|
|
126
|
+
'organizationId', p_organization_id,
|
|
127
|
+
'workspaces', (
|
|
128
|
+
SELECT count(*)::int FROM workspaces w WHERE w.account_id = p_organization_id
|
|
129
|
+
),
|
|
130
|
+
'organizationMemberships', (
|
|
131
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
132
|
+
'byStatus', coalesce(
|
|
133
|
+
(SELECT pg_catalog.jsonb_object_agg(m.status, m.n)
|
|
134
|
+
FROM (
|
|
135
|
+
SELECT om.status, count(*)::int AS n
|
|
136
|
+
FROM organization_memberships om
|
|
137
|
+
WHERE om.account_id = p_organization_id
|
|
138
|
+
GROUP BY om.status
|
|
139
|
+
) m),
|
|
140
|
+
'{}'::jsonb
|
|
141
|
+
),
|
|
142
|
+
'activeWithoutPersonalWorkspace', (
|
|
143
|
+
SELECT count(*)::int FROM organization_memberships om
|
|
144
|
+
WHERE om.account_id = p_organization_id
|
|
145
|
+
AND om.status = 'active'
|
|
146
|
+
AND om.personal_workspace_id IS NULL
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
),
|
|
150
|
+
-- Humans with persisted workspace access in this organization but no
|
|
151
|
+
-- organization-membership anchor: nothing exists yet for a backfill to
|
|
152
|
+
-- attach canonical ownership to (they never re-authenticated post-0219).
|
|
153
|
+
'workspaceMemberSubjectsWithoutMembershipAnchor', (
|
|
154
|
+
SELECT count(DISTINCT wm.subject_id)::int
|
|
155
|
+
FROM workspace_memberships wm
|
|
156
|
+
JOIN workspaces w ON w.id = wm.workspace_id
|
|
157
|
+
WHERE w.account_id = p_organization_id
|
|
158
|
+
AND wm.subject_id LIKE 'user:%'
|
|
159
|
+
AND NOT EXISTS (
|
|
160
|
+
SELECT 1 FROM organization_memberships om
|
|
161
|
+
WHERE om.account_id = p_organization_id
|
|
162
|
+
AND om.subject_id = wm.subject_id
|
|
163
|
+
)
|
|
164
|
+
),
|
|
165
|
+
'sessions', (
|
|
166
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
167
|
+
'total', count(*)::int,
|
|
168
|
+
'ownerless', count(*) FILTER (
|
|
169
|
+
WHERE s.owner_organization_membership_id IS NULL
|
|
170
|
+
)::int,
|
|
171
|
+
'userPrivate', count(*) FILTER (
|
|
172
|
+
WHERE s.visibility = 'user_private'
|
|
173
|
+
)::int,
|
|
174
|
+
'advancedAuthorityEpoch', count(*) FILTER (
|
|
175
|
+
WHERE s.authority_epoch > 1
|
|
176
|
+
)::int
|
|
177
|
+
)
|
|
178
|
+
FROM sessions s WHERE s.account_id = p_organization_id
|
|
179
|
+
),
|
|
180
|
+
'variableSets', (
|
|
181
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
182
|
+
'byScope', coalesce(
|
|
183
|
+
(SELECT pg_catalog.jsonb_object_agg(v.authority_scope, v.n)
|
|
184
|
+
FROM (
|
|
185
|
+
SELECT vs.authority_scope, count(*)::int AS n
|
|
186
|
+
FROM workspace_variable_sets vs
|
|
187
|
+
WHERE vs.account_id = p_organization_id
|
|
188
|
+
GROUP BY vs.authority_scope
|
|
189
|
+
) v),
|
|
190
|
+
'{}'::jsonb
|
|
191
|
+
),
|
|
192
|
+
'unclassified', (
|
|
193
|
+
SELECT count(*)::int FROM workspace_variable_sets vs
|
|
194
|
+
WHERE vs.account_id = p_organization_id AND vs.authority_id IS NULL
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
),
|
|
198
|
+
'rigs', (
|
|
199
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
200
|
+
'byScope', coalesce(
|
|
201
|
+
(SELECT pg_catalog.jsonb_object_agg(r.authority_scope, r.n)
|
|
202
|
+
FROM (
|
|
203
|
+
SELECT rr.authority_scope, count(*)::int AS n
|
|
204
|
+
FROM rigs rr WHERE rr.account_id = p_organization_id
|
|
205
|
+
GROUP BY rr.authority_scope
|
|
206
|
+
) r),
|
|
207
|
+
'{}'::jsonb
|
|
208
|
+
),
|
|
209
|
+
'unclassified', (
|
|
210
|
+
SELECT count(*)::int FROM rigs rr
|
|
211
|
+
WHERE rr.account_id = p_organization_id AND rr.authority_id IS NULL
|
|
212
|
+
)
|
|
213
|
+
)
|
|
214
|
+
),
|
|
215
|
+
'machines', (
|
|
216
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
217
|
+
'byScope', coalesce(
|
|
218
|
+
(SELECT pg_catalog.jsonb_object_agg(e.authority_scope, e.n)
|
|
219
|
+
FROM (
|
|
220
|
+
SELECT en.authority_scope, count(*)::int AS n
|
|
221
|
+
FROM enrollments en WHERE en.account_id = p_organization_id
|
|
222
|
+
GROUP BY en.authority_scope
|
|
223
|
+
) e),
|
|
224
|
+
'{}'::jsonb
|
|
225
|
+
),
|
|
226
|
+
'unclassified', (
|
|
227
|
+
SELECT count(*)::int FROM enrollments en
|
|
228
|
+
WHERE en.account_id = p_organization_id AND en.authority_id IS NULL
|
|
229
|
+
)
|
|
230
|
+
)
|
|
231
|
+
),
|
|
232
|
+
'connections', (
|
|
233
|
+
SELECT coalesce(
|
|
234
|
+
(SELECT pg_catalog.jsonb_object_agg(c.authority_scope, c.n)
|
|
235
|
+
FROM (
|
|
236
|
+
SELECT cn.authority_scope, count(*)::int AS n
|
|
237
|
+
FROM connections cn WHERE cn.account_id = p_organization_id
|
|
238
|
+
GROUP BY cn.authority_scope
|
|
239
|
+
) c),
|
|
240
|
+
'{}'::jsonb
|
|
241
|
+
)
|
|
242
|
+
),
|
|
243
|
+
-- Linked-input gate (documents-internal migration is owned elsewhere and
|
|
244
|
+
-- never written by this program; the count is the cutover gate input).
|
|
245
|
+
'documents', (
|
|
246
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
247
|
+
'total', count(*)::int,
|
|
248
|
+
-- The gate population is a LEGACY personal Document with no common
|
|
249
|
+
-- authority - organization/workspace documents are REQUIRED to have
|
|
250
|
+
-- a NULL authority_id forever (documents_authority_chk, 0258) and
|
|
251
|
+
-- must never be counted as unmigrated.
|
|
252
|
+
'legacyPersonalNullAuthority', count(*) FILTER (
|
|
253
|
+
WHERE d.authority_kind = 'personal' AND d.authority_id IS NULL
|
|
254
|
+
)::int
|
|
255
|
+
)
|
|
256
|
+
FROM documents d WHERE d.account_id = p_organization_id
|
|
257
|
+
),
|
|
258
|
+
-- Linked-input gate (ownership repair is owned elsewhere; never backfilled
|
|
259
|
+
-- heuristically; the count is the cutover gate input).
|
|
260
|
+
'codexCredentials', (
|
|
261
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
262
|
+
'total', count(*)::int,
|
|
263
|
+
'unattributedConnector', count(*) FILTER (
|
|
264
|
+
WHERE cc.connected_by_subject_id IS NULL
|
|
265
|
+
)::int
|
|
266
|
+
)
|
|
267
|
+
FROM codex_subscription_credentials cc
|
|
268
|
+
WHERE cc.account_id = p_organization_id
|
|
269
|
+
),
|
|
270
|
+
'workspaceWriters', (
|
|
271
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
272
|
+
'admissions', (
|
|
273
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
274
|
+
'total', count(*)::int,
|
|
275
|
+
'legacyUnattributed', count(*) FILTER (
|
|
276
|
+
WHERE a.initiator_kind = 'legacy_unattributed'
|
|
277
|
+
)::int
|
|
278
|
+
)
|
|
279
|
+
FROM sandbox_workspace_mutation_admissions a
|
|
280
|
+
WHERE a.account_id = p_organization_id
|
|
281
|
+
),
|
|
282
|
+
'retainedProcesses', (
|
|
283
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
284
|
+
'total', count(*)::int,
|
|
285
|
+
'legacyUnattributed', count(*) FILTER (
|
|
286
|
+
WHERE p.initiator_kind = 'legacy_unattributed'
|
|
287
|
+
)::int
|
|
288
|
+
)
|
|
289
|
+
FROM sandbox_retained_processes p
|
|
290
|
+
WHERE p.account_id = p_organization_id
|
|
291
|
+
)
|
|
292
|
+
)
|
|
293
|
+
)
|
|
294
|
+
) INTO result;
|
|
295
|
+
|
|
296
|
+
DELETE FROM opengeni_private.organization_tenancy_inventory_capabilities
|
|
297
|
+
WHERE backend_pid = pg_catalog.pg_backend_pid()
|
|
298
|
+
AND transaction_id = pg_catalog.pg_current_xact_id_if_assigned();
|
|
299
|
+
RETURN result;
|
|
300
|
+
EXCEPTION WHEN OTHERS THEN
|
|
301
|
+
DELETE FROM opengeni_private.organization_tenancy_inventory_capabilities
|
|
302
|
+
WHERE backend_pid = pg_catalog.pg_backend_pid()
|
|
303
|
+
AND transaction_id = pg_catalog.pg_current_xact_id_if_assigned();
|
|
304
|
+
RAISE;
|
|
305
|
+
END
|
|
306
|
+
$$;
|
|
307
|
+
|
|
308
|
+
REVOKE ALL ON FUNCTION inventory_organization_tenancy(uuid) FROM PUBLIC;
|
|
309
|
+
DO $tenancy_inventory_grant$
|
|
310
|
+
BEGIN
|
|
311
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'opengeni_app') THEN
|
|
312
|
+
GRANT EXECUTE ON FUNCTION inventory_organization_tenancy(uuid) TO opengeni_app;
|
|
313
|
+
-- The predicate is harmless to expose (a read-only boolean over a
|
|
314
|
+
-- transaction-local bookkeeping row, never data) and MUST be independently
|
|
315
|
+
-- grantable here: an ordinary opengeni_app-effective role touching ANY
|
|
316
|
+
-- table this capability protects (e.g. sessions, via session_reference_
|
|
317
|
+
-- visible's inlined SQL body evaluating every PERMISSIVE policy) needs
|
|
318
|
+
-- EXECUTE on every predicate function those policies reference, or the
|
|
319
|
+
-- unrelated read fails closed with a permission error instead of the
|
|
320
|
+
-- policy simply evaluating false. Matches 0254's identical explicit grant
|
|
321
|
+
-- for variable_set_authority_capability_active - relying solely on
|
|
322
|
+
-- provisionRoles' blanket schema-wide sweep is not sufficient for a
|
|
323
|
+
-- database whose test/deploy path never runs that step.
|
|
324
|
+
GRANT EXECUTE ON FUNCTION
|
|
325
|
+
opengeni_private.organization_tenancy_inventory_capability_active()
|
|
326
|
+
TO opengeni_app;
|
|
327
|
+
END IF;
|
|
328
|
+
END
|
|
329
|
+
$tenancy_inventory_grant$;
|