From c598383f2774bb764539a1d6498e94dbce89e444 Mon Sep 17 00:00:00 2001 From: hugocasa Date: Fri, 27 Nov 2026 12:01:58 +0100 Subject: [PATCH] refactor: store a view-only grant as "read" in extra_perms instead of a view_only column Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 4 +- ...cfca8913ba1129fdf4978a8a4738689786160.json | 19 ++++ ...4c286a2508d5fc8303356b74502a230a46e26.json | 16 --- ...74be5dc49bd2765ac3a81961c9eaaa477e3a4.json | 19 ---- ...a9aa70a8f89777e95e0415877ffa90ecd87c.json} | 4 +- ...cfbdf9f4c3037766c287c6a2eaa9a03b4fab9.json | 26 ----- ...416534453510861774c9529c2624f7c271c33.json | 15 --- ...4e2da64a443e7699b8d8579a5795d69dde38b.json | 15 --- ...a8dad940c6c19baa2ca4481ed69bb481c83f.json} | 4 +- ...41508776f5f998821e04bc92df917176cea6.json} | 18 +-- ...4eeadcf092b37a20d03d52f2160ca21f79fb0.json | 15 +++ ...c7150c7292a4510ba5c751e40f7c5e2fc5841.json | 15 --- ...fea97aec4d6d3ec65d3e7402811c7dddbbf64.json | 16 +++ ...53461dee4bcc8d7180a9a517d5809c42e11d7.json | 15 +++ ...87374b4ff0fd03c4c48bf16d876df3978bdfa.json | 16 --- ...ddb79398f57a34d180d08aa00aaaaa1050c8.json} | 18 +-- ...5650c53b43416ea5913d1755bc5214b8c715f.json | 26 +++++ ...c9c94d1f3a853529c04d786f0c1221b3fd47.json} | 36 +++--- ...aa7f5755da9997419c4a9d07b30d4da318bea.json | 15 +++ ...ec55d1c07998b1bd0268725d34f7f0b98103.json} | 4 +- ...5f33faa61710388f71f04da2d4569bc3dd71.json} | 5 +- ...e5fe53514913562ca93de44d9ad0a02a0fe8.json} | 14 +-- ...7f90a04016cd7fb9d249b7165f0f31c28b665.json | 24 ---- ...3103c9ac8924bdf959602fb224bf32677df4a.json | 47 -------- ...7399e3000b671a2133f9c9849a899360f1bb1.json | 16 --- ...7be041c6f434982519a7d0634cb4f8358001f.json | 35 ++++++ ...64eb6af24e8d8aa99b846f21f2ed49c320bdc.json | 16 +++ ...3eb83d5c19e32aef199bf161e8ba8d1adf176.json | 16 +++ ...326443d7b78639f8316c1b8e2cd27965af731.json | 15 --- ...28d84f1ca3c91de86d520dce06ac12d557bd5.json | 24 ++++ ...6258c1635506d4d0edd9d9c3d40fc38cabf88.json | 15 --- ...48f9bd36a86233f3b0a3e73f51698ed353dd.json} | 4 +- ...14ad64feb4129a0117d2789346ebd370d33a2.json | 41 +++++++ ...737b3b4b662a89148cf6ac70eb3563ad7f0c5.json | 15 +++ ...c104f7b8ea88130692ce9c1390bda289627a.json} | 4 +- ...e2c8c7043e89e5fae70613c8230d94a183f6c.json | 16 --- ...d10fc10d9ec4dc2359f43d79fe255d101cad8.json | 15 +++ ...e17d56a1c7c403a2dcbe4335ace15798b2e86.json | 15 --- .../20261113143004_acl_read_level.down.sql | 40 +++++++ .../20261113143004_acl_read_level.up.sql | 45 ++++++++ .../20261113143004_acl_view_only.down.sql | 5 - .../20261113143004_acl_view_only.up.sql | 15 --- backend/windmill-api-flows/src/flows.rs | 14 +-- backend/windmill-api-groups/src/access.rs | 4 +- backend/windmill-api-groups/src/folders.rs | 87 +++++---------- .../windmill-api-groups/src/granular_acls.rs | 78 ++++--------- .../tests/view_only_acls.rs | 27 +++++ backend/windmill-api-scripts/src/scripts.rs | 22 ---- backend/windmill-api-users/src/users.rs | 8 +- .../windmill-api-workspaces/src/workspaces.rs | 16 +-- .../src/workspaces_extra.rs | 8 +- backend/windmill-api/openapi.yaml | 104 +++++------------- .../src/ai_session_tools/gen/tools.json | 2 +- backend/windmill-api/src/jobs.rs | 23 ++-- backend/windmill-api/src/mcp/utils.rs | 4 +- backend/windmill-api/src/offboarding.rs | 4 +- backend/windmill-api/src/trash.rs | 10 +- backend/windmill-api/src/users.rs | 12 +- backend/windmill-api/src/workspaces_export.rs | 23 +--- backend/windmill-common/src/auth.rs | 29 +++-- backend/windmill-common/src/scripts.rs | 5 +- backend/windmill-store/src/resources.rs | 12 +- backend/windmill-types/src/flows.rs | 8 -- backend/windmill-types/src/scripts.rs | 10 +- cli/src/commands/flow/flow.ts | 4 - cli/src/commands/folder/folder.ts | 4 +- cli/src/commands/script/script.ts | 6 - cli/src/commands/user/user.ts | 2 +- cli/src/core/extra_perms.ts | 66 +++++------ cli/test/extra_perms_levels_unit.test.ts | 44 ++++++++ cli/test/extra_perms_view_only_unit.test.ts | 48 -------- docs/workspace-roles.md | 33 ++++-- .../src/lib/components/FolderEditor.svelte | 16 +-- .../src/lib/components/GroupEditor.svelte | 8 +- .../src/lib/components/ResourceEditor.svelte | 3 +- frontend/src/lib/components/RunForm.svelte | 3 +- .../components/RunFormAdvancedPopup.svelte | 3 +- .../src/lib/components/SharedBadge.svelte | 10 +- .../src/lib/components/VariableEditor.svelte | 5 +- .../apps/editor/InWorkspaceAppViewer.svelte | 5 +- .../components/assets/VolumesDrawer.svelte | 11 +- .../components/copilot/chat/global/core.ts | 2 +- .../copilot/chat/global/workspaceItems.ts | 3 +- .../lib/components/details/FlowDetail.svelte | 2 +- .../components/details/ScriptDetail.svelte | 5 +- .../flows/content/AgentDetailPage.svelte | 2 +- .../flows/content/AgentResourceBar.svelte | 5 +- .../lib/components/flows/linkedAgentDrafts.ts | 3 +- .../itemSettings/ItemAccessList.svelte | 35 ++---- .../itemSettings/inheritedAccess.ts | 14 ++- .../amqp/AmqpTriggerEditorInner.svelte | 3 +- .../azure/AzureTriggerEditorInner.svelte | 3 +- .../email/EmailTriggerEditorInner.svelte | 5 +- .../triggers/gcp/GcpTriggerEditorInner.svelte | 3 +- .../triggers/http/RouteEditorInner.svelte | 5 +- .../kafka/KafkaTriggerEditorInner.svelte | 3 +- .../mqtt/MqttTriggerEditorInner.svelte | 3 +- .../nats/NatsTriggerEditorInner.svelte | 3 +- .../PostgresTriggerEditorInner.svelte | 3 +- .../schedules/ScheduleEditorInner.svelte | 3 +- .../triggers/sqs/SqsTriggerEditorInner.svelte | 3 +- .../WebsocketTriggerEditorInner.svelte | 10 +- .../src/lib/components/workspacePicker.ts | 3 +- frontend/src/lib/editRights.ts | 5 +- frontend/src/lib/folderDraft.ts | 5 +- frontend/src/lib/operatorWriteRights.ts | 5 +- frontend/src/lib/utils.ts | 46 ++++---- frontend/src/lib/utils_workspace_deploy.ts | 3 +- 108 files changed, 808 insertions(+), 916 deletions(-) create mode 100644 backend/.sqlx/query-05b610ad1809d487c32e85b0392cfca8913ba1129fdf4978a8a4738689786160.json delete mode 100644 backend/.sqlx/query-0c2eb37f3c10de954af0196596e4c286a2508d5fc8303356b74502a230a46e26.json delete mode 100644 backend/.sqlx/query-10d82ac4c6c42512110d44bb41f74be5dc49bd2765ac3a81961c9eaaa477e3a4.json rename backend/.sqlx/{query-696c2f4c76c3876c4ff65ebacfd2aae6d9c8ccdcc0e621ac5ca2bf28a30fe2e4.json => query-1f003a8a6a9402f5f7021b032281a9aa70a8f89777e95e0415877ffa90ecd87c.json} (60%) delete mode 100644 backend/.sqlx/query-2823efb1bd4f76d2887a08e6f53cfbdf9f4c3037766c287c6a2eaa9a03b4fab9.json delete mode 100644 backend/.sqlx/query-410ca1d957cbd4f10c6c215f911416534453510861774c9529c2624f7c271c33.json delete mode 100644 backend/.sqlx/query-412524514458af602f4319887d04e2da64a443e7699b8d8579a5795d69dde38b.json rename backend/.sqlx/{query-0766c40a729c2ba448f838b4492d6e2cad53d4ad27041beab87f0bf5fab92a16.json => query-41a17f941cf4d97ebbca23a0a206a8dad940c6c19baa2ca4481ed69bb481c83f.json} (60%) rename backend/.sqlx/{query-4f2c9e6206391e9b7dbcbd0bffeeef5fb70f6cdf445c114f8f2925ba39551be7.json => query-42600bdeb6b86ac306ab276cb49241508776f5f998821e04bc92df917176cea6.json} (80%) create mode 100644 backend/.sqlx/query-4ca364e493dd51d5f83489dc4674eeadcf092b37a20d03d52f2160ca21f79fb0.json delete mode 100644 backend/.sqlx/query-50c7797e3214841ba005618e170c7150c7292a4510ba5c751e40f7c5e2fc5841.json create mode 100644 backend/.sqlx/query-580271c5fe178f5e31f3e211cd7fea97aec4d6d3ec65d3e7402811c7dddbbf64.json create mode 100644 backend/.sqlx/query-5b4214deb7677ae16df0bea7c6553461dee4bcc8d7180a9a517d5809c42e11d7.json delete mode 100644 backend/.sqlx/query-5d7c49c74b6324215f89b0a3f1587374b4ff0fd03c4c48bf16d876df3978bdfa.json rename backend/.sqlx/{query-95a6b9f7c302ca86f10a9ee0b51b10ec320663d2038928c90a8199335c53d482.json => query-636dd6906a20b608eea34e04a81bddb79398f57a34d180d08aa00aaaaa1050c8.json} (79%) create mode 100644 backend/.sqlx/query-6bb977fdca71a6a98a651b986ad5650c53b43416ea5913d1755bc5214b8c715f.json rename backend/.sqlx/{query-03894b75ae362139b523ddaaff21e30392acb80022005e2bb74199b5fb4375e7.json => query-6e45704fddf3deb181520b295018c9c94d1f3a853529c04d786f0c1221b3fd47.json} (67%) create mode 100644 backend/.sqlx/query-706f2227e34971d22a577b33f6aaa7f5755da9997419c4a9d07b30d4da318bea.json rename backend/.sqlx/{query-251c6463cc54705b09ecab2a155628da162490e15743c4bb9a0e8c205bee1bfa.json => query-70bad6ac45db6d03c59aa375f915ec55d1c07998b1bd0268725d34f7f0b98103.json} (61%) rename backend/.sqlx/{query-092fb3f2bc24d2d1692a3fc4864015176899bbd9c5223d65549a8997af565152.json => query-813b91a338f2fe46a7d27a155c435f33faa61710388f71f04da2d4569bc3dd71.json} (59%) rename backend/.sqlx/{query-2e897638b8b4f77d6a3e30a0f7b1fd7009ebe1082b19456d73686d076526affb.json => query-825b7e301307373ecfa6b59b4091e5fe53514913562ca93de44d9ad0a02a0fe8.json} (79%) delete mode 100644 backend/.sqlx/query-91b82ddd4964a23bb69dcdfc5ff7f90a04016cd7fb9d249b7165f0f31c28b665.json delete mode 100644 backend/.sqlx/query-9f4611d4968b551a9e7c33bcf383103c9ac8924bdf959602fb224bf32677df4a.json delete mode 100644 backend/.sqlx/query-a875cca3478a982c08e9263876a7399e3000b671a2133f9c9849a899360f1bb1.json create mode 100644 backend/.sqlx/query-b1f55dd2395500bfde5ca07967c7be041c6f434982519a7d0634cb4f8358001f.json create mode 100644 backend/.sqlx/query-b40c9e2d637cf0f2f49fd4c720b64eb6af24e8d8aa99b846f21f2ed49c320bdc.json create mode 100644 backend/.sqlx/query-bf763c3ae4951537033d18ce48d3eb83d5c19e32aef199bf161e8ba8d1adf176.json delete mode 100644 backend/.sqlx/query-c39e37756387c774e30177c2997326443d7b78639f8316c1b8e2cd27965af731.json create mode 100644 backend/.sqlx/query-c4eaa6e3b1d30a72ef1b54b2b7f28d84f1ca3c91de86d520dce06ac12d557bd5.json delete mode 100644 backend/.sqlx/query-c7841d246e0a53979507c278d606258c1635506d4d0edd9d9c3d40fc38cabf88.json rename backend/.sqlx/{query-924b4941829f69ff96c55f0a432298de7cf3aa1690c931a5b569fce3203a86c3.json => query-cc9e2460b8fded240eff64cf3cf348f9bd36a86233f3b0a3e73f51698ed353dd.json} (61%) create mode 100644 backend/.sqlx/query-d64af095618cdfd5e8a5a2ad3b714ad64feb4129a0117d2789346ebd370d33a2.json create mode 100644 backend/.sqlx/query-df1fe2e7ef004b8de0e626f40fd737b3b4b662a89148cf6ac70eb3563ad7f0c5.json rename backend/.sqlx/{query-a6deb6191f84b084cb523c7385a3977c15deffa9e484945e53d8e0aa46f1fbc1.json => query-e38dd0f093636efa2ec1cda4618fc104f7b8ea88130692ce9c1390bda289627a.json} (61%) delete mode 100644 backend/.sqlx/query-e6818d4b9ea9991b252f5771c3fe2c8c7043e89e5fae70613c8230d94a183f6c.json create mode 100644 backend/.sqlx/query-e81eaa501b4af1269a4929ec660d10fc10d9ec4dc2359f43d79fe255d101cad8.json delete mode 100644 backend/.sqlx/query-f0a7de33927a3c1ec11387870f5e17d56a1c7c403a2dcbe4335ace15798b2e86.json create mode 100644 backend/migrations/20261113143004_acl_read_level.down.sql create mode 100644 backend/migrations/20261113143004_acl_read_level.up.sql delete mode 100644 backend/migrations/20261113143004_acl_view_only.down.sql delete mode 100644 backend/migrations/20261113143004_acl_view_only.up.sql create mode 100644 cli/test/extra_perms_levels_unit.test.ts delete mode 100644 cli/test/extra_perms_view_only_unit.test.ts diff --git a/AGENTS.md b/AGENTS.md index 44027e3244..83cb5518e9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -46,8 +46,8 @@ Open-source platform for internal tools, workflows, API integrations, background - **Enterprise**: `docs/enterprise.md` — EE file conventions and PR workflow - **Workspace roles**: `docs/workspace-roles.md` — instance-defined roles with per-workspace overrides, the capabilities a role holds, why `ApiAuthed::is_operator` must be derived from the - role, the `role_seat` table billing reads, and the view-only grants on folders and items, which - every copy of a script, flow, agent or folder row must carry + role, the `role_seat` table billing reads, and the levels an `extra_perms` value can hold + (`true`/`false` or `"read"`/`"run"`/`"write"`), which every reader must accept - **Operator write rights**: `docs/operator-write-rights.md` — which `operator_settings` flags are enforced rather than cosmetic, and why a right that is granted-unless-withdrawn needs `Option` fields and a jsonb merge rather than a serde default diff --git a/backend/.sqlx/query-05b610ad1809d487c32e85b0392cfca8913ba1129fdf4978a8a4738689786160.json b/backend/.sqlx/query-05b610ad1809d487c32e85b0392cfca8913ba1129fdf4978a8a4738689786160.json new file mode 100644 index 0000000000..5c6ee3d506 --- /dev/null +++ b/backend/.sqlx/query-05b610ad1809d487c32e85b0392cfca8913ba1129fdf4978a8a4738689786160.json @@ -0,0 +1,19 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO script\n (workspace_id, hash, path, parent_hashes, summary, description, content, created_by, schema, is_template, extra_perms, lock, language, kind, tag, envs, concurrent_limit, concurrency_time_window_s, cache_ttl, cache_ignore_s3_path, dedicated_worker, ws_error_handler_muted, priority, restart_unless_cancelled, delete_after_use, delete_after_secs, timeout, concurrency_key, visible_to_runner_only, auto_kind, codebase, has_preprocessor, on_behalf_of, on_behalf_of_email, schema_validation, assets, debounce_key, debounce_delay_s, runnable_settings_handle, modules, labels, job_token_scopes, lock_error_logs, created_at)\n\n SELECT workspace_id, $1, path, array_prepend($2::bigint, COALESCE(parent_hashes, '{}'::bigint[])), summary, description, content, created_by, schema, is_template, extra_perms, $4::text, language, kind, tag, envs, concurrent_limit, concurrency_time_window_s, cache_ttl, cache_ignore_s3_path, dedicated_worker, ws_error_handler_muted, priority, restart_unless_cancelled, delete_after_use, delete_after_secs, timeout, concurrency_key, visible_to_runner_only, auto_kind, codebase, has_preprocessor, on_behalf_of, on_behalf_of_email, schema_validation, assets, debounce_key, debounce_delay_s, runnable_settings_handle, COALESCE($5::jsonb, modules), labels, job_token_scopes, $6::text, clock_timestamp()\n\n FROM script WHERE hash = $2 AND workspace_id = $3;\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int8", + "Int8", + "Text", + "Text", + "Jsonb", + "Text" + ] + }, + "nullable": [] + }, + "hash": "05b610ad1809d487c32e85b0392cfca8913ba1129fdf4978a8a4738689786160" +} diff --git a/backend/.sqlx/query-0c2eb37f3c10de954af0196596e4c286a2508d5fc8303356b74502a230a46e26.json b/backend/.sqlx/query-0c2eb37f3c10de954af0196596e4c286a2508d5fc8303356b74502a230a46e26.json deleted file mode 100644 index 8372391938..0000000000 --- a/backend/.sqlx/query-0c2eb37f3c10de954af0196596e4c286a2508d5fc8303356b74502a230a46e26.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO resource (workspace_id, path, value, description, resource_type, extra_perms, view_only, edited_at, created_by)\n SELECT $2, path,\n CASE WHEN $3::text IS NOT NULL AND resource_type = 'ai_agent'\n AND jsonb_typeof(value) = 'object' AND value ? 'on_behalf_of'\n THEN jsonb_set(value, '{on_behalf_of}', to_jsonb($3::text))\n ELSE value END,\n description, resource_type, extra_perms, view_only, edited_at, created_by\n FROM resource\n WHERE workspace_id = $1", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - "Varchar", - "Text" - ] - }, - "nullable": [] - }, - "hash": "0c2eb37f3c10de954af0196596e4c286a2508d5fc8303356b74502a230a46e26" -} diff --git a/backend/.sqlx/query-10d82ac4c6c42512110d44bb41f74be5dc49bd2765ac3a81961c9eaaa477e3a4.json b/backend/.sqlx/query-10d82ac4c6c42512110d44bb41f74be5dc49bd2765ac3a81961c9eaaa477e3a4.json deleted file mode 100644 index efc202a8e8..0000000000 --- a/backend/.sqlx/query-10d82ac4c6c42512110d44bb41f74be5dc49bd2765ac3a81961c9eaaa477e3a4.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO script\n (workspace_id, hash, path, parent_hashes, summary, description, content, created_by, schema, is_template, extra_perms, view_only, lock, language, kind, tag, envs, concurrent_limit, concurrency_time_window_s, cache_ttl, cache_ignore_s3_path, dedicated_worker, ws_error_handler_muted, priority, restart_unless_cancelled, delete_after_use, delete_after_secs, timeout, concurrency_key, visible_to_runner_only, auto_kind, codebase, has_preprocessor, on_behalf_of, on_behalf_of_email, schema_validation, assets, debounce_key, debounce_delay_s, runnable_settings_handle, modules, labels, job_token_scopes, lock_error_logs, created_at)\n\n SELECT workspace_id, $1, path, array_prepend($2::bigint, COALESCE(parent_hashes, '{}'::bigint[])), summary, description, content, created_by, schema, is_template, extra_perms, view_only, $4::text, language, kind, tag, envs, concurrent_limit, concurrency_time_window_s, cache_ttl, cache_ignore_s3_path, dedicated_worker, ws_error_handler_muted, priority, restart_unless_cancelled, delete_after_use, delete_after_secs, timeout, concurrency_key, visible_to_runner_only, auto_kind, codebase, has_preprocessor, on_behalf_of, on_behalf_of_email, schema_validation, assets, debounce_key, debounce_delay_s, runnable_settings_handle, COALESCE($5::jsonb, modules), labels, job_token_scopes, $6::text, clock_timestamp()\n\n FROM script WHERE hash = $2 AND workspace_id = $3;\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Int8", - "Text", - "Text", - "Jsonb", - "Text" - ] - }, - "nullable": [] - }, - "hash": "10d82ac4c6c42512110d44bb41f74be5dc49bd2765ac3a81961c9eaaa477e3a4" -} diff --git a/backend/.sqlx/query-696c2f4c76c3876c4ff65ebacfd2aae6d9c8ccdcc0e621ac5ca2bf28a30fe2e4.json b/backend/.sqlx/query-1f003a8a6a9402f5f7021b032281a9aa70a8f89777e95e0415877ffa90ecd87c.json similarity index 60% rename from backend/.sqlx/query-696c2f4c76c3876c4ff65ebacfd2aae6d9c8ccdcc0e621ac5ca2bf28a30fe2e4.json rename to backend/.sqlx/query-1f003a8a6a9402f5f7021b032281a9aa70a8f89777e95e0415877ffa90ecd87c.json index 5c998818d1..a7f4cfa7b3 100644 --- a/backend/.sqlx/query-696c2f4c76c3876c4ff65ebacfd2aae6d9c8ccdcc0e621ac5ca2bf28a30fe2e4.json +++ b/backend/.sqlx/query-1f003a8a6a9402f5f7021b032281a9aa70a8f89777e95e0415877ffa90ecd87c.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "UPDATE resource SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)), view_only = array_replace(view_only, 'u/' || $2, 'u/' || $1) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", + "query": "UPDATE resource SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", "describe": { "columns": [], "parameters": { @@ -12,5 +12,5 @@ }, "nullable": [] }, - "hash": "696c2f4c76c3876c4ff65ebacfd2aae6d9c8ccdcc0e621ac5ca2bf28a30fe2e4" + "hash": "1f003a8a6a9402f5f7021b032281a9aa70a8f89777e95e0415877ffa90ecd87c" } diff --git a/backend/.sqlx/query-2823efb1bd4f76d2887a08e6f53cfbdf9f4c3037766c287c6a2eaa9a03b4fab9.json b/backend/.sqlx/query-2823efb1bd4f76d2887a08e6f53cfbdf9f4c3037766c287c6a2eaa9a03b4fab9.json deleted file mode 100644 index 456ba4e5f0..0000000000 --- a/backend/.sqlx/query-2823efb1bd4f76d2887a08e6f53cfbdf9f4c3037766c287c6a2eaa9a03b4fab9.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "WITH item AS (\n -- The newest version only: a script reusing a retired path starts with no grants,\n -- and the retired versions' must not run it.\n (SELECT extra_perms, view_only FROM script\n WHERE $5 = 'script' AND workspace_id = $1 AND path = $2\n ORDER BY created_at DESC LIMIT 1)\n UNION ALL SELECT extra_perms, view_only FROM flow\n WHERE $5 = 'flow' AND workspace_id = $1 AND path = $2\n UNION ALL SELECT extra_perms, view_only FROM resource\n WHERE $5 = 'resource' AND workspace_id = $1 AND path = $2\n )\n SELECT EXISTS (\n SELECT 1 FROM item WHERE acl_grants_run(item.extra_perms, item.view_only, $4)\n ) OR EXISTS (\n SELECT 1 FROM folder f\n WHERE f.workspace_id = $1 AND f.name = $3\n AND (f.owners::text[] && $4 OR acl_grants_run(f.extra_perms, f.view_only, $4))\n ) AS \"can_run!\"", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "can_run!", - "type_info": "Bool" - } - ], - "parameters": { - "Left": [ - "Text", - "Text", - "Text", - "TextArray", - "Text" - ] - }, - "nullable": [ - null - ] - }, - "hash": "2823efb1bd4f76d2887a08e6f53cfbdf9f4c3037766c287c6a2eaa9a03b4fab9" -} diff --git a/backend/.sqlx/query-410ca1d957cbd4f10c6c215f911416534453510861774c9529c2624f7c271c33.json b/backend/.sqlx/query-410ca1d957cbd4f10c6c215f911416534453510861774c9529c2624f7c271c33.json deleted file mode 100644 index 72c1f2498d..0000000000 --- a/backend/.sqlx/query-410ca1d957cbd4f10c6c215f911416534453510861774c9529c2624f7c271c33.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "UPDATE folder SET view_only = ARRAY(\n SELECT v FROM unnest(view_only) v WHERE extra_perms->>v = 'false'\n ) WHERE name = $1 AND workspace_id = $2", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - "Text" - ] - }, - "nullable": [] - }, - "hash": "410ca1d957cbd4f10c6c215f911416534453510861774c9529c2624f7c271c33" -} diff --git a/backend/.sqlx/query-412524514458af602f4319887d04e2da64a443e7699b8d8579a5795d69dde38b.json b/backend/.sqlx/query-412524514458af602f4319887d04e2da64a443e7699b8d8579a5795d69dde38b.json deleted file mode 100644 index e61d07843d..0000000000 --- a/backend/.sqlx/query-412524514458af602f4319887d04e2da64a443e7699b8d8579a5795d69dde38b.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO flow (\n workspace_id, path, summary, description, value, edited_by, edited_at,\n archived, schema, extra_perms, view_only, dependency_job, tag,\n ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only,\n concurrency_key, versions, on_behalf_of, on_behalf_of_email, lock_error_logs,\n job_token_scopes\n )\n SELECT $2, path, summary, description, value, edited_by, edited_at,\n archived, schema, extra_perms, view_only, NULL, tag,\n ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only,\n concurrency_key, ARRAY[]::bigint[],\n -- Same predicate as clone_scripts.\n CASE WHEN on_behalf_of LIKE 'u/%' THEN\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM usr u WHERE u.workspace_id = $2::varchar\n AND u.username = substring(on_behalf_of from 3)\n UNION ALL\n SELECT 1 FROM password p WHERE p.super_admin\n AND (p.username = substring(on_behalf_of from 3)\n OR p.email = substring(on_behalf_of from 3))))\n WHEN on_behalf_of LIKE 'g/%' THEN\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM group_ g WHERE g.workspace_id = $2::varchar\n AND g.name = substring(on_behalf_of from 3)))\n ELSE\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM usr u WHERE u.workspace_id = $2::varchar\n AND u.username = on_behalf_of\n UNION ALL\n SELECT 1 FROM password p WHERE p.email = on_behalf_of\n AND p.super_admin))\n END, on_behalf_of_email, lock_error_logs, job_token_scopes\n FROM flow\n WHERE workspace_id = $1", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - "Varchar" - ] - }, - "nullable": [] - }, - "hash": "412524514458af602f4319887d04e2da64a443e7699b8d8579a5795d69dde38b" -} diff --git a/backend/.sqlx/query-0766c40a729c2ba448f838b4492d6e2cad53d4ad27041beab87f0bf5fab92a16.json b/backend/.sqlx/query-41a17f941cf4d97ebbca23a0a206a8dad940c6c19baa2ca4481ed69bb481c83f.json similarity index 60% rename from backend/.sqlx/query-0766c40a729c2ba448f838b4492d6e2cad53d4ad27041beab87f0bf5fab92a16.json rename to backend/.sqlx/query-41a17f941cf4d97ebbca23a0a206a8dad940c6c19baa2ca4481ed69bb481c83f.json index 4324cda660..46e0ff3af3 100644 --- a/backend/.sqlx/query-0766c40a729c2ba448f838b4492d6e2cad53d4ad27041beab87f0bf5fab92a16.json +++ b/backend/.sqlx/query-41a17f941cf4d97ebbca23a0a206a8dad940c6c19baa2ca4481ed69bb481c83f.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT name FROM folder\n WHERE workspace_id = $2 AND extra_perms ?| $1 AND cardinality(view_only) > 0\n AND NOT owners::text[] && $1 AND NOT acl_grants_run(extra_perms, view_only, $1)", + "query": "SELECT name FROM folder\n WHERE workspace_id = $2 AND extra_perms ?| $1\n AND NOT owners::text[] && $1 AND NOT acl_grants_run(extra_perms, $1)", "describe": { "columns": [ { @@ -19,5 +19,5 @@ false ] }, - "hash": "0766c40a729c2ba448f838b4492d6e2cad53d4ad27041beab87f0bf5fab92a16" + "hash": "41a17f941cf4d97ebbca23a0a206a8dad940c6c19baa2ca4481ed69bb481c83f" } diff --git a/backend/.sqlx/query-4f2c9e6206391e9b7dbcbd0bffeeef5fb70f6cdf445c114f8f2925ba39551be7.json b/backend/.sqlx/query-42600bdeb6b86ac306ab276cb49241508776f5f998821e04bc92df917176cea6.json similarity index 80% rename from backend/.sqlx/query-4f2c9e6206391e9b7dbcbd0bffeeef5fb70f6cdf445c114f8f2925ba39551be7.json rename to backend/.sqlx/query-42600bdeb6b86ac306ab276cb49241508776f5f998821e04bc92df917176cea6.json index 6d9ca5ab10..617930de62 100644 --- a/backend/.sqlx/query-4f2c9e6206391e9b7dbcbd0bffeeef5fb70f6cdf445c114f8f2925ba39551be7.json +++ b/backend/.sqlx/query-42600bdeb6b86ac306ab276cb49241508776f5f998821e04bc92df917176cea6.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT workspace_id, name, display_name, owners, extra_perms, view_only, summary, created_by, edited_at, default_permissioned_as, labels FROM folder WHERE name = $1 AND workspace_id = $2", + "query": "SELECT workspace_id, name, display_name, owners, extra_perms, summary, created_by, edited_at, default_permissioned_as, labels FROM folder WHERE name = $1 AND workspace_id = $2", "describe": { "columns": [ { @@ -30,31 +30,26 @@ }, { "ordinal": 5, - "name": "view_only", - "type_info": "TextArray" - }, - { - "ordinal": 6, "name": "summary", "type_info": "Text" }, { - "ordinal": 7, + "ordinal": 6, "name": "created_by", "type_info": "Varchar" }, { - "ordinal": 8, + "ordinal": 7, "name": "edited_at", "type_info": "Timestamptz" }, { - "ordinal": 9, + "ordinal": 8, "name": "default_permissioned_as", "type_info": "Jsonb" }, { - "ordinal": 10, + "ordinal": 9, "name": "labels", "type_info": "TextArray" } @@ -71,7 +66,6 @@ false, false, false, - false, true, true, true, @@ -79,5 +73,5 @@ true ] }, - "hash": "4f2c9e6206391e9b7dbcbd0bffeeef5fb70f6cdf445c114f8f2925ba39551be7" + "hash": "42600bdeb6b86ac306ab276cb49241508776f5f998821e04bc92df917176cea6" } diff --git a/backend/.sqlx/query-4ca364e493dd51d5f83489dc4674eeadcf092b37a20d03d52f2160ca21f79fb0.json b/backend/.sqlx/query-4ca364e493dd51d5f83489dc4674eeadcf092b37a20d03d52f2160ca21f79fb0.json new file mode 100644 index 0000000000..f486fdd689 --- /dev/null +++ b/backend/.sqlx/query-4ca364e493dd51d5f83489dc4674eeadcf092b37a20d03d52f2160ca21f79fb0.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO folder (workspace_id, name, display_name, owners, extra_perms, summary, edited_at, created_by, default_permissioned_as, labels)\n SELECT $2, name, display_name, owners, extra_perms, summary, edited_at, created_by, default_permissioned_as, labels\n FROM folder\n WHERE workspace_id = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Varchar" + ] + }, + "nullable": [] + }, + "hash": "4ca364e493dd51d5f83489dc4674eeadcf092b37a20d03d52f2160ca21f79fb0" +} diff --git a/backend/.sqlx/query-50c7797e3214841ba005618e170c7150c7292a4510ba5c751e40f7c5e2fc5841.json b/backend/.sqlx/query-50c7797e3214841ba005618e170c7150c7292a4510ba5c751e40f7c5e2fc5841.json deleted file mode 100644 index ef68a002fc..0000000000 --- a/backend/.sqlx/query-50c7797e3214841ba005618e170c7150c7292a4510ba5c751e40f7c5e2fc5841.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO folder (workspace_id, name, display_name, owners, extra_perms, view_only, summary, edited_at, created_by, default_permissioned_as, labels)\n SELECT $2, name, display_name, owners, extra_perms, view_only, summary, edited_at, created_by, default_permissioned_as, labels\n FROM folder\n WHERE workspace_id = $1", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - "Varchar" - ] - }, - "nullable": [] - }, - "hash": "50c7797e3214841ba005618e170c7150c7292a4510ba5c751e40f7c5e2fc5841" -} diff --git a/backend/.sqlx/query-580271c5fe178f5e31f3e211cd7fea97aec4d6d3ec65d3e7402811c7dddbbf64.json b/backend/.sqlx/query-580271c5fe178f5e31f3e211cd7fea97aec4d6d3ec65d3e7402811c7dddbbf64.json new file mode 100644 index 0000000000..e1f4609346 --- /dev/null +++ b/backend/.sqlx/query-580271c5fe178f5e31f3e211cd7fea97aec4d6d3ec65d3e7402811c7dddbbf64.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO flow\n (workspace_id, path, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, job_token_scopes)\n SELECT workspace_id, $1, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, job_token_scopes\n FROM flow\n WHERE path = $2 AND workspace_id = $3", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Varchar", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "580271c5fe178f5e31f3e211cd7fea97aec4d6d3ec65d3e7402811c7dddbbf64" +} diff --git a/backend/.sqlx/query-5b4214deb7677ae16df0bea7c6553461dee4bcc8d7180a9a517d5809c42e11d7.json b/backend/.sqlx/query-5b4214deb7677ae16df0bea7c6553461dee4bcc8d7180a9a517d5809c42e11d7.json new file mode 100644 index 0000000000..a5e2b45b75 --- /dev/null +++ b/backend/.sqlx/query-5b4214deb7677ae16df0bea7c6553461dee4bcc8d7180a9a517d5809c42e11d7.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO folder (name, workspace_id, display_name, owners, extra_perms, summary, edited_at, created_by, default_permissioned_as, labels) SELECT name, $1, display_name, owners, extra_perms, summary, edited_at, created_by, default_permissioned_as, labels FROM folder WHERE workspace_id = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Varchar", + "Text" + ] + }, + "nullable": [] + }, + "hash": "5b4214deb7677ae16df0bea7c6553461dee4bcc8d7180a9a517d5809c42e11d7" +} diff --git a/backend/.sqlx/query-5d7c49c74b6324215f89b0a3f1587374b4ff0fd03c4c48bf16d876df3978bdfa.json b/backend/.sqlx/query-5d7c49c74b6324215f89b0a3f1587374b4ff0fd03c4c48bf16d876df3978bdfa.json deleted file mode 100644 index c0fb7f6fe8..0000000000 --- a/backend/.sqlx/query-5d7c49c74b6324215f89b0a3f1587374b4ff0fd03c4c48bf16d876df3978bdfa.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "UPDATE script SET view_only = $1 WHERE hash = $2 AND workspace_id = $3", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "TextArray", - "Int8", - "Text" - ] - }, - "nullable": [] - }, - "hash": "5d7c49c74b6324215f89b0a3f1587374b4ff0fd03c4c48bf16d876df3978bdfa" -} diff --git a/backend/.sqlx/query-95a6b9f7c302ca86f10a9ee0b51b10ec320663d2038928c90a8199335c53d482.json b/backend/.sqlx/query-636dd6906a20b608eea34e04a81bddb79398f57a34d180d08aa00aaaaa1050c8.json similarity index 79% rename from backend/.sqlx/query-95a6b9f7c302ca86f10a9ee0b51b10ec320663d2038928c90a8199335c53d482.json rename to backend/.sqlx/query-636dd6906a20b608eea34e04a81bddb79398f57a34d180d08aa00aaaaa1050c8.json index 9c2de05dc8..9028b69027 100644 --- a/backend/.sqlx/query-95a6b9f7c302ca86f10a9ee0b51b10ec320663d2038928c90a8199335c53d482.json +++ b/backend/.sqlx/query-636dd6906a20b608eea34e04a81bddb79398f57a34d180d08aa00aaaaa1050c8.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT workspace_id, name, display_name, owners, extra_perms, view_only, summary, created_by, edited_at, default_permissioned_as, labels FROM folder WHERE workspace_id = $1 ORDER BY name asc LIMIT $2 OFFSET $3", + "query": "SELECT workspace_id, name, display_name, owners, extra_perms, summary, created_by, edited_at, default_permissioned_as, labels FROM folder WHERE workspace_id = $1 ORDER BY name asc LIMIT $2 OFFSET $3", "describe": { "columns": [ { @@ -30,31 +30,26 @@ }, { "ordinal": 5, - "name": "view_only", - "type_info": "TextArray" - }, - { - "ordinal": 6, "name": "summary", "type_info": "Text" }, { - "ordinal": 7, + "ordinal": 6, "name": "created_by", "type_info": "Varchar" }, { - "ordinal": 8, + "ordinal": 7, "name": "edited_at", "type_info": "Timestamptz" }, { - "ordinal": 9, + "ordinal": 8, "name": "default_permissioned_as", "type_info": "Jsonb" }, { - "ordinal": 10, + "ordinal": 9, "name": "labels", "type_info": "TextArray" } @@ -72,7 +67,6 @@ false, false, false, - false, true, true, true, @@ -80,5 +74,5 @@ true ] }, - "hash": "95a6b9f7c302ca86f10a9ee0b51b10ec320663d2038928c90a8199335c53d482" + "hash": "636dd6906a20b608eea34e04a81bddb79398f57a34d180d08aa00aaaaa1050c8" } diff --git a/backend/.sqlx/query-6bb977fdca71a6a98a651b986ad5650c53b43416ea5913d1755bc5214b8c715f.json b/backend/.sqlx/query-6bb977fdca71a6a98a651b986ad5650c53b43416ea5913d1755bc5214b8c715f.json new file mode 100644 index 0000000000..56f48766cf --- /dev/null +++ b/backend/.sqlx/query-6bb977fdca71a6a98a651b986ad5650c53b43416ea5913d1755bc5214b8c715f.json @@ -0,0 +1,26 @@ +{ + "db_name": "PostgreSQL", + "query": "WITH item AS (\n -- The newest version only: a script reusing a retired path starts with no grants,\n -- and the retired versions' must not run it.\n (SELECT extra_perms FROM script\n WHERE $5 = 'script' AND workspace_id = $1 AND path = $2\n ORDER BY created_at DESC LIMIT 1)\n UNION ALL SELECT extra_perms FROM flow\n WHERE $5 = 'flow' AND workspace_id = $1 AND path = $2\n UNION ALL SELECT extra_perms FROM resource\n WHERE $5 = 'resource' AND workspace_id = $1 AND path = $2\n )\n SELECT EXISTS (\n SELECT 1 FROM item WHERE acl_grants_run(item.extra_perms, $4)\n ) OR EXISTS (\n SELECT 1 FROM folder f\n WHERE f.workspace_id = $1 AND f.name = $3\n AND (f.owners::text[] && $4 OR acl_grants_run(f.extra_perms, $4))\n ) AS \"can_run!\"", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "can_run!", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Text", + "TextArray", + "Text" + ] + }, + "nullable": [ + null + ] + }, + "hash": "6bb977fdca71a6a98a651b986ad5650c53b43416ea5913d1755bc5214b8c715f" +} diff --git a/backend/.sqlx/query-03894b75ae362139b523ddaaff21e30392acb80022005e2bb74199b5fb4375e7.json b/backend/.sqlx/query-6e45704fddf3deb181520b295018c9c94d1f3a853529c04d786f0c1221b3fd47.json similarity index 67% rename from backend/.sqlx/query-03894b75ae362139b523ddaaff21e30392acb80022005e2bb74199b5fb4375e7.json rename to backend/.sqlx/query-6e45704fddf3deb181520b295018c9c94d1f3a853529c04d786f0c1221b3fd47.json index 031b2db67b..43c2aaf051 100644 --- a/backend/.sqlx/query-03894b75ae362139b523ddaaff21e30392acb80022005e2bb74199b5fb4375e7.json +++ b/backend/.sqlx/query-6e45704fddf3deb181520b295018c9c94d1f3a853529c04d786f0c1221b3fd47.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT resource.workspace_id, resource.path, resource.value, resource.description,\n resource.resource_type, resource.extra_perms, resource.view_only, resource.created_by, resource.edited_at,\n resource.labels,\n folder_labels(resource.workspace_id, resource.path) as \"inherited_labels?\",\n (now() > account.expires_at) as is_expired, account.refresh_token != '' as is_refreshed,\n account.refresh_error, account.scopes as \"scopes?\",\n variable.path IS NOT NULL as is_linked,\n variable.is_oauth as \"is_oauth?\",\n variable.account,\n ws_specific.path IS NOT NULL as ws_specific,\n null::bool as draft_only,\n null::bool as is_draft\n FROM resource\n LEFT JOIN variable ON variable.path = resource.path AND variable.workspace_id = $2\n LEFT JOIN account ON variable.account = account.id AND account.workspace_id = $2\n LEFT JOIN ws_specific ON ws_specific.path = resource.path AND ws_specific.workspace_id = $2 AND ws_specific.item_kind = 'resource'\n WHERE resource.path = $1 AND resource.workspace_id = $2", + "query": "SELECT resource.workspace_id, resource.path, resource.value, resource.description,\n resource.resource_type, resource.extra_perms, resource.created_by, resource.edited_at,\n resource.labels,\n folder_labels(resource.workspace_id, resource.path) as \"inherited_labels?\",\n (now() > account.expires_at) as is_expired, account.refresh_token != '' as is_refreshed,\n account.refresh_error, account.scopes as \"scopes?\",\n variable.path IS NOT NULL as is_linked,\n variable.is_oauth as \"is_oauth?\",\n variable.account,\n ws_specific.path IS NOT NULL as ws_specific,\n null::bool as draft_only,\n null::bool as is_draft\n FROM resource\n LEFT JOIN variable ON variable.path = resource.path AND variable.workspace_id = $2\n LEFT JOIN account ON variable.account = account.id AND account.workspace_id = $2\n LEFT JOIN ws_specific ON ws_specific.path = resource.path AND ws_specific.workspace_id = $2 AND ws_specific.item_kind = 'resource'\n WHERE resource.path = $1 AND resource.workspace_id = $2", "describe": { "columns": [ { @@ -35,76 +35,71 @@ }, { "ordinal": 6, - "name": "view_only", - "type_info": "TextArray" - }, - { - "ordinal": 7, "name": "created_by", "type_info": "Varchar" }, { - "ordinal": 8, + "ordinal": 7, "name": "edited_at", "type_info": "Timestamptz" }, { - "ordinal": 9, + "ordinal": 8, "name": "labels", "type_info": "TextArray" }, { - "ordinal": 10, + "ordinal": 9, "name": "inherited_labels?", "type_info": "TextArray" }, { - "ordinal": 11, + "ordinal": 10, "name": "is_expired", "type_info": "Bool" }, { - "ordinal": 12, + "ordinal": 11, "name": "is_refreshed", "type_info": "Bool" }, { - "ordinal": 13, + "ordinal": 12, "name": "refresh_error", "type_info": "Text" }, { - "ordinal": 14, + "ordinal": 13, "name": "scopes?", "type_info": "TextArray" }, { - "ordinal": 15, + "ordinal": 14, "name": "is_linked", "type_info": "Bool" }, { - "ordinal": 16, + "ordinal": 15, "name": "is_oauth?", "type_info": "Bool" }, { - "ordinal": 17, + "ordinal": 16, "name": "account", "type_info": "Int4" }, { - "ordinal": 18, + "ordinal": 17, "name": "ws_specific", "type_info": "Bool" }, { - "ordinal": 19, + "ordinal": 18, "name": "draft_only", "type_info": "Bool" }, { - "ordinal": 20, + "ordinal": 19, "name": "is_draft", "type_info": "Bool" } @@ -122,7 +117,6 @@ true, false, false, - false, true, true, true, @@ -139,5 +133,5 @@ null ] }, - "hash": "03894b75ae362139b523ddaaff21e30392acb80022005e2bb74199b5fb4375e7" + "hash": "6e45704fddf3deb181520b295018c9c94d1f3a853529c04d786f0c1221b3fd47" } diff --git a/backend/.sqlx/query-706f2227e34971d22a577b33f6aaa7f5755da9997419c4a9d07b30d4da318bea.json b/backend/.sqlx/query-706f2227e34971d22a577b33f6aaa7f5755da9997419c4a9d07b30d4da318bea.json new file mode 100644 index 0000000000..7c305d1e7a --- /dev/null +++ b/backend/.sqlx/query-706f2227e34971d22a577b33f6aaa7f5755da9997419c4a9d07b30d4da318bea.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO script (\n workspace_id, hash, path, parent_hashes, summary, description, content,\n created_by, created_at, archived, schema, deleted, is_template,\n extra_perms, lock, lock_error_logs, language, kind, tag,\n envs, concurrent_limit, concurrency_time_window_s, cache_ttl,\n dedicated_worker, ws_error_handler_muted, priority, timeout,\n delete_after_use, delete_after_secs, restart_unless_cancelled, concurrency_key,\n visible_to_runner_only, auto_kind, codebase, has_preprocessor,\n on_behalf_of, on_behalf_of_email, assets, modules, job_token_scopes\n )\n SELECT\n $1, hash, path, parent_hashes, summary, description, content,\n created_by, created_at, archived, schema, deleted, is_template,\n extra_perms, lock, lock_error_logs, language, kind, tag,\n envs, concurrent_limit, concurrency_time_window_s, cache_ttl,\n dedicated_worker, ws_error_handler_muted, priority, timeout,\n delete_after_use, delete_after_secs, restart_unless_cancelled, concurrency_key,\n visible_to_runner_only, auto_kind, codebase, has_preprocessor,\n -- Same three forms and the same prefix-first rule as permissioned_as_exists,\n -- superadmin fallback included: one acting outside their workspaces has no usr\n -- row but still authenticates.\n CASE WHEN on_behalf_of LIKE 'u/%' THEN\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM usr u WHERE u.workspace_id = $1::varchar\n AND u.username = substring(on_behalf_of from 3)\n UNION ALL\n SELECT 1 FROM password p WHERE p.super_admin\n AND (p.username = substring(on_behalf_of from 3)\n OR p.email = substring(on_behalf_of from 3))))\n WHEN on_behalf_of LIKE 'g/%' THEN\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM group_ g WHERE g.workspace_id = $1::varchar\n AND g.name = substring(on_behalf_of from 3)))\n ELSE\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM usr u WHERE u.workspace_id = $1::varchar\n AND u.username = on_behalf_of\n UNION ALL\n SELECT 1 FROM password p WHERE p.email = on_behalf_of\n AND p.super_admin))\n END, on_behalf_of_email, assets, modules, job_token_scopes\n FROM script\n WHERE workspace_id = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Varchar", + "Text" + ] + }, + "nullable": [] + }, + "hash": "706f2227e34971d22a577b33f6aaa7f5755da9997419c4a9d07b30d4da318bea" +} diff --git a/backend/.sqlx/query-251c6463cc54705b09ecab2a155628da162490e15743c4bb9a0e8c205bee1bfa.json b/backend/.sqlx/query-70bad6ac45db6d03c59aa375f915ec55d1c07998b1bd0268725d34f7f0b98103.json similarity index 61% rename from backend/.sqlx/query-251c6463cc54705b09ecab2a155628da162490e15743c4bb9a0e8c205bee1bfa.json rename to backend/.sqlx/query-70bad6ac45db6d03c59aa375f915ec55d1c07998b1bd0268725d34f7f0b98103.json index 69c1e3a88d..a3eb036d93 100644 --- a/backend/.sqlx/query-251c6463cc54705b09ecab2a155628da162490e15743c4bb9a0e8c205bee1bfa.json +++ b/backend/.sqlx/query-70bad6ac45db6d03c59aa375f915ec55d1c07998b1bd0268725d34f7f0b98103.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "UPDATE flow SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)), view_only = array_replace(view_only, 'u/' || $2, 'u/' || $1) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", + "query": "UPDATE flow SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", "describe": { "columns": [], "parameters": { @@ -12,5 +12,5 @@ }, "nullable": [] }, - "hash": "251c6463cc54705b09ecab2a155628da162490e15743c4bb9a0e8c205bee1bfa" + "hash": "70bad6ac45db6d03c59aa375f915ec55d1c07998b1bd0268725d34f7f0b98103" } diff --git a/backend/.sqlx/query-092fb3f2bc24d2d1692a3fc4864015176899bbd9c5223d65549a8997af565152.json b/backend/.sqlx/query-813b91a338f2fe46a7d27a155c435f33faa61710388f71f04da2d4569bc3dd71.json similarity index 59% rename from backend/.sqlx/query-092fb3f2bc24d2d1692a3fc4864015176899bbd9c5223d65549a8997af565152.json rename to backend/.sqlx/query-813b91a338f2fe46a7d27a155c435f33faa61710388f71f04da2d4569bc3dd71.json index b262ee76f5..025a2c8ff3 100644 --- a/backend/.sqlx/query-092fb3f2bc24d2d1692a3fc4864015176899bbd9c5223d65549a8997af565152.json +++ b/backend/.sqlx/query-813b91a338f2fe46a7d27a155c435f33faa61710388f71f04da2d4569bc3dd71.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "INSERT INTO folder (workspace_id, name, display_name, owners, extra_perms, view_only, summary, created_by, edited_at, default_permissioned_as, labels) VALUES ($1, $2, $3, $4, $5, $10, $6, $7, now(), $8, $9)", + "query": "INSERT INTO folder (workspace_id, name, display_name, owners, extra_perms, summary, created_by, edited_at, default_permissioned_as, labels) VALUES ($1, $2, $3, $4, $5, $6, $7, now(), $8, $9)", "describe": { "columns": [], "parameters": { @@ -13,11 +13,10 @@ "Text", "Varchar", "Jsonb", - "TextArray", "TextArray" ] }, "nullable": [] }, - "hash": "092fb3f2bc24d2d1692a3fc4864015176899bbd9c5223d65549a8997af565152" + "hash": "813b91a338f2fe46a7d27a155c435f33faa61710388f71f04da2d4569bc3dd71" } diff --git a/backend/.sqlx/query-2e897638b8b4f77d6a3e30a0f7b1fd7009ebe1082b19456d73686d076526affb.json b/backend/.sqlx/query-825b7e301307373ecfa6b59b4091e5fe53514913562ca93de44d9ad0a02a0fe8.json similarity index 79% rename from backend/.sqlx/query-2e897638b8b4f77d6a3e30a0f7b1fd7009ebe1082b19456d73686d076526affb.json rename to backend/.sqlx/query-825b7e301307373ecfa6b59b4091e5fe53514913562ca93de44d9ad0a02a0fe8.json index 452fc3f032..46ec0bde59 100644 --- a/backend/.sqlx/query-2e897638b8b4f77d6a3e30a0f7b1fd7009ebe1082b19456d73686d076526affb.json +++ b/backend/.sqlx/query-825b7e301307373ecfa6b59b4091e5fe53514913562ca93de44d9ad0a02a0fe8.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT workspace_id, path, value, description, resource_type, extra_perms, view_only, created_by, edited_at, labels FROM resource WHERE workspace_id = $1 AND resource_type <> ALL($2)", + "query": "SELECT workspace_id, path, value, description, resource_type, extra_perms, created_by, edited_at, labels FROM resource WHERE workspace_id = $1 AND resource_type <> ALL($2)", "describe": { "columns": [ { @@ -35,21 +35,16 @@ }, { "ordinal": 6, - "name": "view_only", - "type_info": "TextArray" - }, - { - "ordinal": 7, "name": "created_by", "type_info": "Varchar" }, { - "ordinal": 8, + "ordinal": 7, "name": "edited_at", "type_info": "Timestamptz" }, { - "ordinal": 9, + "ordinal": 8, "name": "labels", "type_info": "TextArray" } @@ -67,11 +62,10 @@ true, false, false, - false, true, true, true ] }, - "hash": "2e897638b8b4f77d6a3e30a0f7b1fd7009ebe1082b19456d73686d076526affb" + "hash": "825b7e301307373ecfa6b59b4091e5fe53514913562ca93de44d9ad0a02a0fe8" } diff --git a/backend/.sqlx/query-91b82ddd4964a23bb69dcdfc5ff7f90a04016cd7fb9d249b7165f0f31c28b665.json b/backend/.sqlx/query-91b82ddd4964a23bb69dcdfc5ff7f90a04016cd7fb9d249b7165f0f31c28b665.json deleted file mode 100644 index c11ac60e23..0000000000 --- a/backend/.sqlx/query-91b82ddd4964a23bb69dcdfc5ff7f90a04016cd7fb9d249b7165f0f31c28b665.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "WITH inserted AS (\n INSERT INTO flow\n (workspace_id, path, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, lock_error_logs, job_token_scopes)\n SELECT workspace_id, REGEXP_REPLACE(path, 'u/' || $2 || '/(.*)', $1 || '/\\1'), summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, lock_error_logs, job_token_scopes\n FROM flow\n WHERE path LIKE ('u/' || $2 || '/%') AND workspace_id = $3\n RETURNING 1\n ) SELECT COUNT(*) FROM inserted", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "count", - "type_info": "Int8" - } - ], - "parameters": { - "Left": [ - "Text", - "Text", - "Text" - ] - }, - "nullable": [ - null - ] - }, - "hash": "91b82ddd4964a23bb69dcdfc5ff7f90a04016cd7fb9d249b7165f0f31c28b665" -} diff --git a/backend/.sqlx/query-9f4611d4968b551a9e7c33bcf383103c9ac8924bdf959602fb224bf32677df4a.json b/backend/.sqlx/query-9f4611d4968b551a9e7c33bcf383103c9ac8924bdf959602fb224bf32677df4a.json deleted file mode 100644 index 0312f2c990..0000000000 --- a/backend/.sqlx/query-9f4611d4968b551a9e7c33bcf383103c9ac8924bdf959602fb224bf32677df4a.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "WITH RECURSIVE chain(origin, id, parent_job, depth) AS (\n SELECT id, id, parent_job, 0 FROM v2_job WHERE id = ANY($1) AND workspace_id = $2\n UNION ALL\n SELECT c.origin, j.id, j.parent_job, c.depth + 1 FROM v2_job j\n JOIN chain c ON j.id = c.parent_job AND j.workspace_id = $2\n WHERE c.depth < 100\n )\n SELECT c.origin AS \"id!\", c.depth AS \"depth!\", j.created_by AS \"created_by!\",\n CASE WHEN a.agent THEN regexp_replace(j.runnable_path, '\\.chat$', '')\n ELSE j.runnable_path END AS runnable_path,\n CASE\n WHEN a.agent THEN 'agent'\n WHEN j.kind IN ('script', 'script_hub', 'unassigned_script', 'preview')\n THEN 'script'\n WHEN j.kind IN ('flow', 'unassigned_flow', 'flowpreview') THEN 'flow'\n WHEN j.kind IN ('singlestepflow', 'unassigned_singlestepflow') THEN\n CASE WHEN COALESCE(\n (SELECT m->'value'->>'type'\n FROM jsonb_array_elements(j.raw_flow->'modules') m\n WHERE m->>'id' IN ('a', 'main')\n LIMIT 1),\n 'script'\n ) = 'flow' THEN 'flow' ELSE 'script' END\n END AS acl_kind\n FROM chain c JOIN v2_job j ON j.id = c.id AND j.workspace_id = $2,\n LATERAL (SELECT j.kind = 'flowpreview'\n AND j.raw_flow->'modules'->1 IS NULL\n AND j.raw_flow->'modules'->0->>'id' = '__wm_agent_root' AS agent) a\n ORDER BY c.origin, c.depth", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id!", - "type_info": "Uuid" - }, - { - "ordinal": 1, - "name": "depth!", - "type_info": "Int4" - }, - { - "ordinal": 2, - "name": "created_by!", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "runnable_path", - "type_info": "Varchar" - }, - { - "ordinal": 4, - "name": "acl_kind", - "type_info": "Text" - } - ], - "parameters": { - "Left": [ - "UuidArray", - "Text" - ] - }, - "nullable": [ - null, - null, - false, - null, - null - ] - }, - "hash": "9f4611d4968b551a9e7c33bcf383103c9ac8924bdf959602fb224bf32677df4a" -} diff --git a/backend/.sqlx/query-a875cca3478a982c08e9263876a7399e3000b671a2133f9c9849a899360f1bb1.json b/backend/.sqlx/query-a875cca3478a982c08e9263876a7399e3000b671a2133f9c9849a899360f1bb1.json deleted file mode 100644 index 881601bbc6..0000000000 --- a/backend/.sqlx/query-a875cca3478a982c08e9263876a7399e3000b671a2133f9c9849a899360f1bb1.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO flow\n (workspace_id, path, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, job_token_scopes)\n SELECT workspace_id, REGEXP_REPLACE(path,'u/' || $2 || '/(.*)','u/' || $1 || '/\\1'), summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, job_token_scopes\n FROM flow\n WHERE path LIKE ('u/' || $2 || '/%') AND workspace_id = $3", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Text" - ] - }, - "nullable": [] - }, - "hash": "a875cca3478a982c08e9263876a7399e3000b671a2133f9c9849a899360f1bb1" -} diff --git a/backend/.sqlx/query-b1f55dd2395500bfde5ca07967c7be041c6f434982519a7d0634cb4f8358001f.json b/backend/.sqlx/query-b1f55dd2395500bfde5ca07967c7be041c6f434982519a7d0634cb4f8358001f.json new file mode 100644 index 0000000000..810cacc2af --- /dev/null +++ b/backend/.sqlx/query-b1f55dd2395500bfde5ca07967c7be041c6f434982519a7d0634cb4f8358001f.json @@ -0,0 +1,35 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT name, (EXISTS (SELECT 1 FROM (SELECT key, value FROM jsonb_each_text(extra_perms) WHERE key = ANY($1)) t WHERE value IN ('true', 'write'))) as write, $1 && owners::text[] as owner FROM folder\n WHERE extra_perms ?| $1 AND workspace_id = $2", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "name", + "type_info": "Varchar" + }, + { + "ordinal": 1, + "name": "write", + "type_info": "Bool" + }, + { + "ordinal": 2, + "name": "owner", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "TextArray", + "Text" + ] + }, + "nullable": [ + false, + null, + null + ] + }, + "hash": "b1f55dd2395500bfde5ca07967c7be041c6f434982519a7d0634cb4f8358001f" +} diff --git a/backend/.sqlx/query-b40c9e2d637cf0f2f49fd4c720b64eb6af24e8d8aa99b846f21f2ed49c320bdc.json b/backend/.sqlx/query-b40c9e2d637cf0f2f49fd4c720b64eb6af24e8d8aa99b846f21f2ed49c320bdc.json new file mode 100644 index 0000000000..db729b97b1 --- /dev/null +++ b/backend/.sqlx/query-b40c9e2d637cf0f2f49fd4c720b64eb6af24e8d8aa99b846f21f2ed49c320bdc.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO flow\n (workspace_id, path, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, job_token_scopes)\n SELECT workspace_id, REGEXP_REPLACE(path,'u/' || $2 || '/(.*)','u/' || $1 || '/\\1'), summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, job_token_scopes\n FROM flow\n WHERE path LIKE ('u/' || $2 || '/%') AND workspace_id = $3", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "b40c9e2d637cf0f2f49fd4c720b64eb6af24e8d8aa99b846f21f2ed49c320bdc" +} diff --git a/backend/.sqlx/query-bf763c3ae4951537033d18ce48d3eb83d5c19e32aef199bf161e8ba8d1adf176.json b/backend/.sqlx/query-bf763c3ae4951537033d18ce48d3eb83d5c19e32aef199bf161e8ba8d1adf176.json new file mode 100644 index 0000000000..d6b261b56c --- /dev/null +++ b/backend/.sqlx/query-bf763c3ae4951537033d18ce48d3eb83d5c19e32aef199bf161e8ba8d1adf176.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO resource (workspace_id, path, value, description, resource_type, extra_perms, edited_at, created_by)\n SELECT $2, path,\n CASE WHEN $3::text IS NOT NULL AND resource_type = 'ai_agent'\n AND jsonb_typeof(value) = 'object' AND value ? 'on_behalf_of'\n THEN jsonb_set(value, '{on_behalf_of}', to_jsonb($3::text))\n ELSE value END,\n description, resource_type, extra_perms, edited_at, created_by\n FROM resource\n WHERE workspace_id = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Varchar", + "Text" + ] + }, + "nullable": [] + }, + "hash": "bf763c3ae4951537033d18ce48d3eb83d5c19e32aef199bf161e8ba8d1adf176" +} diff --git a/backend/.sqlx/query-c39e37756387c774e30177c2997326443d7b78639f8316c1b8e2cd27965af731.json b/backend/.sqlx/query-c39e37756387c774e30177c2997326443d7b78639f8316c1b8e2cd27965af731.json deleted file mode 100644 index 93d0cad076..0000000000 --- a/backend/.sqlx/query-c39e37756387c774e30177c2997326443d7b78639f8316c1b8e2cd27965af731.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO flow\n (workspace_id, path, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, lock_error_logs, job_token_scopes)\n SELECT $1, path, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, lock_error_logs, job_token_scopes\n FROM flow WHERE workspace_id = $2", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Text" - ] - }, - "nullable": [] - }, - "hash": "c39e37756387c774e30177c2997326443d7b78639f8316c1b8e2cd27965af731" -} diff --git a/backend/.sqlx/query-c4eaa6e3b1d30a72ef1b54b2b7f28d84f1ca3c91de86d520dce06ac12d557bd5.json b/backend/.sqlx/query-c4eaa6e3b1d30a72ef1b54b2b7f28d84f1ca3c91de86d520dce06ac12d557bd5.json new file mode 100644 index 0000000000..151296d652 --- /dev/null +++ b/backend/.sqlx/query-c4eaa6e3b1d30a72ef1b54b2b7f28d84f1ca3c91de86d520dce06ac12d557bd5.json @@ -0,0 +1,24 @@ +{ + "db_name": "PostgreSQL", + "query": "WITH inserted AS (\n INSERT INTO flow\n (workspace_id, path, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, lock_error_logs, job_token_scopes)\n SELECT workspace_id, REGEXP_REPLACE(path, 'u/' || $2 || '/(.*)', $1 || '/\\1'), summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, lock_error_logs, job_token_scopes\n FROM flow\n WHERE path LIKE ('u/' || $2 || '/%') AND workspace_id = $3\n RETURNING 1\n ) SELECT COUNT(*) FROM inserted", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "count", + "type_info": "Int8" + } + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Text" + ] + }, + "nullable": [ + null + ] + }, + "hash": "c4eaa6e3b1d30a72ef1b54b2b7f28d84f1ca3c91de86d520dce06ac12d557bd5" +} diff --git a/backend/.sqlx/query-c7841d246e0a53979507c278d606258c1635506d4d0edd9d9c3d40fc38cabf88.json b/backend/.sqlx/query-c7841d246e0a53979507c278d606258c1635506d4d0edd9d9c3d40fc38cabf88.json deleted file mode 100644 index b27ea94182..0000000000 --- a/backend/.sqlx/query-c7841d246e0a53979507c278d606258c1635506d4d0edd9d9c3d40fc38cabf88.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO script (\n workspace_id, hash, path, parent_hashes, summary, description, content,\n created_by, created_at, archived, schema, deleted, is_template,\n extra_perms, view_only, lock, lock_error_logs, language, kind, tag,\n envs, concurrent_limit, concurrency_time_window_s, cache_ttl,\n dedicated_worker, ws_error_handler_muted, priority, timeout,\n delete_after_use, delete_after_secs, restart_unless_cancelled, concurrency_key,\n visible_to_runner_only, auto_kind, codebase, has_preprocessor,\n on_behalf_of, on_behalf_of_email, assets, modules, job_token_scopes\n )\n SELECT\n $1, hash, path, parent_hashes, summary, description, content,\n created_by, created_at, archived, schema, deleted, is_template,\n extra_perms, view_only, lock, lock_error_logs, language, kind, tag,\n envs, concurrent_limit, concurrency_time_window_s, cache_ttl,\n dedicated_worker, ws_error_handler_muted, priority, timeout,\n delete_after_use, delete_after_secs, restart_unless_cancelled, concurrency_key,\n visible_to_runner_only, auto_kind, codebase, has_preprocessor,\n -- Same three forms and the same prefix-first rule as permissioned_as_exists,\n -- superadmin fallback included: one acting outside their workspaces has no usr\n -- row but still authenticates.\n CASE WHEN on_behalf_of LIKE 'u/%' THEN\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM usr u WHERE u.workspace_id = $1::varchar\n AND u.username = substring(on_behalf_of from 3)\n UNION ALL\n SELECT 1 FROM password p WHERE p.super_admin\n AND (p.username = substring(on_behalf_of from 3)\n OR p.email = substring(on_behalf_of from 3))))\n WHEN on_behalf_of LIKE 'g/%' THEN\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM group_ g WHERE g.workspace_id = $1::varchar\n AND g.name = substring(on_behalf_of from 3)))\n ELSE\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM usr u WHERE u.workspace_id = $1::varchar\n AND u.username = on_behalf_of\n UNION ALL\n SELECT 1 FROM password p WHERE p.email = on_behalf_of\n AND p.super_admin))\n END, on_behalf_of_email, assets, modules, job_token_scopes\n FROM script\n WHERE workspace_id = $2", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Text" - ] - }, - "nullable": [] - }, - "hash": "c7841d246e0a53979507c278d606258c1635506d4d0edd9d9c3d40fc38cabf88" -} diff --git a/backend/.sqlx/query-924b4941829f69ff96c55f0a432298de7cf3aa1690c931a5b569fce3203a86c3.json b/backend/.sqlx/query-cc9e2460b8fded240eff64cf3cf348f9bd36a86233f3b0a3e73f51698ed353dd.json similarity index 61% rename from backend/.sqlx/query-924b4941829f69ff96c55f0a432298de7cf3aa1690c931a5b569fce3203a86c3.json rename to backend/.sqlx/query-cc9e2460b8fded240eff64cf3cf348f9bd36a86233f3b0a3e73f51698ed353dd.json index f3167a5e3f..af93f11961 100644 --- a/backend/.sqlx/query-924b4941829f69ff96c55f0a432298de7cf3aa1690c931a5b569fce3203a86c3.json +++ b/backend/.sqlx/query-cc9e2460b8fded240eff64cf3cf348f9bd36a86233f3b0a3e73f51698ed353dd.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "UPDATE folder SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)), view_only = array_replace(view_only, 'u/' || $2, 'u/' || $1) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", + "query": "UPDATE folder SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", "describe": { "columns": [], "parameters": { @@ -12,5 +12,5 @@ }, "nullable": [] }, - "hash": "924b4941829f69ff96c55f0a432298de7cf3aa1690c931a5b569fce3203a86c3" + "hash": "cc9e2460b8fded240eff64cf3cf348f9bd36a86233f3b0a3e73f51698ed353dd" } diff --git a/backend/.sqlx/query-d64af095618cdfd5e8a5a2ad3b714ad64feb4129a0117d2789346ebd370d33a2.json b/backend/.sqlx/query-d64af095618cdfd5e8a5a2ad3b714ad64feb4129a0117d2789346ebd370d33a2.json new file mode 100644 index 0000000000..c3a1a122cc --- /dev/null +++ b/backend/.sqlx/query-d64af095618cdfd5e8a5a2ad3b714ad64feb4129a0117d2789346ebd370d33a2.json @@ -0,0 +1,41 @@ +{ + "db_name": "PostgreSQL", + "query": "WITH RECURSIVE chain(origin, id, parent_job, depth) AS (\n SELECT id, id, parent_job, 0 FROM v2_job WHERE id = ANY($1) AND workspace_id = $2\n UNION ALL\n SELECT c.origin, j.id, j.parent_job, c.depth + 1 FROM v2_job j\n JOIN chain c ON j.id = c.parent_job AND j.workspace_id = $2\n WHERE c.depth < 100\n )\n SELECT c.origin AS \"id!\", j.created_by AS \"created_by!\",\n CASE WHEN a.agent THEN regexp_replace(j.runnable_path, '\\.chat$', '')\n ELSE j.runnable_path END AS runnable_path,\n CASE\n WHEN a.agent THEN 'agent'\n WHEN j.kind IN ('script', 'script_hub', 'unassigned_script', 'preview')\n THEN 'script'\n WHEN j.kind IN ('flow', 'unassigned_flow', 'flowpreview') THEN 'flow'\n WHEN j.kind IN ('singlestepflow', 'unassigned_singlestepflow') THEN\n CASE WHEN COALESCE(\n (SELECT m->'value'->>'type'\n FROM jsonb_array_elements(j.raw_flow->'modules') m\n WHERE m->>'id' IN ('a', 'main')\n LIMIT 1),\n 'script'\n ) = 'flow' THEN 'flow' ELSE 'script' END\n END AS acl_kind\n FROM chain c JOIN v2_job j ON j.id = c.id AND j.workspace_id = $2,\n LATERAL (SELECT j.kind = 'flowpreview'\n AND j.raw_flow->'modules'->1 IS NULL\n AND j.raw_flow->'modules'->0->>'id' = '__wm_agent_root' AS agent) a\n ORDER BY c.origin, c.depth", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id!", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "created_by!", + "type_info": "Varchar" + }, + { + "ordinal": 2, + "name": "runnable_path", + "type_info": "Varchar" + }, + { + "ordinal": 3, + "name": "acl_kind", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "UuidArray", + "Text" + ] + }, + "nullable": [ + null, + false, + null, + null + ] + }, + "hash": "d64af095618cdfd5e8a5a2ad3b714ad64feb4129a0117d2789346ebd370d33a2" +} diff --git a/backend/.sqlx/query-df1fe2e7ef004b8de0e626f40fd737b3b4b662a89148cf6ac70eb3563ad7f0c5.json b/backend/.sqlx/query-df1fe2e7ef004b8de0e626f40fd737b3b4b662a89148cf6ac70eb3563ad7f0c5.json new file mode 100644 index 0000000000..7f160dc856 --- /dev/null +++ b/backend/.sqlx/query-df1fe2e7ef004b8de0e626f40fd737b3b4b662a89148cf6ac70eb3563ad7f0c5.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO flow (\n workspace_id, path, summary, description, value, edited_by, edited_at,\n archived, schema, extra_perms, dependency_job, tag,\n ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only,\n concurrency_key, versions, on_behalf_of, on_behalf_of_email, lock_error_logs,\n job_token_scopes\n )\n SELECT $2, path, summary, description, value, edited_by, edited_at,\n archived, schema, extra_perms, NULL, tag,\n ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only,\n concurrency_key, ARRAY[]::bigint[],\n -- Same predicate as clone_scripts.\n CASE WHEN on_behalf_of LIKE 'u/%' THEN\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM usr u WHERE u.workspace_id = $2::varchar\n AND u.username = substring(on_behalf_of from 3)\n UNION ALL\n SELECT 1 FROM password p WHERE p.super_admin\n AND (p.username = substring(on_behalf_of from 3)\n OR p.email = substring(on_behalf_of from 3))))\n WHEN on_behalf_of LIKE 'g/%' THEN\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM group_ g WHERE g.workspace_id = $2::varchar\n AND g.name = substring(on_behalf_of from 3)))\n ELSE\n (SELECT on_behalf_of WHERE EXISTS (\n SELECT 1 FROM usr u WHERE u.workspace_id = $2::varchar\n AND u.username = on_behalf_of\n UNION ALL\n SELECT 1 FROM password p WHERE p.email = on_behalf_of\n AND p.super_admin))\n END, on_behalf_of_email, lock_error_logs, job_token_scopes\n FROM flow\n WHERE workspace_id = $1", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Varchar" + ] + }, + "nullable": [] + }, + "hash": "df1fe2e7ef004b8de0e626f40fd737b3b4b662a89148cf6ac70eb3563ad7f0c5" +} diff --git a/backend/.sqlx/query-a6deb6191f84b084cb523c7385a3977c15deffa9e484945e53d8e0aa46f1fbc1.json b/backend/.sqlx/query-e38dd0f093636efa2ec1cda4618fc104f7b8ea88130692ce9c1390bda289627a.json similarity index 61% rename from backend/.sqlx/query-a6deb6191f84b084cb523c7385a3977c15deffa9e484945e53d8e0aa46f1fbc1.json rename to backend/.sqlx/query-e38dd0f093636efa2ec1cda4618fc104f7b8ea88130692ce9c1390bda289627a.json index 52159b1744..63f8295ef6 100644 --- a/backend/.sqlx/query-a6deb6191f84b084cb523c7385a3977c15deffa9e484945e53d8e0aa46f1fbc1.json +++ b/backend/.sqlx/query-e38dd0f093636efa2ec1cda4618fc104f7b8ea88130692ce9c1390bda289627a.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "UPDATE script SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)), view_only = array_replace(view_only, 'u/' || $2, 'u/' || $1) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", + "query": "UPDATE script SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", "describe": { "columns": [], "parameters": { @@ -12,5 +12,5 @@ }, "nullable": [] }, - "hash": "a6deb6191f84b084cb523c7385a3977c15deffa9e484945e53d8e0aa46f1fbc1" + "hash": "e38dd0f093636efa2ec1cda4618fc104f7b8ea88130692ce9c1390bda289627a" } diff --git a/backend/.sqlx/query-e6818d4b9ea9991b252f5771c3fe2c8c7043e89e5fae70613c8230d94a183f6c.json b/backend/.sqlx/query-e6818d4b9ea9991b252f5771c3fe2c8c7043e89e5fae70613c8230d94a183f6c.json deleted file mode 100644 index 982164eba8..0000000000 --- a/backend/.sqlx/query-e6818d4b9ea9991b252f5771c3fe2c8c7043e89e5fae70613c8230d94a183f6c.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO flow\n (workspace_id, path, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, job_token_scopes)\n SELECT workspace_id, $1, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, job_token_scopes\n FROM flow\n WHERE path = $2 AND workspace_id = $3", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Text", - "Text" - ] - }, - "nullable": [] - }, - "hash": "e6818d4b9ea9991b252f5771c3fe2c8c7043e89e5fae70613c8230d94a183f6c" -} diff --git a/backend/.sqlx/query-e81eaa501b4af1269a4929ec660d10fc10d9ec4dc2359f43d79fe255d101cad8.json b/backend/.sqlx/query-e81eaa501b4af1269a4929ec660d10fc10d9ec4dc2359f43d79fe255d101cad8.json new file mode 100644 index 0000000000..909565b8c6 --- /dev/null +++ b/backend/.sqlx/query-e81eaa501b4af1269a4929ec660d10fc10d9ec4dc2359f43d79fe255d101cad8.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO flow\n (workspace_id, path, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, lock_error_logs, job_token_scopes)\n SELECT $1, path, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, lock_error_logs, job_token_scopes\n FROM flow WHERE workspace_id = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Varchar", + "Text" + ] + }, + "nullable": [] + }, + "hash": "e81eaa501b4af1269a4929ec660d10fc10d9ec4dc2359f43d79fe255d101cad8" +} diff --git a/backend/.sqlx/query-f0a7de33927a3c1ec11387870f5e17d56a1c7c403a2dcbe4335ace15798b2e86.json b/backend/.sqlx/query-f0a7de33927a3c1ec11387870f5e17d56a1c7c403a2dcbe4335ace15798b2e86.json deleted file mode 100644 index 4c2b52f20a..0000000000 --- a/backend/.sqlx/query-f0a7de33927a3c1ec11387870f5e17d56a1c7c403a2dcbe4335ace15798b2e86.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO folder (name, workspace_id, display_name, owners, extra_perms, view_only, summary, edited_at, created_by, default_permissioned_as, labels) SELECT name, $1, display_name, owners, extra_perms, view_only, summary, edited_at, created_by, default_permissioned_as, labels FROM folder WHERE workspace_id = $2", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Text" - ] - }, - "nullable": [] - }, - "hash": "f0a7de33927a3c1ec11387870f5e17d56a1c7c403a2dcbe4335ace15798b2e86" -} diff --git a/backend/migrations/20261113143004_acl_read_level.down.sql b/backend/migrations/20261113143004_acl_read_level.down.sql new file mode 100644 index 0000000000..a5da469c1a --- /dev/null +++ b/backend/migrations/20261113143004_acl_read_level.down.sql @@ -0,0 +1,40 @@ +DROP FUNCTION acl_grants_run(JSONB, TEXT[]); + +-- Back to booleans, so the casts below hold: a view-only grant becomes a read grant, which runs. +DO $$ +DECLARE t TEXT; +BEGIN + FOREACH t IN ARRAY ARRAY['script', 'flow', 'resource', 'folder'] LOOP + EXECUTE format($p$UPDATE %1$I SET extra_perms = ( + SELECT jsonb_object_agg(key, value IN ('true', 'write')) + FROM jsonb_each_text(extra_perms)) + WHERE EXISTS (SELECT 1 FROM jsonb_each(extra_perms) e + WHERE jsonb_typeof(e.value) = 'string')$p$, t); + END LOOP; + FOREACH t IN ARRAY ARRAY['script', 'flow', 'resource'] LOOP + EXECUTE format($p$ALTER POLICY see_extra_perms_user_insert ON %1$I WITH CHECK ( + ((extra_perms ->> (SELECT concat('u/', current_setting('session.user')))))::boolean)$p$, t); + EXECUTE format($p$ALTER POLICY see_extra_perms_user_update ON %1$I USING ( + ((extra_perms ->> (SELECT concat('u/', current_setting('session.user')))))::boolean)$p$, t); + EXECUTE format($p$ALTER POLICY see_extra_perms_user_delete ON %1$I USING ( + ((extra_perms ->> (SELECT concat('u/', current_setting('session.user')))))::boolean)$p$, t); + EXECUTE format($p$ALTER POLICY see_extra_perms_groups_insert ON %1$I WITH CHECK ( + EXISTS (SELECT 1 FROM jsonb_each_text(%1$I.extra_perms) e + WHERE split_part(e.key, '/', 1) = 'g' + AND e.key = ANY ((SELECT regexp_split_to_array( + current_setting('session.pgroups'), ','))::text[]) + AND e.value::boolean))$p$, t); + EXECUTE format($p$ALTER POLICY see_extra_perms_groups_update ON %1$I USING ( + EXISTS (SELECT 1 FROM jsonb_each_text(%1$I.extra_perms) e + WHERE split_part(e.key, '/', 1) = 'g' + AND e.key = ANY ((SELECT regexp_split_to_array( + current_setting('session.pgroups'), ','))::text[]) + AND e.value::boolean))$p$, t); + EXECUTE format($p$ALTER POLICY see_extra_perms_groups_delete ON %1$I USING ( + EXISTS (SELECT 1 FROM jsonb_each_text(%1$I.extra_perms) e + WHERE split_part(e.key, '/', 1) = 'g' + AND e.key = ANY ((SELECT regexp_split_to_array( + current_setting('session.pgroups'), ','))::text[]) + AND e.value::boolean))$p$, t); + END LOOP; +END $$; diff --git a/backend/migrations/20261113143004_acl_read_level.up.sql b/backend/migrations/20261113143004_acl_read_level.up.sql new file mode 100644 index 0000000000..d5e9d6765a --- /dev/null +++ b/backend/migrations/20261113143004_acl_read_level.up.sql @@ -0,0 +1,45 @@ +-- A grant in `extra_perms` is `true` (write), `false` (the level below write: run where the +-- item runs, read elsewhere) or one of "read", "run", "write". These policies read it without +-- the boolean cast they had, which a string value would make fail for every writer of the row. +DO $$ +DECLARE t TEXT; +BEGIN + FOREACH t IN ARRAY ARRAY['script', 'flow', 'resource'] LOOP + EXECUTE format($p$ALTER POLICY see_extra_perms_user_insert ON %1$I WITH CHECK ( + (extra_perms ->> (SELECT concat('u/', current_setting('session.user')))) + IN ('true', 'write'))$p$, t); + EXECUTE format($p$ALTER POLICY see_extra_perms_user_update ON %1$I USING ( + (extra_perms ->> (SELECT concat('u/', current_setting('session.user')))) + IN ('true', 'write'))$p$, t); + EXECUTE format($p$ALTER POLICY see_extra_perms_user_delete ON %1$I USING ( + (extra_perms ->> (SELECT concat('u/', current_setting('session.user')))) + IN ('true', 'write'))$p$, t); + EXECUTE format($p$ALTER POLICY see_extra_perms_groups_insert ON %1$I WITH CHECK ( + EXISTS (SELECT 1 FROM jsonb_each_text(%1$I.extra_perms) e + WHERE split_part(e.key, '/', 1) = 'g' + AND e.key = ANY ((SELECT regexp_split_to_array( + current_setting('session.pgroups'), ','))::text[]) + AND e.value IN ('true', 'write')))$p$, t); + EXECUTE format($p$ALTER POLICY see_extra_perms_groups_update ON %1$I USING ( + EXISTS (SELECT 1 FROM jsonb_each_text(%1$I.extra_perms) e + WHERE split_part(e.key, '/', 1) = 'g' + AND e.key = ANY ((SELECT regexp_split_to_array( + current_setting('session.pgroups'), ','))::text[]) + AND e.value IN ('true', 'write')))$p$, t); + EXECUTE format($p$ALTER POLICY see_extra_perms_groups_delete ON %1$I USING ( + EXISTS (SELECT 1 FROM jsonb_each_text(%1$I.extra_perms) e + WHERE split_part(e.key, '/', 1) = 'g' + AND e.key = ANY ((SELECT regexp_split_to_array( + current_setting('session.pgroups'), ','))::text[]) + AND e.value IN ('true', 'write')))$p$, t); + END LOOP; +END $$; + +-- Whether any of `principals` holds a grant in `extra_perms` of a runnable that includes running. +CREATE FUNCTION acl_grants_run(extra_perms JSONB, principals TEXT[]) +RETURNS BOOLEAN LANGUAGE sql IMMUTABLE AS $$ + SELECT EXISTS ( + SELECT 1 FROM jsonb_each_text(extra_perms) e + WHERE e.key = ANY(principals) AND e.value <> 'read' + ) +$$; diff --git a/backend/migrations/20261113143004_acl_view_only.down.sql b/backend/migrations/20261113143004_acl_view_only.down.sql deleted file mode 100644 index 4b4c7e4b93..0000000000 --- a/backend/migrations/20261113143004_acl_view_only.down.sql +++ /dev/null @@ -1,5 +0,0 @@ -DROP FUNCTION acl_grants_run(JSONB, TEXT[], TEXT[]); -ALTER TABLE script DROP COLUMN view_only; -ALTER TABLE flow DROP COLUMN view_only; -ALTER TABLE resource DROP COLUMN view_only; -ALTER TABLE folder DROP COLUMN view_only; diff --git a/backend/migrations/20261113143004_acl_view_only.up.sql b/backend/migrations/20261113143004_acl_view_only.up.sql deleted file mode 100644 index 1751a958d7..0000000000 --- a/backend/migrations/20261113143004_acl_view_only.up.sql +++ /dev/null @@ -1,15 +0,0 @@ --- Principals of `extra_perms` whose read grant does not include running. Empty for every --- existing row, so every existing read grant keeps running. -ALTER TABLE script ADD COLUMN view_only TEXT[] NOT NULL DEFAULT '{}'; -ALTER TABLE flow ADD COLUMN view_only TEXT[] NOT NULL DEFAULT '{}'; -ALTER TABLE resource ADD COLUMN view_only TEXT[] NOT NULL DEFAULT '{}'; -ALTER TABLE folder ADD COLUMN view_only TEXT[] NOT NULL DEFAULT '{}'; - --- Whether any of `principals` holds a grant in `extra_perms` that includes running. -CREATE FUNCTION acl_grants_run(extra_perms JSONB, view_only TEXT[], principals TEXT[]) -RETURNS BOOLEAN LANGUAGE sql IMMUTABLE AS $$ - SELECT EXISTS ( - SELECT 1 FROM jsonb_each_text(extra_perms) e - WHERE e.key = ANY(principals) AND (e.value::boolean OR NOT e.key = ANY(view_only)) - ) -$$; diff --git a/backend/windmill-api-flows/src/flows.rs b/backend/windmill-api-flows/src/flows.rs index 3caf24e68e..063bc8a4f3 100644 --- a/backend/windmill-api-flows/src/flows.rs +++ b/backend/windmill-api-flows/src/flows.rs @@ -169,7 +169,6 @@ async fn list_flows( "fv.created_at as edited_at", "archived", "extra_perms", - "o.view_only", "favorite.path IS NOT NULL as starred", "ws_error_handler_muted", "o.labels", @@ -313,7 +312,6 @@ async fn list_flows( edited_at: Some(row.created_at), archived: false, extra_perms: serde_json::Value::Object(serde_json::Map::new()), - view_only: vec![], starred: false, draft_only: Some(true), ws_error_handler_muted: None, @@ -1116,7 +1114,7 @@ async fn get_flow_version( let mut tx = user_db.begin(&authed).await?; let flow = sqlx::query_as::<_, Flow>( - "SELECT flow.workspace_id, flow.path, flow.summary, flow.description, flow.archived, flow.extra_perms, flow.view_only, flow.dedicated_worker, flow.tag, flow.ws_error_handler_muted, flow.timeout, flow.visible_to_runner_only, flow.on_behalf_of, flow.labels, flow.job_token_scopes, flow_version.schema, flow_version.value, flow_version.created_at as edited_at, flow_version.created_by as edited_by + "SELECT flow.workspace_id, flow.path, flow.summary, flow.description, flow.archived, flow.extra_perms, flow.dedicated_worker, flow.tag, flow.ws_error_handler_muted, flow.timeout, flow.visible_to_runner_only, flow.on_behalf_of, flow.labels, flow.job_token_scopes, flow_version.schema, flow_version.value, flow_version.created_at as edited_at, flow_version.created_by as edited_by FROM flow LEFT JOIN flow_version ON flow_version.path = flow.path AND flow_version.workspace_id = flow.workspace_id WHERE flow.path = $1 AND flow.workspace_id = $2 AND flow_version.id = $3", @@ -1168,7 +1166,7 @@ async fn get_flow_version_by_id( flow.summary, flow.description, flow.archived, - flow.extra_perms, flow.view_only, + flow.extra_perms, flow.dedicated_worker, flow.tag, flow.ws_error_handler_muted, @@ -1431,8 +1429,8 @@ async fn update_flow( // if new path, must clone flow to new path and delete old flow for flow_version foreign key constraint sqlx::query!( "INSERT INTO flow - (workspace_id, path, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, job_token_scopes) - SELECT workspace_id, $1, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, job_token_scopes + (workspace_id, path, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, job_token_scopes) + SELECT workspace_id, $1, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, job_token_scopes FROM flow WHERE path = $2 AND workspace_id = $3", nf.path, @@ -1884,7 +1882,7 @@ async fn get_flow_by_path( flow.summary, flow.description, flow.archived, - flow.extra_perms, flow.view_only, + flow.extra_perms, flow.dedicated_worker, flow.tag, flow.ws_error_handler_muted, @@ -1926,7 +1924,7 @@ async fn get_flow_by_path( flow.summary, flow.description, flow.archived, - flow.extra_perms, flow.view_only, + flow.extra_perms, flow.dedicated_worker, flow.tag, flow.ws_error_handler_muted, diff --git a/backend/windmill-api-groups/src/access.rs b/backend/windmill-api-groups/src/access.rs index 6fa159c008..c35546e5a9 100644 --- a/backend/windmill-api-groups/src/access.rs +++ b/backend/windmill-api-groups/src/access.rs @@ -137,11 +137,11 @@ fn items_query() -> String { (split_part(i.path, '/', 1) = 'u' AND split_part(i.path, '/', 2) = s.usr) AS own, CASE WHEN split_part(i.path, '/', 1) = 'g' AND split_part(i.path, '/', 2) = ANY(s.groups) THEN split_part(i.path, '/', 2) END AS path_group, - (i.extra_perms ->> ('u/' || s.usr))::boolean AS user_grant, + (i.extra_perms ->> ('u/' || s.usr)) IN ('true', 'write') AS user_grant, ARRAY(SELECT substr(e.key, 3) FROM jsonb_each_text(i.extra_perms) e WHERE e.key = ANY(s.pgroups) ORDER BY e.key) AS group_read, ARRAY(SELECT substr(e.key, 3) FROM jsonb_each_text(i.extra_perms) e - WHERE e.key = ANY(s.pgroups) AND e.value::boolean ORDER BY e.key) AS group_write, + WHERE e.key = ANY(s.pgroups) AND e.value IN ('true', 'write') ORDER BY e.key) AS group_write, CASE WHEN split_part(i.path, '/', 1) = 'f' AND split_part(i.path, '/', 2) = ANY(s.fr) THEN split_part(i.path, '/', 2) END AS folder, (split_part(i.path, '/', 1) = 'f' AND split_part(i.path, '/', 2) = ANY(s.fw)) AS folder_write diff --git a/backend/windmill-api-groups/src/folders.rs b/backend/windmill-api-groups/src/folders.rs index 353c9061c6..9d6088c3ab 100644 --- a/backend/windmill-api-groups/src/folders.rs +++ b/backend/windmill-api-groups/src/folders.rs @@ -60,9 +60,6 @@ pub struct Folder { pub display_name: String, pub owners: Vec, pub extra_perms: serde_json::Value, - /// Principals of `extra_perms` that may view but not run what the folder holds. - #[serde(default)] - pub view_only: Vec, pub summary: Option, pub created_by: Option, pub edited_at: Option>, @@ -78,7 +75,6 @@ pub struct NewFolder { pub display_name: Option, pub owners: Option>, pub extra_perms: Option, - pub view_only: Option>, pub default_permissioned_as: Option, pub labels: Option>, } @@ -89,9 +85,6 @@ pub struct UpdateFolder { pub display_name: Option, pub owners: Option>, pub extra_perms: Option, - /// `None` keeps the stored list: git sync posts a folder file whole, and one written before - /// view-only grants existed must not turn every viewer into a runner. - pub view_only: Option>, pub default_permissioned_as: Option, pub labels: Option>, } @@ -122,7 +115,7 @@ async fn list_folders( let allowed = build_scope_path_predicate(&authed, "folders", "read"); let rows = sqlx::query_as!( Folder, - "SELECT workspace_id, name, display_name, owners, extra_perms, view_only, summary, created_by, edited_at, default_permissioned_as, labels FROM folder WHERE workspace_id = $1 ORDER BY name asc LIMIT $2 OFFSET $3", + "SELECT workspace_id, name, display_name, owners, extra_perms, summary, created_by, edited_at, default_permissioned_as, labels FROM folder WHERE workspace_id = $1 ORDER BY name asc LIMIT $2 OFFSET $3", w_id, per_page as i64, offset as i64 @@ -320,6 +313,7 @@ async fn create_folder( .unwrap_or_else(|| serde_json::Value::Object(serde_json::Map::new())); if extra_perms.is_object() { + normalize_acl_values(&mut extra_perms)?; let extra_mut = extra_perms.as_object_mut().unwrap(); for o in &owners { extra_mut.insert(o.clone(), serde_json::json!(true)); @@ -338,7 +332,7 @@ async fn create_folder( if let Err(e) = sqlx::query_as!( Folder, - "INSERT INTO folder (workspace_id, name, display_name, owners, extra_perms, view_only, summary, created_by, edited_at, default_permissioned_as, labels) VALUES ($1, $2, $3, $4, $5, $10, $6, $7, now(), $8, $9)", + "INSERT INTO folder (workspace_id, name, display_name, owners, extra_perms, summary, created_by, edited_at, default_permissioned_as, labels) VALUES ($1, $2, $3, $4, $5, $6, $7, now(), $8, $9)", w_id, ng.name, ng.display_name.unwrap_or(ng.name.clone()), @@ -347,12 +341,7 @@ async fn create_folder( ng.summary, authed.username, default_permissioned_as, - ng.labels.as_deref().filter(|l| !l.is_empty()) as Option<&[String]>, - &ng.view_only - .unwrap_or_default() - .into_iter() - .filter(|p| extra_perms.get(p) == Some(&serde_json::json!(false))) - .collect::>(), + ng.labels.as_deref().filter(|l| !l.is_empty()) as Option<&[String]> ) .execute(&mut *tx) .await { @@ -461,11 +450,7 @@ async fn update_folder( // update_folder can also grant permissions (owners / extra_perms / default_permissioned_as), // so it is a sharing path and must honor the demo-workspace sharing restriction. - if ng.owners.is_some() - || ng.extra_perms.is_some() - || ng.view_only.is_some() - || ng.default_permissioned_as.is_some() - { + if ng.owners.is_some() || ng.extra_perms.is_some() || ng.default_permissioned_as.is_some() { crate::check_demo_workspace_restriction(&authed, &w_id, "Sharing")?; } @@ -519,34 +504,20 @@ async fn update_folder( )), ); } - if let Some(extra_perms) = ng.extra_perms { + if let Some(mut extra_perms) = ng.extra_perms { if !extra_perms.is_object() { return Err(windmill_common::error::Error::BadRequest(format!( "extra_perms must be an object, received {}", extra_perms.to_string() ))); } + normalize_acl_values(&mut extra_perms)?; sqlb.set( "extra_perms", "?".bind(&serde_json::to_string(&extra_perms).map_err(to_anyhow)?), ); } - let view_only_changed = ng.view_only.is_some(); - if let Some(view_only) = ng.view_only.as_ref() { - sqlb.set( - "view_only", - "?".bind(&format!( - "{{{}}}", - view_only - .iter() - .map(|x| format!("\"{}\"", x.replace('\\', "\\\\").replace('"', "\\\""))) - .collect::>() - .join(","), - )), - ); - } - if let Some(default_permissioned_as) = ng.default_permissioned_as.as_ref() { validate_default_permissioned_as(default_permissioned_as)?; sqlb.set( @@ -597,8 +568,7 @@ async fn update_folder( for o in nfolder.owners { if !extra_perms .get(&o) - .and_then(|x| x.as_bool()) - .unwrap_or(false) + .is_some_and(windmill_common::auth::acl_writes) { return Err(windmill_common::error::Error::BadRequest(format!( "Owner {} would not have permission to write to folder and that is an invalid state", @@ -631,12 +601,11 @@ async fn update_folder( ) .await?; } - if extra_perms_changed || view_only_changed { + if extra_perms_changed { log_folder_permission_change(&mut *tx, &w_id, &name, &authed.username, "update_acl", None) .await?; - prune_view_only(&mut *tx, &w_id, &name).await?; } - if owners_changed || extra_perms_changed || view_only_changed { + if owners_changed || extra_perms_changed { windmill_common::auth::notify_run_perms_change(&mut *tx).await?; } if default_permissioned_as_changed { @@ -655,7 +624,7 @@ async fn update_folder( } tx.commit().await?; - if owners_changed || extra_perms_changed || view_only_changed { + if owners_changed || extra_perms_changed { windmill_common::auth::invalidate_run_perms_cache(); } @@ -686,7 +655,7 @@ pub async fn get_folderopt<'c>( ) -> Result> { let folderopt = sqlx::query_as!( Folder, - "SELECT workspace_id, name, display_name, owners, extra_perms, view_only, summary, created_by, edited_at, default_permissioned_as, labels FROM folder WHERE name = $1 AND workspace_id = $2", + "SELECT workspace_id, name, display_name, owners, extra_perms, summary, created_by, edited_at, default_permissioned_as, labels FROM folder WHERE name = $1 AND workspace_id = $2", name, w_id ) @@ -928,7 +897,6 @@ async fn add_owner( .bind(&owner) .fetch_optional(&mut *tx) .await?; - prune_view_only(&mut *tx, &w_id, &name).await?; audit_log( &mut *tx, @@ -1013,7 +981,7 @@ async fn remove_owner( if let Some(write) = write { let old_write = sqlx::query_scalar::<_, Option>( "UPDATE folder SET extra_perms = jsonb_set(extra_perms, array[$4]::text[], to_jsonb($1), \ - true) FROM (SELECT (extra_perms->>$4)::boolean as old_val FROM folder WHERE name = $2 AND workspace_id = $3) old \ + true) FROM (SELECT (extra_perms->>$4) IN ('true', 'write') as old_val FROM folder WHERE name = $2 AND workspace_id = $3) old \ WHERE name = $2 AND workspace_id = $3 RETURNING old.old_val" ) .bind(write) @@ -1030,7 +998,6 @@ async fn remove_owner( owner, name, write )); } - prune_view_only(&mut *tx, &w_id, &name).await?; } audit_log( @@ -1104,18 +1071,22 @@ pub async fn log_folder_permission_change<'c, E: sqlx::Executor<'c, Database = P Ok(()) } -/// Keeps in `view_only` only principals still holding a read grant, so replacing a folder's -/// grants cannot leave a stale entry that a later read grant would silently pick up. -async fn prune_view_only(tx: &mut sqlx::PgConnection, w_id: &str, name: &str) -> Result<()> { - sqlx::query!( - "UPDATE folder SET view_only = ARRAY( - SELECT v FROM unnest(view_only) v WHERE extra_perms->>v = 'false' - ) WHERE name = $1 AND workspace_id = $2", - name, - w_id - ) - .execute(tx) - .await?; +/// Accepts each grant as `true`, `false`, `"read"`, `"run"` or `"write"`, and stores it the way +/// `/acls/add` does: booleans for run and write, which every client reads, `"read"` otherwise. +fn normalize_acl_values(extra_perms: &mut serde_json::Value) -> Result<()> { + for (owner, v) in extra_perms.as_object_mut().into_iter().flatten() { + *v = match &*v { + serde_json::Value::Bool(_) => continue, + serde_json::Value::String(l) if l == "read" => continue, + serde_json::Value::String(l) if l == "run" => serde_json::json!(false), + serde_json::Value::String(l) if l == "write" => serde_json::json!(true), + _ => { + return Err(error::Error::BadRequest(format!( + "Invalid grant for {owner}: {v}, expected true, false, \"read\", \"run\" or \"write\"" + ))) + } + }; + } Ok(()) } diff --git a/backend/windmill-api-groups/src/granular_acls.rs b/backend/windmill-api-groups/src/granular_acls.rs index 6c769cdb58..46835ba695 100644 --- a/backend/windmill-api-groups/src/granular_acls.rs +++ b/backend/windmill-api-groups/src/granular_acls.rs @@ -88,7 +88,6 @@ const KINDS: [&str; 21] = [ pub fn workspaced_service() -> Router { Router::new() .route("/get/{*path}", get(get_granular_acls)) - .route("/get_view_only/{*path}", get(get_granular_acls_view_only)) .route("/add/{*path}", post(add_granular_acl)) .route("/remove/{*path}", post(remove_granular_acl)) } @@ -102,8 +101,8 @@ pub enum AclLevel { Write, } -/// Kinds whose ACL tells reading from running (`view_only`). On every other kind a read grant is -/// all there is. +/// Kinds whose ACL tells reading from running, with a `"read"` value. On every other kind `false` +/// is all a reader gets. const RUN_LEVEL_KINDS: [&str; 4] = ["script", "flow", "resource", "folder"]; #[derive(Serialize, Deserialize)] @@ -212,25 +211,22 @@ async fn add_granular_acl( // DeployedObject::RawApp so the worker writes back `.raw_app.json`. let table = if kind == "raw_app" { "app" } else { kind }; // SAFETY: `kind` has been validated against the `KINDS` allowlist before reaching this function. - let set_view_only = if has_run_level { - ", view_only = CASE WHEN $6 THEN array_append(array_remove(view_only, $5), $5) \ - ELSE array_remove(view_only, $5) END" - } else { - "" + // Run and write stay `false` and `true`, which every client reads; only the level they + // could not express is a string. + let value = match level { + AclLevel::Read => serde_json::json!("read"), + _ => serde_json::json!(level == AclLevel::Write), }; - let sql = format!( - "UPDATE {table} SET extra_perms = jsonb_set(extra_perms, $1, to_jsonb($2), \ - true){set_view_only} WHERE {identifier} = $3 AND workspace_id = $4 RETURNING extra_perms" - ); - let mut query = sqlx::query_scalar::<_, serde_json::Value>(&sql) - .bind(vec![owner.clone()]) - .bind(write.unwrap_or(false)) - .bind(path) - .bind(&w_id); - if has_run_level { - query = query.bind(&owner).bind(level == AclLevel::Read); - } - let obj_o = query.fetch_optional(&mut *tx).await?; + let obj_o = sqlx::query_scalar::<_, serde_json::Value>(&format!( + "UPDATE {table} SET extra_perms = jsonb_set(extra_perms, $1, $2, \ + true) WHERE {identifier} = $3 AND workspace_id = $4 RETURNING extra_perms" + )) + .bind(vec![owner.clone()]) + .bind(value) + .bind(path) + .bind(&w_id) + .fetch_optional(&mut *tx) + .await?; let _ = not_found_if_none(obj_o, &kind, &path)?; @@ -465,19 +461,14 @@ async fn remove_granular_acl( // LIMIT 1: `script` shares (workspace_id, path) across versions, so `old` can // return >1 row, which would break the scalar subquery in RETURNING. let has_run_level = RUN_LEVEL_KINDS.contains(&kind); - let unset_view_only = if has_run_level { - ", view_only = array_remove(view_only, $1)" - } else { - "" - }; let obj_o = sqlx::query_scalar::<_, bool>(&format!( "WITH old AS ( SELECT extra_perms->$1 as old_write FROM {table} WHERE {identifier} = $2 AND workspace_id = $3 AND extra_perms ? $1 ) - UPDATE {table} SET extra_perms = extra_perms - $1{unset_view_only} + UPDATE {table} SET extra_perms = extra_perms - $1 WHERE {identifier} = $2 AND workspace_id = $3 AND extra_perms ? $1 - RETURNING (SELECT old_write FROM old LIMIT 1)::bool" + RETURNING (SELECT old_write FROM old LIMIT 1) IN ('true', '\"write\"')" )) .bind(&owner) .bind(path) @@ -676,34 +667,3 @@ async fn get_granular_acls( Ok(Json(obj)) } - -/// The principals of `/acls/get` whose read grant does not include running: empty for every kind -/// without a run level. -async fn get_granular_acls_view_only( - authed: ApiAuthed, - Extension(user_db): Extension, - Path((w_id, path)): Path<(String, StripPath)>, -) -> JsonResult> { - let path = path.to_path(); - let (kind, path) = path - .split_once('/') - .ok_or_else(|| Error::BadRequest("Invalid path or kind".to_string()))?; - if !KINDS.contains(&kind) { - return Err(Error::BadRequest("Invalid kind".to_string())); - } - if !RUN_LEVEL_KINDS.contains(&kind) { - return Ok(Json(vec![])); - } - let identifier = if kind == "folder" { "name" } else { "path" }; - let mut tx = user_db.begin(&authed).await?; - // SAFETY: `kind` is one of `RUN_LEVEL_KINDS`. - let view_only = sqlx::query_scalar::<_, Vec>(&format!( - "SELECT view_only FROM {kind} WHERE {identifier} = $1 AND workspace_id = $2 LIMIT 1" - )) - .bind(path) - .bind(w_id) - .fetch_optional(&mut *tx) - .await?; - tx.commit().await?; - Ok(Json(not_found_if_none(view_only, &kind, &path)?)) -} diff --git a/backend/windmill-api-integration-tests/tests/view_only_acls.rs b/backend/windmill-api-integration-tests/tests/view_only_acls.rs index bf489ff568..0faab30122 100644 --- a/backend/windmill-api-integration-tests/tests/view_only_acls.rs +++ b/backend/windmill-api-integration-tests/tests/view_only_acls.rs @@ -47,6 +47,12 @@ async fn test_view_only_grants(db: Pool) -> anyhow::Result<()> { let admin = client_for("SECRET_TOKEN"); let viewer = client_for("SECRET_TOKEN_2"); // test-user-2 let runner = client_for("SECRET_TOKEN_3"); // test-user-3 + // Before any request of theirs: the groups of a token are cached. + sqlx::query( + "INSERT INTO usr_to_group (workspace_id, group_, usr) VALUES ('test-workspace', 'all', 'test-user-2')", + ) + .execute(&db) + .await?; assert_eq!( post(&admin, port, "folders/create", json!({"name": "vo"})).await?, @@ -238,6 +244,27 @@ async fn test_view_only_grants(db: Pool) -> anyhow::Result<()> { post(&runner, port, "jobs/run/p/u/test-user/own", json!({})).await?, 403 ); + // A personal view-only grant beside a group's write grant: the write policies read it + // without failing on it. + for grant in [ + json!({"owner": "g/all", "write": true}), + json!({"owner": "u/test-user-2", "level": "read"}), + ] { + assert_eq!( + post(&admin, port, "acls/add/script/u/test-user/own", grant).await?, + 200 + ); + } + let deployed: serde_json::Value = admin + .get(format!( + "http://localhost:{port}/api/w/{WS}/scripts/get/p/u/test-user/own" + )) + .send() + .await? + .json() + .await?; + let next = bash_script("u/test-user/own", deployed["hash"].as_str()); + assert_eq!(post(&viewer, port, "scripts/create", next).await?, 201); Ok(()) } diff --git a/backend/windmill-api-scripts/src/scripts.rs b/backend/windmill-api-scripts/src/scripts.rs index 60075fb8e1..cefc89e205 100644 --- a/backend/windmill-api-scripts/src/scripts.rs +++ b/backend/windmill-api-scripts/src/scripts.rs @@ -203,7 +203,6 @@ async fn list_scripts( "o.created_at as created_at", "archived", "extra_perms", - "o.view_only", if !lq.without_description.unwrap_or(false) { "description" } else { @@ -455,7 +454,6 @@ async fn list_scripts( created_at: row.created_at, archived: false, extra_perms: serde_json::Value::Object(serde_json::Map::new()), - view_only: vec![], language, starred: false, tag: v.get("tag").and_then(|s| s.as_str()).map(|s| s.to_string()), @@ -1546,7 +1544,6 @@ async fn create_script_internal<'c>( struct ParentInfo { p_hashes: Vec, perms: serde_json::Value, - view_only: Vec, p_path: String, } // When auto_parent is set, resolve parent_hash to the current head for this path @@ -1829,11 +1826,6 @@ async fn create_script_internal<'c>( } else { ps.extra_perms }, - view_only: if parent_adopted_from_retired_path { - vec![] - } else { - ps.view_only - }, p_path: ps.path, })), }; @@ -1853,10 +1845,6 @@ async fn create_script_internal<'c>( .as_ref() .map(|v| v.perms.clone()) .unwrap_or(json!({})); - let view_only = parent_hashes_and_perms - .as_ref() - .map(|v| v.view_only.clone()) - .unwrap_or_default(); // A dbt lock names a manifest digest and engine versions that only a // dependency job can determine, and that job is also what publishes the // script's manifest graph. Honouring a supplied one would skip it, leaving @@ -2397,16 +2385,6 @@ async fn create_script_internal<'c>( ) .execute(&mut *tx) .await?; - if !view_only.is_empty() { - sqlx::query!( - "UPDATE script SET view_only = $1 WHERE hash = $2 AND workspace_id = $3", - &view_only, - &hash.0, - &w_id - ) - .execute(&mut *tx) - .await?; - } windmill_common::scopes::log_job_token_scopes_deploy( "script", resolved_job_token_scopes.as_deref(), diff --git a/backend/windmill-api-users/src/users.rs b/backend/windmill-api-users/src/users.rs index c82cf419e7..87473d5357 100644 --- a/backend/windmill-api-users/src/users.rs +++ b/backend/windmill-api-users/src/users.rs @@ -2612,14 +2612,8 @@ pub async fn delete_workspace_user_internal( ]; // SAFETY: `table` comes from a hardcoded allowlist `extra_perms_tables`, not user input. for table in &extra_perms_tables { - // A `view_only` entry left behind would make a later grant to a re-added user view-only. - let view_only = if ["script", "flow", "resource", "folder"].contains(table) { - ", view_only = array_remove(view_only, 'u/' || $1)" - } else { - "" - }; sqlx::query(&format!( - "UPDATE {table} SET extra_perms = extra_perms - ('u/' || $1){view_only} \ + "UPDATE {table} SET extra_perms = extra_perms - ('u/' || $1) \ WHERE extra_perms ? ('u/' || $1) AND workspace_id = $2" )) .bind(username_to_delete) diff --git a/backend/windmill-api-workspaces/src/workspaces.rs b/backend/windmill-api-workspaces/src/workspaces.rs index 1e93517304..89d907c3d1 100644 --- a/backend/windmill-api-workspaces/src/workspaces.rs +++ b/backend/windmill-api-workspaces/src/workspaces.rs @@ -8066,8 +8066,8 @@ async fn clone_folders( target_workspace_id: &str, ) -> Result<()> { sqlx::query!( - "INSERT INTO folder (workspace_id, name, display_name, owners, extra_perms, view_only, summary, edited_at, created_by, default_permissioned_as, labels) - SELECT $2, name, display_name, owners, extra_perms, view_only, summary, edited_at, created_by, default_permissioned_as, labels + "INSERT INTO folder (workspace_id, name, display_name, owners, extra_perms, summary, edited_at, created_by, default_permissioned_as, labels) + SELECT $2, name, display_name, owners, extra_perms, summary, edited_at, created_by, default_permissioned_as, labels FROM folder WHERE workspace_id = $1", source_workspace_id, @@ -8248,13 +8248,13 @@ async fn clone_resources( let repoint = (!windmill_common::can_preserve_on_behalf_of(authed)) .then(|| username_to_permissioned_as(&authed.username)); sqlx::query!( - "INSERT INTO resource (workspace_id, path, value, description, resource_type, extra_perms, view_only, edited_at, created_by) + "INSERT INTO resource (workspace_id, path, value, description, resource_type, extra_perms, edited_at, created_by) SELECT $2, path, CASE WHEN $3::text IS NOT NULL AND resource_type = 'ai_agent' AND jsonb_typeof(value) = 'object' AND value ? 'on_behalf_of' THEN jsonb_set(value, '{on_behalf_of}', to_jsonb($3::text)) ELSE value END, - description, resource_type, extra_perms, view_only, edited_at, created_by + description, resource_type, extra_perms, edited_at, created_by FROM resource WHERE workspace_id = $1", source_workspace_id, @@ -8384,7 +8384,7 @@ async fn clone_scripts( r#"INSERT INTO script ( workspace_id, hash, path, parent_hashes, summary, description, content, created_by, created_at, archived, schema, deleted, is_template, - extra_perms, view_only, lock, lock_error_logs, language, kind, tag, + extra_perms, lock, lock_error_logs, language, kind, tag, envs, concurrent_limit, concurrency_time_window_s, cache_ttl, dedicated_worker, ws_error_handler_muted, priority, timeout, delete_after_use, delete_after_secs, restart_unless_cancelled, concurrency_key, @@ -8394,7 +8394,7 @@ async fn clone_scripts( SELECT $1, hash, path, parent_hashes, summary, description, content, created_by, created_at, archived, schema, deleted, is_template, - extra_perms, view_only, lock, lock_error_logs, language, kind, tag, + extra_perms, lock, lock_error_logs, language, kind, tag, envs, concurrent_limit, concurrency_time_window_s, cache_ttl, dedicated_worker, ws_error_handler_muted, priority, timeout, delete_after_use, delete_after_secs, restart_unless_cancelled, concurrency_key, @@ -8821,13 +8821,13 @@ async fn clone_flows( sqlx::query!( "INSERT INTO flow ( workspace_id, path, summary, description, value, edited_by, edited_at, - archived, schema, extra_perms, view_only, dependency_job, tag, + archived, schema, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, concurrency_key, versions, on_behalf_of, on_behalf_of_email, lock_error_logs, job_token_scopes ) SELECT $2, path, summary, description, value, edited_by, edited_at, - archived, schema, extra_perms, view_only, NULL, tag, + archived, schema, extra_perms, NULL, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, concurrency_key, ARRAY[]::bigint[], -- Same predicate as clone_scripts. diff --git a/backend/windmill-api-workspaces/src/workspaces_extra.rs b/backend/windmill-api-workspaces/src/workspaces_extra.rs index 5af4c84fd3..19087df2bf 100644 --- a/backend/windmill-api-workspaces/src/workspaces_extra.rs +++ b/backend/windmill-api-workspaces/src/workspaces_extra.rs @@ -450,8 +450,8 @@ pub(crate) async fn change_workspace_id( info!("Duplicating flow table rows"); sqlx::query!( "INSERT INTO flow - (workspace_id, path, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, lock_error_logs, job_token_scopes) - SELECT $1, path, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, lock_error_logs, job_token_scopes + (workspace_id, path, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, lock_error_logs, job_token_scopes) + SELECT $1, path, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, lock_error_logs, job_token_scopes FROM flow WHERE workspace_id = $2", &rw.new_id, &old_id @@ -696,8 +696,8 @@ pub(crate) async fn change_workspace_id( // Duplicate folders with new workspace id (FK constraint) info!("Duplicating folder table rows"); sqlx::query!( - "INSERT INTO folder (name, workspace_id, display_name, owners, extra_perms, view_only, summary, edited_at, created_by, default_permissioned_as, labels) \ - SELECT name, $1, display_name, owners, extra_perms, view_only, summary, edited_at, created_by, default_permissioned_as, labels \ + "INSERT INTO folder (name, workspace_id, display_name, owners, extra_perms, summary, edited_at, created_by, default_permissioned_as, labels) \ + SELECT name, $1, display_name, owners, extra_perms, summary, edited_at, created_by, default_permissioned_as, labels \ FROM folder WHERE workspace_id = $2", &rw.new_id, &old_id diff --git a/backend/windmill-api/openapi.yaml b/backend/windmill-api/openapi.yaml index aa0e2a59f0..6a0a8d6308 100644 --- a/backend/windmill-api/openapi.yaml +++ b/backend/windmill-api/openapi.yaml @@ -24685,12 +24685,7 @@ paths: type: string extra_perms: additionalProperties: - type: boolean - view_only: - type: array - description: Principals of `extra_perms` that may view what the folder holds but not run it. - items: - type: string + $ref: "#/components/schemas/AclValue" default_permissioned_as: $ref: '#/components/schemas/FolderDefaultPermissionedAs' labels: @@ -24734,12 +24729,7 @@ paths: type: string extra_perms: additionalProperties: - type: boolean - view_only: - type: array - description: Principals of `extra_perms` that may view what the folder holds but not run it. Omitted keeps the stored list. - items: - type: string + $ref: "#/components/schemas/AclValue" default_permissioned_as: $ref: '#/components/schemas/FolderDefaultPermissionedAs' labels: @@ -25697,34 +25687,7 @@ paths: content: application/json: schema: - type: object - additionalProperties: - type: boolean - - /w/{workspace}/acls/get_view_only/{kind}/{path}: - get: - summary: get the principals of the granular acls that may view but not run - operationId: getGranularAclsViewOnly - tags: - - granular_acl - parameters: - - $ref: "#/components/parameters/WorkspaceId" - - $ref: "#/components/parameters/Path" - - name: kind - in: path - required: true - schema: - type: string - enum: [script, flow, resource, folder] - responses: - "200": - description: principals with a view-only grant - content: - application/json: - schema: - type: array - items: - type: string + $ref: "#/components/schemas/ExtraPerms" /w/{workspace}/acls/add/{kind}/{path}: post: @@ -31985,7 +31948,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean + $ref: "#/components/schemas/AclValue" starred: type: boolean archived: @@ -32089,12 +32052,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean - view_only: - type: array - description: Principals of `extra_perms` that may view but not run it. - items: - type: string + $ref: "#/components/schemas/AclValue" lock: type: string lock_error_logs: @@ -33542,7 +33500,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean + $ref: "#/components/schemas/AclValue" is_expired: type: boolean refresh_error: @@ -34211,12 +34169,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean - view_only: - type: array - description: Principals of `extra_perms` that may view but not run it. - items: - type: string + $ref: "#/components/schemas/AclValue" created_by: type: string edited_at: @@ -34278,12 +34231,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean - view_only: - type: array - description: Principals of `extra_perms` that may view but not run it. - items: - type: string + $ref: "#/components/schemas/AclValue" is_expired: type: boolean refresh_error: @@ -34472,7 +34420,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean + $ref: "#/components/schemas/AclValue" description: Additional permissions for this schedule email: type: string @@ -34882,7 +34830,7 @@ components: type: object description: Additional permissions for this trigger additionalProperties: - type: boolean + $ref: "#/components/schemas/AclValue" workspace_id: type: string description: The workspace this trigger belongs to @@ -37883,7 +37831,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean + $ref: "#/components/schemas/AclValue" required: - name @@ -37971,12 +37919,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean - view_only: - type: array - description: Principals of `extra_perms` that may view but not run it. - items: - type: string + $ref: "#/components/schemas/AclValue" summary: type: string created_by: @@ -38482,7 +38425,17 @@ components: ExtraPerms: type: object additionalProperties: - type: boolean + $ref: "#/components/schemas/AclValue" + + AclValue: + description: > + A grant: `true` writes; `false` is the level below write, which runs a script, flow or + AI agent and reads anything else; or the level by name. `read` alone views a script, + flow, AI agent or folder content without running it. + oneOf: + - type: boolean + - type: string + enum: [read, run, write] FlowMetadata: type: object @@ -38500,11 +38453,6 @@ components: type: boolean extra_perms: $ref: "#/components/schemas/ExtraPerms" - view_only: - type: array - description: Principals of `extra_perms` that may view but not run it. - items: - type: string starred: type: boolean draft_only: @@ -38769,7 +38717,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean + $ref: "#/components/schemas/AclValue" starred: type: boolean edited_at: @@ -38879,7 +38827,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean + $ref: "#/components/schemas/AclValue" starred: type: boolean version: @@ -38937,7 +38885,7 @@ components: extra_perms: type: object additionalProperties: - type: boolean + $ref: "#/components/schemas/AclValue" custom_path: type: string raw_app: diff --git a/backend/windmill-api/src/ai_session_tools/gen/tools.json b/backend/windmill-api/src/ai_session_tools/gen/tools.json index 55ee6a8b01..1e65e7c1d7 100644 --- a/backend/windmill-api/src/ai_session_tools/gen/tools.json +++ b/backend/windmill-api/src/ai_session_tools/gen/tools.json @@ -502,7 +502,7 @@ }, { "name": "read_workspace_item", - "description": "Read one workspace item or draft. Prefers your draft when one exists; pass version: \"deployed\" to read the deployed state instead. A deployed item carries extraPerms (a draft does not; pass version: \"deployed\" for it): who it is shared with beyond its owner, as u/ or g/ → true (write) or false (read-only). A folder returns its owners and extraPerms; a group returns its members and extraPerms (who may manage it). For a folder or group, path is its name. A g/ entry grants every member of that group (g/all is everyone), and workspace admins can read and write every folder and item whatever these lists say.", + "description": "Read one workspace item or draft. Prefers your draft when one exists; pass version: \"deployed\" to read the deployed state instead. A deployed item carries extraPerms (a draft does not; pass version: \"deployed\" for it): who it is shared with beyond its owner, as u/ or g/ → true (write), false (read; on a script, flow, agent or folder also run) or \"read\" (view only: sees it and its runs, cannot run it). A folder returns its owners and extraPerms; a group returns its members and extraPerms (who may manage it). For a folder or group, path is its name. A g/ entry grants every member of that group (g/all is everyone), and workspace admins can read and write every folder and item whatever these lists say.", "parameters": { "type": "object", "properties": { diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index 7784872066..050d6448e4 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -2414,7 +2414,6 @@ async fn require_preview_label_runnable( /// A job, or one of its `parent_job` ancestors, as its ACL names what it runs. struct JobRunnable { id: Uuid, - depth: i32, created_by: String, target: Option<(RunnableAclKind, String)>, } @@ -2434,7 +2433,7 @@ async fn job_runnables(db: &DB, w_id: &str, ids: &[Uuid]) -> error::Result error::Result Some(RunnableAclKind::Flow), _ => None, }; - JobRunnable { - id: r.id, - depth: r.depth, - created_by: r.created_by, - target: kind.zip(r.runnable_path), - } + JobRunnable { id: r.id, created_by: r.created_by, target: kind.zip(r.runnable_path) } }) .collect()) } -/// `require_can_run` on what the job itself runs, for a route that starts it again. +/// `require_can_run` on what the job runs, for a route that starts it again: its own runnable, +/// or for a branch or loop child, which has none, the nearest ancestor's. #[cfg(feature = "enterprise")] async fn require_can_run_job( db: &DB, @@ -2488,10 +2483,12 @@ async fn require_can_run_job( w_id: &str, id: Uuid, ) -> error::Result<()> { - for job in job_runnables(db, w_id, &[id]).await? { - if let (0, Some((kind, path))) = (job.depth, job.target) { - require_can_run(db, &authed.to_authed_ref(), w_id, kind, &path).await?; - } + let nearest = job_runnables(db, w_id, &[id]) + .await? + .into_iter() + .find_map(|job| job.target); + if let Some((kind, path)) = nearest { + require_can_run(db, &authed.to_authed_ref(), w_id, kind, &path).await?; } Ok(()) } diff --git a/backend/windmill-api/src/mcp/utils.rs b/backend/windmill-api/src/mcp/utils.rs index 7c87a2a8b2..1557e40d94 100644 --- a/backend/windmill-api/src/mcp/utils.rs +++ b/backend/windmill-api/src/mcp/utils.rs @@ -197,10 +197,10 @@ fn items_query( sqlb.and_where(format!( "(split_part(o.path, '/', 1) = 'u' AND split_part(o.path, '/', 2) = current_setting('session.user') \ OR split_part(o.path, '/', 1) = 'g' AND split_part(o.path, '/', 2) = ANY(regexp_split_to_array(current_setting('session.groups'), ',')) \ - OR acl_grants_run(o.extra_perms, o.view_only, {principals}) \ + OR acl_grants_run(o.extra_perms, {principals}) \ OR EXISTS (SELECT 1 FROM folder f WHERE split_part(o.path, '/', 1) = 'f' \ AND f.workspace_id = o.workspace_id AND f.name = split_part(o.path, '/', 2) \ - AND (f.owners::text[] && {principals} OR acl_grants_run(f.extra_perms, f.view_only, {principals}))))" + AND (f.owners::text[] && {principals} OR acl_grants_run(f.extra_perms, {principals}))))" )); } diff --git a/backend/windmill-api/src/offboarding.rs b/backend/windmill-api/src/offboarding.rs index db97270c02..3fe9750d2b 100644 --- a/backend/windmill-api/src/offboarding.rs +++ b/backend/windmill-api/src/offboarding.rs @@ -894,8 +894,8 @@ async fn offboard_user_from_workspace<'c>( let flows_reassigned = sqlx::query_scalar!( r#"WITH inserted AS ( INSERT INTO flow - (workspace_id, path, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, lock_error_logs, job_token_scopes) - SELECT workspace_id, REGEXP_REPLACE(path, 'u/' || $2 || '/(.*)', $1 || '/\1'), summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, lock_error_logs, job_token_scopes + (workspace_id, path, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, lock_error_logs, job_token_scopes) + SELECT workspace_id, REGEXP_REPLACE(path, 'u/' || $2 || '/(.*)', $1 || '/\1'), summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, labels, lock_error_logs, job_token_scopes FROM flow WHERE path LIKE ('u/' || $2 || '/%') AND workspace_id = $3 RETURNING 1 diff --git a/backend/windmill-api/src/trash.rs b/backend/windmill-api/src/trash.rs index fbbc344251..39b50b01dd 100644 --- a/backend/windmill-api/src/trash.rs +++ b/backend/windmill-api/src/trash.rs @@ -206,10 +206,8 @@ async fn restore_script(tx: &mut sqlx::PgConnection, item: &TrashItemWithData) - .and_then(|v| v.as_array()) .ok_or_else(|| Error::internal_err("Invalid trash data for script"))?; - // The `view_only` default merged under each snapshot of a script, flow or resource: one - // trashed before the column existed lacks the key, which would insert NULL into it. for script in scripts { - sqlx::query("INSERT INTO script SELECT * FROM jsonb_populate_record(null::script, '{\"view_only\": []}'::jsonb || $1)") + sqlx::query("INSERT INTO script SELECT * FROM jsonb_populate_record(null::script, $1)") .bind(script) .execute(&mut *tx) .await @@ -255,7 +253,7 @@ async fn restore_flow(tx: &mut sqlx::PgConnection, item: &TrashItemWithData) -> .get("row") .ok_or_else(|| Error::internal_err("Invalid trash data for flow"))?; - sqlx::query("INSERT INTO flow SELECT * FROM jsonb_populate_record(null::flow, '{\"view_only\": []}'::jsonb || $1)") + sqlx::query("INSERT INTO flow SELECT * FROM jsonb_populate_record(null::flow, $1)") .bind(row) .execute(&mut *tx) .await?; @@ -427,7 +425,7 @@ async fn restore_variable(tx: &mut sqlx::PgConnection, item: &TrashItemWithData) if let Some(linked_resource) = data.get("linked_resource") { if !linked_resource.is_null() { sqlx::query( - "INSERT INTO resource SELECT * FROM jsonb_populate_record(null::resource, '{\"view_only\": []}'::jsonb || $1) + "INSERT INTO resource SELECT * FROM jsonb_populate_record(null::resource, $1) ON CONFLICT DO NOTHING", ) .bind(linked_resource) @@ -462,7 +460,7 @@ async fn restore_resource(tx: &mut sqlx::PgConnection, item: &TrashItemWithData) .get("row") .ok_or_else(|| Error::internal_err("Invalid trash data for resource"))?; - sqlx::query("INSERT INTO resource SELECT * FROM jsonb_populate_record(null::resource, '{\"view_only\": []}'::jsonb || $1)") + sqlx::query("INSERT INTO resource SELECT * FROM jsonb_populate_record(null::resource, $1)") .bind(row) .execute(&mut *tx) .await?; diff --git a/backend/windmill-api/src/users.rs b/backend/windmill-api/src/users.rs index a5667601da..9153454dfe 100644 --- a/backend/windmill-api/src/users.rs +++ b/backend/windmill-api/src/users.rs @@ -596,7 +596,7 @@ async fn update_username_in_workpsace<'c>( .await?; sqlx::query!( - "UPDATE resource SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)), view_only = array_replace(view_only, 'u/' || $2, 'u/' || $1) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", + "UPDATE resource SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", new_username, old_username, w_id @@ -781,7 +781,7 @@ async fn update_username_in_workpsace<'c>( .unwrap(); sqlx::query!( - "UPDATE script SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)), view_only = array_replace(view_only, 'u/' || $2, 'u/' || $1) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", + "UPDATE script SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", new_username, old_username, w_id @@ -806,8 +806,8 @@ async fn update_username_in_workpsace<'c>( // ---- flows ---- sqlx::query!( r#"INSERT INTO flow - (workspace_id, path, summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, job_token_scopes) - SELECT workspace_id, REGEXP_REPLACE(path,'u/' || $2 || '/(.*)','u/' || $1 || '/\1'), summary, description, archived, extra_perms, view_only, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, job_token_scopes + (workspace_id, path, summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, job_token_scopes) + SELECT workspace_id, REGEXP_REPLACE(path,'u/' || $2 || '/(.*)','u/' || $1 || '/\1'), summary, description, archived, extra_perms, dependency_job, tag, ws_error_handler_muted, dedicated_worker, timeout, visible_to_runner_only, on_behalf_of, on_behalf_of_email, concurrency_key, versions, value, schema, edited_by, edited_at, job_token_scopes FROM flow WHERE path LIKE ('u/' || $2 || '/%') AND workspace_id = $3"#, new_username, @@ -876,7 +876,7 @@ async fn update_username_in_workpsace<'c>( .await?; sqlx::query!( - "UPDATE flow SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)), view_only = array_replace(view_only, 'u/' || $2, 'u/' || $1) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", + "UPDATE flow SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", new_username, old_username, w_id @@ -1089,7 +1089,7 @@ async fn update_username_in_workpsace<'c>( .await?; sqlx::query!( - "UPDATE folder SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)), view_only = array_replace(view_only, 'u/' || $2, 'u/' || $1) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", + "UPDATE folder SET extra_perms = extra_perms - ('u/' || $2) || jsonb_build_object(('u/' || $1), extra_perms->('u/' || $2)) WHERE extra_perms ? ('u/' || $2) AND workspace_id = $3", new_username, old_username, w_id diff --git a/backend/windmill-api/src/workspaces_export.rs b/backend/windmill-api/src/workspaces_export.rs index ce82b926ee..ceaea724da 100644 --- a/backend/windmill-api/src/workspaces_export.rs +++ b/backend/windmill-api/src/workspaces_export.rs @@ -123,8 +123,6 @@ struct ScriptMetadata { pub job_token_scopes: Option>, #[serde(skip_serializing_if = "is_empty_extra_perms")] pub extra_perms: serde_json::Value, - #[serde(skip_serializing_if = "Vec::is_empty")] - pub view_only: Vec, } /// `syncBehavior` as the CLI writes it (`"v1"`); anything unparseable is v0, matching @@ -481,16 +479,6 @@ where obj.remove("extra_perms"); } } - // Only meaningful beside `extra_perms`, and omitted while empty so files exported - // before view-only grants existed stay unchanged. - if !obj.contains_key("extra_perms") - || obj - .get("view_only") - .and_then(|v| v.as_array()) - .is_some_and(|a| a.is_empty()) - { - obj.remove("view_only"); - } if obj .get("default_permissioned_as") .and_then(|v| v.as_array()) @@ -752,7 +740,7 @@ pub(crate) async fn tarball_workspace( .flatten(); { - let folders = sqlx::query_as::<_, Folder>("SELECT name, workspace_id, display_name, owners, extra_perms, view_only, summary, edited_at, created_by, default_permissioned_as, labels FROM folder WHERE workspace_id = $1") + let folders = sqlx::query_as::<_, Folder>("SELECT name, workspace_id, display_name, owners, extra_perms, summary, edited_at, created_by, default_permissioned_as, labels FROM folder WHERE workspace_id = $1") .bind(&w_id) .fetch_all(&mut *tx) .await?; @@ -888,11 +876,6 @@ pub(crate) async fn tarball_workspace( } else { serde_json::Value::Null }, - view_only: if matches!(new_kinds_extra_perms, ExtraPermsBehavior::KeepIfNonEmpty) { - script.view_only - } else { - vec![] - }, }; let metadata_str = serde_json::to_string_pretty(&metadata).unwrap(); archive @@ -904,7 +887,7 @@ pub(crate) async fn tarball_workspace( if !skip_resources.unwrap_or(false) { let resources = sqlx::query_as!( Resource, - "SELECT workspace_id, path, value, description, resource_type, extra_perms, view_only, created_by, edited_at, labels FROM resource WHERE workspace_id = $1 AND resource_type <> ALL($2)", + "SELECT workspace_id, path, value, description, resource_type, extra_perms, created_by, edited_at, labels FROM resource WHERE workspace_id = $1 AND resource_type <> ALL($2)", &w_id, &windmill_store::resources::INTERNAL_RESOURCE_TYPES.map(|t| t.to_string())[..] ) @@ -951,7 +934,7 @@ pub(crate) async fn tarball_workspace( { let flows = sqlx::query_as::<_, Flow>( - "SELECT flow.workspace_id, flow.path, flow.summary, flow.description, flow.archived, flow.extra_perms, flow.view_only, flow.dedicated_worker, flow.tag, flow.ws_error_handler_muted, flow.timeout, flow.visible_to_runner_only, flow.on_behalf_of, flow.labels, flow.job_token_scopes, flow_version.schema, flow_version.value, flow_version.created_at as edited_at, flow_version.created_by as edited_by + "SELECT flow.workspace_id, flow.path, flow.summary, flow.description, flow.archived, flow.extra_perms, flow.dedicated_worker, flow.tag, flow.ws_error_handler_muted, flow.timeout, flow.visible_to_runner_only, flow.on_behalf_of, flow.labels, flow.job_token_scopes, flow_version.schema, flow_version.value, flow_version.created_at as edited_at, flow_version.created_by as edited_by FROM flow LEFT JOIN flow_version ON flow_version.id = flow.versions[array_upper(flow.versions, 1)] WHERE flow.workspace_id = $1 AND flow.archived = false", diff --git a/backend/windmill-common/src/auth.rs b/backend/windmill-common/src/auth.rs index f7ea0f6843..8de71743ab 100644 --- a/backend/windmill-common/src/auth.rs +++ b/backend/windmill-common/src/auth.rs @@ -230,8 +230,8 @@ pub fn invalidate_run_perms_cache() { } /// Whether the caller may start `path`, as opposed to only reading it. Readers run unless every -/// grant they read it through is view-only (`view_only` of the item or of its folder): run is the -/// union of the grants, as read and write are. Call it on top of the read check the fetch of the +/// grant they read it through is `"read"` (on the item or on its folder): run is the union of the +/// grants, as read and write are. Call it on top of the read check the fetch of the /// runnable already does, and of the role's `run` capability, which stays the ceiling. pub async fn require_can_run( db: &DB, @@ -274,20 +274,20 @@ pub async fn require_can_run( "WITH item AS ( -- The newest version only: a script reusing a retired path starts with no grants, -- and the retired versions' must not run it. - (SELECT extra_perms, view_only FROM script + (SELECT extra_perms FROM script WHERE $5 = 'script' AND workspace_id = $1 AND path = $2 ORDER BY created_at DESC LIMIT 1) - UNION ALL SELECT extra_perms, view_only FROM flow + UNION ALL SELECT extra_perms FROM flow WHERE $5 = 'flow' AND workspace_id = $1 AND path = $2 - UNION ALL SELECT extra_perms, view_only FROM resource + UNION ALL SELECT extra_perms FROM resource WHERE $5 = 'resource' AND workspace_id = $1 AND path = $2 ) SELECT EXISTS ( - SELECT 1 FROM item WHERE acl_grants_run(item.extra_perms, item.view_only, $4) + SELECT 1 FROM item WHERE acl_grants_run(item.extra_perms, $4) ) OR EXISTS ( SELECT 1 FROM folder f WHERE f.workspace_id = $1 AND f.name = $3 - AND (f.owners::text[] && $4 OR acl_grants_run(f.extra_perms, f.view_only, $4)) + AND (f.owners::text[] && $4 OR acl_grants_run(f.extra_perms, $4)) ) AS \"can_run!\"", w_id, path, @@ -372,6 +372,11 @@ impl PermsCache { } } +/// Whether an `extra_perms` value grants write: `true` or `"write"`. +pub fn acl_writes(v: &serde_json::Value) -> bool { + v.as_bool().unwrap_or(false) || v.as_str() == Some("write") +} + /// Check a user's access level against an `extra_perms` JSONB object. /// /// Returns `None` if the user has no matching entry (no access). @@ -390,7 +395,7 @@ pub fn check_extra_perms( format!("{PERMISSIONED_AS_USER_PREFIX}{username}") }; if let Some(v) = extra_perms.get(&user_key) { - return Some(v.as_bool().unwrap_or(false)); + return Some(acl_writes(v)); } // Check group permissions — return highest access level found @@ -404,7 +409,7 @@ pub fn check_extra_perms( }; if let Some(v) = extra_perms.get(&key) { found = true; - if v.as_bool().unwrap_or(false) { + if acl_writes(v) { write = true; break; } @@ -785,7 +790,7 @@ pub async fn get_folders_for_user<'e, E: sqlx::PgExecutor<'e>>( .collect::>(); perms.insert(0, format!("u/{}", username)); let folders = sqlx::query!( - "SELECT name, (EXISTS (SELECT 1 FROM (SELECT key, value FROM jsonb_each_text(extra_perms) WHERE key = ANY($1)) t WHERE value::boolean IS true)) as write, $1 && owners::text[] as owner FROM folder + "SELECT name, (EXISTS (SELECT 1 FROM (SELECT key, value FROM jsonb_each_text(extra_perms) WHERE key = ANY($1)) t WHERE value IN ('true', 'write'))) as write, $1 && owners::text[] as owner FROM folder WHERE extra_perms ?| $1 AND workspace_id = $2", &perms[..], w_id, @@ -814,8 +819,8 @@ pub async fn get_view_only_folders_for_user<'e, E: sqlx::PgExecutor<'e>>( perms.push(format!("u/{}", username)); let folders = sqlx::query_scalar!( "SELECT name FROM folder - WHERE workspace_id = $2 AND extra_perms ?| $1 AND cardinality(view_only) > 0 - AND NOT owners::text[] && $1 AND NOT acl_grants_run(extra_perms, view_only, $1)", + WHERE workspace_id = $2 AND extra_perms ?| $1 + AND NOT owners::text[] && $1 AND NOT acl_grants_run(extra_perms, $1)", &perms[..], w_id, ) diff --git a/backend/windmill-common/src/scripts.rs b/backend/windmill-common/src/scripts.rs index 59e2f8b99e..79a2065354 100644 --- a/backend/windmill-common/src/scripts.rs +++ b/backend/windmill-common/src/scripts.rs @@ -139,7 +139,6 @@ async fn prefetch_cached_script_inner( deleted: script.deleted, is_template: script.is_template, extra_perms: script.extra_perms, - view_only: script.view_only, lock: script.lock, lock_error_logs: script.lock_error_logs, language: script.language, @@ -460,7 +459,7 @@ pub async fn deploy_relocked_version( sqlx::query!(" INSERT INTO script (workspace_id, hash, path, parent_hashes, summary, description, content, \ - created_by, schema, is_template, extra_perms, view_only, lock, language, kind, tag, \ + created_by, schema, is_template, extra_perms, lock, language, kind, tag, \ envs, concurrent_limit, concurrency_time_window_s, cache_ttl, cache_ignore_s3_path, \ dedicated_worker, ws_error_handler_muted, priority, restart_unless_cancelled, \ delete_after_use, delete_after_secs, timeout, concurrency_key, visible_to_runner_only, auto_kind, \ @@ -468,7 +467,7 @@ pub async fn deploy_relocked_version( job_token_scopes, lock_error_logs, created_at) SELECT workspace_id, $1, path, array_prepend($2::bigint, COALESCE(parent_hashes, '{}'::bigint[])), summary, description, \ - content, created_by, schema, is_template, extra_perms, view_only, $4::text, language, kind, tag, \ + content, created_by, schema, is_template, extra_perms, $4::text, language, kind, tag, \ envs, concurrent_limit, concurrency_time_window_s, cache_ttl, cache_ignore_s3_path, \ dedicated_worker, ws_error_handler_muted, priority, restart_unless_cancelled, \ delete_after_use, delete_after_secs, timeout, concurrency_key, visible_to_runner_only, auto_kind, \ diff --git a/backend/windmill-store/src/resources.rs b/backend/windmill-store/src/resources.rs index 78613936ad..14382bac1c 100644 --- a/backend/windmill-store/src/resources.rs +++ b/backend/windmill-store/src/resources.rs @@ -169,10 +169,6 @@ pub struct Resource { pub description: Option, pub resource_type: String, pub extra_perms: serde_json::Value, - /// Principals of `extra_perms` that may view but not run it (AI agents). - #[serde(default, skip_serializing_if = "Vec::is_empty")] - #[sqlx(default)] - pub view_only: Vec, pub created_by: Option, pub edited_at: Option>, #[serde(skip_serializing_if = "Option::is_none")] @@ -187,10 +183,6 @@ pub struct ListableResource { pub description: Option, pub resource_type: String, pub extra_perms: serde_json::Value, - /// Principals of `extra_perms` that may view but not run it (AI agents). - #[serde(default, skip_serializing_if = "Vec::is_empty")] - #[sqlx(default)] - pub view_only: Vec, pub created_by: Option, pub edited_at: Option>, pub is_linked: Option, @@ -379,7 +371,6 @@ async fn list_resources( "resource.description", "resource_type", "resource.extra_perms", - "resource.view_only", "(now() > account.expires_at) as is_expired", "variable.path IS NOT NULL as is_linked", "account.refresh_token != '' as is_refreshed", @@ -582,7 +573,6 @@ async fn list_resources( description, resource_type, extra_perms: serde_json::Value::Object(serde_json::Map::new()), - view_only: vec![], created_by: None, edited_at: Some(row.created_at), is_linked: None, @@ -622,7 +612,7 @@ async fn get_resource( ListableResource, // `null::bool` columns align with the struct fields; deployed rows are never draft-only. "SELECT resource.workspace_id, resource.path, resource.value, resource.description, - resource.resource_type, resource.extra_perms, resource.view_only, resource.created_by, resource.edited_at, + resource.resource_type, resource.extra_perms, resource.created_by, resource.edited_at, resource.labels, folder_labels(resource.workspace_id, resource.path) as \"inherited_labels?\", (now() > account.expires_at) as is_expired, account.refresh_token != '' as is_refreshed, diff --git a/backend/windmill-types/src/flows.rs b/backend/windmill-types/src/flows.rs index 9e24a88b4d..331fb7ba32 100644 --- a/backend/windmill-types/src/flows.rs +++ b/backend/windmill-types/src/flows.rs @@ -29,10 +29,6 @@ pub struct Flow { pub archived: bool, pub schema: Option, pub extra_perms: serde_json::Value, - /// Principals of `extra_perms` that may view but not run it. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - #[sqlx(default)] - pub view_only: Vec, #[serde(skip_serializing_if = "Option::is_none")] pub dedicated_worker: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -93,10 +89,6 @@ pub struct ListableFlow { pub edited_at: Option>, pub archived: bool, pub extra_perms: serde_json::Value, - /// Principals of `extra_perms` that may view but not run it. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - #[sqlx(default)] - pub view_only: Vec, pub starred: bool, /// `Some(true)` only on synthesised draft-only rows; `None` on deployed rows. /// See ListableScript in scripts.rs. diff --git a/backend/windmill-types/src/scripts.rs b/backend/windmill-types/src/scripts.rs index 7747113139..1e4a8858ed 100644 --- a/backend/windmill-types/src/scripts.rs +++ b/backend/windmill-types/src/scripts.rs @@ -325,7 +325,7 @@ pub fn id_to_codebase_info(id: &str) -> CodebaseInfo { /// Shared across all query sites so a schema change only needs one edit. pub const SCRIPT_COLUMNS: &str = concat!( "workspace_id, hash, path, parent_hashes, summary, description, content, ", - "created_by, created_at, archived, schema, deleted, is_template, extra_perms, view_only, ", + "created_by, created_at, archived, schema, deleted, is_template, extra_perms, ", "lock, lock_error_logs, language, kind, tag, envs, ", "dedicated_worker, ws_error_handler_muted, priority, cache_ttl, cache_ignore_s3_path, ", "timeout, delete_after_use, delete_after_secs, restart_unless_cancelled, ", @@ -352,10 +352,6 @@ pub struct Script { #[serde(skip_serializing_if = "Option::is_none")] pub is_template: Option, pub extra_perms: serde_json::Value, - /// Principals of `extra_perms` that may view but not run it. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - #[sqlx(default)] - pub view_only: Vec, #[serde(skip_serializing_if = "Option::is_none")] pub lock: Option, pub lock_error_logs: Option, @@ -458,10 +454,6 @@ pub struct ListableScript { pub created_at: chrono::DateTime, pub archived: bool, pub extra_perms: serde_json::Value, - /// Principals of `extra_perms` that may view but not run it. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - #[sqlx(default)] - pub view_only: Vec, pub language: ScriptLang, pub starred: bool, pub tag: Option, diff --git a/cli/src/commands/flow/flow.ts b/cli/src/commands/flow/flow.ts index d4156085c6..94944d3f06 100644 --- a/cli/src/commands/flow/flow.ts +++ b/cli/src/commands/flow/flow.ts @@ -277,12 +277,10 @@ export async function pushFlow( // step both for the up-to-date short-circuit and after the deploy. const { extra_perms: localPerms, - view_only: localViewOnly, job_token_scopes: localJobTokenScopes, ...localFlowBody } = localFlow as FlowFile & { extra_perms?: Record; - view_only?: string[]; }; // Always sent, unlike the other settings: the server keeps a restriction the body omits, // so a flow.yaml without the key has to clear it explicitly. @@ -351,8 +349,6 @@ export async function pushFlow( remotePath.replaceAll(SEP, "/"), localPerms, (flow as any)?.extra_perms, - localViewOnly, - (flow as any)?.view_only, ); } diff --git a/cli/src/commands/folder/folder.ts b/cli/src/commands/folder/folder.ts index 234c958b5f..0ebc4959ba 100644 --- a/cli/src/commands/folder/folder.ts +++ b/cli/src/commands/folder/folder.ts @@ -18,9 +18,7 @@ export interface FolderFile { summary: string | undefined; display_name: string | undefined; owners: Array | undefined; - extra_perms: { [record: string]: boolean } | undefined; - /** Principals of `extra_perms` that may view what the folder holds but not run it. */ - view_only?: string[]; + extra_perms: { [record: string]: boolean | "read" | "run" | "write" } | undefined; default_permissioned_as?: Array<{ path_glob: string; permissioned_as: string }>; labels?: Array; } diff --git a/cli/src/commands/script/script.ts b/cli/src/commands/script/script.ts index 177bce9de6..ccb56aff07 100644 --- a/cli/src/commands/script/script.ts +++ b/cli/src/commands/script/script.ts @@ -112,8 +112,6 @@ export interface ScriptFile { // (see applyExtraPermsDiff) — never through create_script — so a perm-only // change never bumps the script hash/version. extra_perms?: Record; - // Principals of `extra_perms` that may view the script but not run it. - view_only?: string[]; } /** @@ -734,8 +732,6 @@ export async function handleFile( remotePath.replaceAll(SEP, "/"), (typed as any)?.extra_perms, (remote as any)?.extra_perms, - (typed as any)?.view_only, - (remote as any)?.view_only, ); return true; } @@ -791,8 +787,6 @@ export async function handleFile( remotePath.replaceAll(SEP, "/"), (typed as any)?.extra_perms, (remote as any)?.extra_perms, - (typed as any)?.view_only, - (remote as any)?.view_only, ); return true; diff --git a/cli/src/commands/user/user.ts b/cli/src/commands/user/user.ts index 946d943371..300f614c6b 100644 --- a/cli/src/commands/user/user.ts +++ b/cli/src/commands/user/user.ts @@ -270,7 +270,7 @@ export async function pushGroup( // only consider extra_perms that concern actual members of the group const admins = Object.entries(remoteGroup.extra_perms ?? {}) - .filter(([k, v]) => v && remoteGroup.members?.includes(k.slice(2))) + .filter(([k, v]) => (v === true || v === "write") && remoteGroup.members?.includes(k.slice(2))) .map(([k, _]) => k) .sort(); group = { diff --git a/cli/src/core/extra_perms.ts b/cli/src/core/extra_perms.ts index 7b4af9f8f5..772c0ef1be 100644 --- a/cli/src/core/extra_perms.ts +++ b/cli/src/core/extra_perms.ts @@ -5,7 +5,20 @@ import type { AddGranularAclsData } from "../../gen/types.gen.ts"; export type ExtraPermsKind = AddGranularAclsData["kind"]; -type PermsMap = Record; +type Level = "read" | "run" | "write"; +type PermsMap = Record; + +/** Kinds whose read grant does not include running: there `false` is "run" and `"read"` views + * only. Elsewhere `false` and `"read"` are the same read grant. */ +const RUN_LEVEL_KINDS: string[] = ["script", "flow", "resource", "folder"]; + +/** A grant as the level it gives: `true` or `"write"`, `false` or `"run"`, or `"read"`. */ +function levelOf(value: unknown, runLevel: boolean): Level | undefined { + if (value === true || value === "write") return "write"; + if (value === false || value === "run") return runLevel ? "run" : "read"; + if (value === "read") return "read"; + return undefined; +} type Normalized = { perms: PermsMap; @@ -17,7 +30,7 @@ type Normalized = { malformedTop: boolean; }; -function normalize(value: unknown, source: string): Normalized { +function normalize(value: unknown, source: string, runLevel: boolean): Normalized { const perms: PermsMap = {}; const invalidOwners = new Set(); @@ -30,7 +43,7 @@ function normalize(value: unknown, source: string): Normalized { if (value !== undefined && value !== null) { log.error( colors.red( - `extra_perms: ${source} is not a {owner: boolean} map — skipping ACL sync to avoid clobbering remote ACLs`, + `extra_perms: ${source} is not a {owner: grant} map — skipping ACL sync to avoid clobbering remote ACLs`, ), ); return { perms, invalidOwners, malformedTop: true }; @@ -40,8 +53,9 @@ function normalize(value: unknown, source: string): Normalized { const invalidList: string[] = []; for (const [k, v] of Object.entries(value as Record)) { - if (typeof v === "boolean") { - perms[k] = v; + const level = levelOf(v, runLevel); + if (level !== undefined) { + perms[k] = level; } else { invalidOwners.add(k); invalidList.push(k); @@ -50,7 +64,7 @@ function normalize(value: unknown, source: string): Normalized { if (invalidList.length > 0) { log.error( colors.red( - `extra_perms: ${invalidList.length} invalid entry/entries in ${source} (non-boolean value, treating as "no opinion"): ${invalidList.join(", ")}`, + `extra_perms: ${invalidList.length} invalid entry/entries in ${source} (not true, false, "read", "run" or "write", treating as "no opinion"): ${invalidList.join(", ")}`, ), ); } @@ -104,11 +118,6 @@ export async function applyExtraPermsDiff( path: string, local: unknown, remote: unknown, - /** `view_only` of the yaml: the read grants that do not include running. Absent is "no - * opinion" on that distinction, like an absent `extra_perms`, so a file written before it - * existed neither promotes nor demotes anyone. */ - localViewOnly?: unknown, - remoteViewOnly?: unknown, ): Promise { // Absent local field = "no opinion" — never call /acls/* in this case. // Crucially, this protects users who don't track ACLs in source from having @@ -117,33 +126,22 @@ export async function applyExtraPermsDiff( return 0; } - const localN = normalize(local, "local yaml"); + const runLevel = RUN_LEVEL_KINDS.includes(kind); + const localN = normalize(local, "local yaml", runLevel); // Top-level malformed (array, primitive, etc.) → treat as "no opinion" so a // typo in yaml can never silently revoke every remote ACL. if (localN.malformedTop) { return 0; } - const remoteN = normalize(remote, "remote response"); + const remoteN = normalize(remote, "remote response", runLevel); const localPerms = localN.perms; const remotePerms = remoteN.perms; - const localVO = Array.isArray(localViewOnly) - ? new Set(localViewOnly.filter((x): x is string => typeof x === "string")) - : undefined; - const remoteVO = new Set( - Array.isArray(remoteViewOnly) - ? remoteViewOnly.filter((x): x is string => typeof x === "string") - : [], - ); - - const toGrant: Array<[string, boolean, "read" | "run" | undefined]> = []; - for (const [owner, write] of Object.entries(localPerms)) { - const level = write || !localVO ? undefined : localVO.has(owner) ? "read" : "run"; - const levelDrift = - level !== undefined && owner in remotePerms && (level === "read") !== remoteVO.has(owner); - if (!(owner in remotePerms) || remotePerms[owner] !== write || levelDrift) { - toGrant.push([owner, write, level]); + const toGrant: Array<[string, Level]> = []; + for (const [owner, level] of Object.entries(localPerms)) { + if (remotePerms[owner] !== level) { + toGrant.push([owner, level]); } } @@ -160,14 +158,18 @@ export async function applyExtraPermsDiff( } let calls = 0; - for (const [owner, write, level] of toGrant) { - const access = write ? "write" : level === "read" ? "view only" : "read"; + for (const [owner, level] of toGrant) { + const access = level === "read" && runLevel ? "view only" : level; try { await wmill.addGranularAcls({ workspace, kind, path, - requestBody: level ? { owner, write, level } : { owner, write }, + // Run and write as the `write` flag every server reads; `level` only for view-only. + requestBody: + level === "read" && runLevel + ? { owner, write: false, level } + : { owner, write: level === "write" }, }); log.info( colors.green( diff --git a/cli/test/extra_perms_levels_unit.test.ts b/cli/test/extra_perms_levels_unit.test.ts new file mode 100644 index 0000000000..b871559ca5 --- /dev/null +++ b/cli/test/extra_perms_levels_unit.test.ts @@ -0,0 +1,44 @@ +import { expect, test, beforeEach } from "bun:test"; +import { mockServices } from "./mock_services.ts"; + +const added: unknown[] = []; +const removed: unknown[] = []; +mockServices({ + addGranularAcls: async (req: { requestBody: unknown }) => { + added.push(req.requestBody); + return ""; + }, + removeGranularAcls: async (req: { requestBody: unknown }) => { + removed.push(req.requestBody); + return ""; + }, +}); + +const { applyExtraPermsDiff } = await import("../src/core/extra_perms.ts"); + +beforeEach(() => { + added.length = 0; + removed.length = 0; +}); + +// A grant is the level it gives, whichever of its spellings a file or the server uses. +test("booleans and level names of the same grant are in sync", async () => { + const calls = await applyExtraPermsDiff( + "ws", + "script", + "f/a/s", + { "u/a": true, "u/b": "run", "u/c": "read" }, + { "u/a": "write", "u/b": false, "u/c": "read" }, + ); + expect(calls).toBe(0); +}); + +test("view-only is granted by level where it exists, as a read grant elsewhere", async () => { + await applyExtraPermsDiff("ws", "flow", "f/a/f", { "u/a": "read" }, { "u/a": false }); + await applyExtraPermsDiff("ws", "variable", "f/a/v", { "u/b": "read" }, { "u/b": false }); + await applyExtraPermsDiff("ws", "variable", "f/a/v", { "u/c": "run" }, {}); + expect(added).toEqual([ + { owner: "u/a", write: false, level: "read" }, + { owner: "u/c", write: false }, + ]); +}); diff --git a/cli/test/extra_perms_view_only_unit.test.ts b/cli/test/extra_perms_view_only_unit.test.ts deleted file mode 100644 index ea172fe64e..0000000000 --- a/cli/test/extra_perms_view_only_unit.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { expect, test, beforeEach } from "bun:test"; -import { mockServices } from "./mock_services.ts"; - -const added: unknown[] = []; -mockServices({ - addGranularAcls: async (req: { requestBody: unknown }) => { - added.push(req.requestBody); - return ""; - }, - removeGranularAcls: async () => "", -}); - -const { applyExtraPermsDiff } = await import("../src/core/extra_perms.ts"); - -beforeEach(() => { - added.length = 0; -}); - -// A yaml written before view-only grants existed has no `view_only`: it must neither promote a -// remote view-only grant to run nor demote a new grant below run. -test("an absent view_only leaves levels alone", async () => { - await applyExtraPermsDiff( - "ws", - "script", - "f/a/s", - { "u/viewer": false, "u/new": false }, - { "u/viewer": false }, - undefined, - ["u/viewer"], - ); - expect(added).toEqual([{ owner: "u/new", write: false }]); -}); - -test("view_only moves a read grant between view and run", async () => { - await applyExtraPermsDiff( - "ws", - "flow", - "f/a/f", - { "u/a": false, "u/b": false }, - { "u/a": false, "u/b": false }, - ["u/a"], - ["u/b"], - ); - expect(added).toEqual([ - { owner: "u/a", write: false, level: "read" }, - { owner: "u/b", write: false, level: "run" }, - ]); -}); diff --git a/docs/workspace-roles.md b/docs/workspace-roles.md index 2b9144b6fa..9f1b9ecbf0 100644 --- a/docs/workspace-roles.md +++ b/docs/workspace-roles.md @@ -56,12 +56,25 @@ start further runs through the API either. ### View-only grants The same split exists per folder and per script, flow or AI agent: a read grant can withhold -running (Viewer, below Runner and Writer). `extra_perms` keeps its `{principal: write}` booleans, -which every RLS policy and client reads, and the principals whose read grant does not run are -listed in a `view_only` column of `folder`, `script`, `flow` and `resource`. A grant made without a -level (`write: false`, every grant from before levels) runs, and RLS is unchanged, so a viewer sees -the item and, through its folder, its runs. Run is the union of a caller's grants, as read and -write are: an item-level view-only grant does not withhold what the folder lets them run. +running (Viewer, below Runner and Writer). It is the value of the principal's `extra_perms` entry: + +| Value | Script, flow, agent (`resource`), folder | Every other kind | +|---|---|---| +| `true` or `"write"` | write | write | +| `false` or `"run"` | run | read | +| `"read"` | view only | read | + +Readers (RLS policies, the backend, the frontend, the CLI) accept all five. Writers store `true` +and `false`, and `"read"` only for a view-only grant, so a client that predates levels keeps +reading every other grant; one that cannot read `"read"` skips that grant rather than revoking +or widening it. Storing the names for every grant is a later step: its migration maps `false` to +`"run"` on the first column and to `"read"` on the second, and it waits until the CLI pinned in +the git-sync hub scripts reads them. The write policies of `script`, `flow` and `resource` compare +the value as text (`IN ('true', 'write')`); a `::boolean` cast there fails every writer of a row +whose own grant is `"read"`. A grant made without a level (`write: false`, every grant from before +levels) runs, and the read policies only test that the key exists, so a viewer sees the item and, +through its folder, its runs. Run is the union of a caller's grants, as read and write are: an +item-level view-only grant does not withhold what the folder lets them run. `windmill_common::auth::require_can_run` enforces it, on top of the RLS read and of the role's `run`, at each place that starts a deployed runnable for a caller: the run routes, restart, cancel @@ -71,11 +84,9 @@ owner on every fire. A schedule's later runs are not re-checked, as they were ne for read either: demoting its owner does not stop it. Flow steps, subflows and agent tools are not checked, as only the top-level run needs it. Cancel and run-now take run on the job or on one of its `parent_job` ancestors, as cancelling a job stops its descendants; a restart takes run on -the flow it restarts. Its positive answers are cached, so every write that can take -run away calls `notify_run_perms_change`; the cache's 60s expiry bounds what that cannot see, such -as an item deleted and recreated without the grant. Anything that copies one of those rows (a new script -version, a rename, a fork, a workspace rename) must copy `view_only` too: a copy that drops it -turns its viewers into runners. +the nearest of them with a runnable of its own. Its positive answers are cached, so every write +that can take run away calls `notify_run_perms_change`; the cache's 60s expiry bounds what that +cannot see, such as an item deleted and recreated without the grant. Unlike `fork`, withdrawing `run` makes a role restricted: it is an enforced gate on hot routes, and the fast path is what spares every unrestricted caller a role lookup on each run. It does not diff --git a/frontend/src/lib/components/FolderEditor.svelte b/frontend/src/lib/components/FolderEditor.svelte index c8dc90955c..5a8dec9fb6 100644 --- a/frontend/src/lib/components/FolderEditor.svelte +++ b/frontend/src/lib/components/FolderEditor.svelte @@ -27,6 +27,7 @@ import { onMount, tick, untrack } from 'svelte' import Select from './select/Select.svelte' import { safeSelectItems } from './select/utils.svelte' + import { aclWrites } from '$lib/utils' import TextInput from './text_input/TextInput.svelte' import PermissionHistory from './PermissionHistory.svelte' import { Minimatch } from 'minimatch' @@ -345,15 +346,14 @@ } function getRole(x: string): Role { - const viewer = x in (folder?.extra_perms ?? {}) - const writer = viewer && (folder?.extra_perms ?? {})[x] + const grant = (folder?.extra_perms ?? {})[x] const owner = folder?.owners?.includes(x) if (owner) { return 'admin' - } else if (writer) { + } else if (aclWrites(grant)) { return 'writer' - } else if ((folder?.view_only ?? []).includes(x)) { + } else if (grant === 'read') { return 'viewer' } else { return 'runner' @@ -515,9 +515,11 @@ default_permissioned_as: next.defaultPermissionedAs, owners: next.perms.filter((p) => p.role === 'admin').map((p) => p.owner_name), extra_perms: Object.fromEntries( - next.perms.map((p) => [p.owner_name, p.role === 'writer' || p.role === 'admin']) - ), - view_only: next.perms.filter((p) => p.role === 'viewer').map((p) => p.owner_name) + next.perms.map((p) => [ + p.owner_name, + p.role === 'viewer' ? 'read' : p.role === 'writer' || p.role === 'admin' + ]) + ) } }) sendUserToast(`Folder ${name} created`) diff --git a/frontend/src/lib/components/GroupEditor.svelte b/frontend/src/lib/components/GroupEditor.svelte index 44d7dc5eb1..fa5c7027c3 100644 --- a/frontend/src/lib/components/GroupEditor.svelte +++ b/frontend/src/lib/components/GroupEditor.svelte @@ -1,4 +1,6 @@ @@ -137,10 +139,7 @@
{vol.name} - } - canWrite={writable} - /> +
{vol.file_count} diff --git a/frontend/src/lib/components/copilot/chat/global/core.ts b/frontend/src/lib/components/copilot/chat/global/core.ts index 4447fc02e8..7a4097bc3b 100644 --- a/frontend/src/lib/components/copilot/chat/global/core.ts +++ b/frontend/src/lib/components/copilot/chat/global/core.ts @@ -3562,7 +3562,7 @@ export const globalTools: SessionTool<{}>[] = [ def: createToolDef( readWorkspaceItemSchema, 'read_workspace_item', - 'Read one workspace item or draft. Prefers your draft when one exists; pass version: "deployed" to read the deployed state instead. A deployed item carries extraPerms (a draft does not; pass version: "deployed" for it): who it is shared with beyond its owner, as u/ or g/ → true (write) or false (read-only). A folder returns its owners and extraPerms; a group returns its members and extraPerms (who may manage it). For a folder or group, path is its name. A g/ entry grants every member of that group (g/all is everyone), and workspace admins can read and write every folder and item whatever these lists say.' + 'Read one workspace item or draft. Prefers your draft when one exists; pass version: "deployed" to read the deployed state instead. A deployed item carries extraPerms (a draft does not; pass version: "deployed" for it): who it is shared with beyond its owner, as u/ or g/ → true (write), false (read; on a script, flow, agent or folder also run) or "read" (view only: sees it and its runs, cannot run it). A folder returns its owners and extraPerms; a group returns its members and extraPerms (who may manage it). For a folder or group, path is its name. A g/ entry grants every member of that group (g/all is everyone), and workspace admins can read and write every folder and item whatever these lists say.' ), planModeSafe: true, fn: async ({ args, workspace, toolId, toolCallbacks }) => { diff --git a/frontend/src/lib/components/copilot/chat/global/workspaceItems.ts b/frontend/src/lib/components/copilot/chat/global/workspaceItems.ts index c01044c85f..c2047234b2 100644 --- a/frontend/src/lib/components/copilot/chat/global/workspaceItems.ts +++ b/frontend/src/lib/components/copilot/chat/global/workspaceItems.ts @@ -1,3 +1,4 @@ +import type { ExtraPerms } from '$lib/gen' import type { AzureTriggerData, CreateResource, @@ -156,7 +157,7 @@ export type WorkspaceItem = { /** Who a deployed item is shared with beyond its path owner, as `u/` / * `g/` → true for write, false for read-only. A draft has no permissions of * its own, so a draft read leaves it unset rather than reporting the item unshared. */ - extraPerms?: Record + extraPerms?: ExtraPerms isDraft: boolean isLiveDraft?: boolean } diff --git a/frontend/src/lib/components/details/FlowDetail.svelte b/frontend/src/lib/components/details/FlowDetail.svelte index 4fc5faf363..3ad53fe1cb 100644 --- a/frontend/src/lib/components/details/FlowDetail.svelte +++ b/frontend/src/lib/components/details/FlowDetail.svelte @@ -157,7 +157,7 @@ ) // Unknown until the acting user resolves: the form offers a run meanwhile. const viewOnly = $derived( - !!flow && !!actingUser && !canRun(flow.path, flow.extra_perms, flow.view_only, actingUser) + !!flow && !!actingUser && !canRun(flow.path, flow.extra_perms, actingUser) ) const promptForAi = $derived((flow?.schema?.prompt_for_ai as string | undefined) ?? '') let shareModal: ShareModal | undefined = $state() diff --git a/frontend/src/lib/components/details/ScriptDetail.svelte b/frontend/src/lib/components/details/ScriptDetail.svelte index 90ec6f51c1..a7fdfbc838 100644 --- a/frontend/src/lib/components/details/ScriptDetail.svelte +++ b/frontend/src/lib/components/details/ScriptDetail.svelte @@ -185,10 +185,7 @@ // Unknown until the acting user resolves: the form offers a run meanwhile, as it would to // anyone the server then lets through. const viewOnly = $derived( - !isHubScript && - !!script && - !!actingUser && - !canRun(script.path, script.extra_perms, script.view_only, actingUser) + !isHubScript && !!script && !!actingUser && !canRun(script.path, script.extra_perms, actingUser) ) const editRights = useEditRights() const caps = $derived(editRights.capabilities) diff --git a/frontend/src/lib/components/flows/content/AgentDetailPage.svelte b/frontend/src/lib/components/flows/content/AgentDetailPage.svelte index b065e118da..5ee28440a9 100644 --- a/frontend/src/lib/components/flows/content/AgentDetailPage.svelte +++ b/frontend/src/lib/components/flows/content/AgentDetailPage.svelte @@ -116,7 +116,7 @@ let viewOnly = $derived( !!grants.current && !!operatingUser.current && - !canRun(path, grants.current.extra_perms, grants.current.view_only, operatingUser.current) + !canRun(path, grants.current.extra_perms, operatingUser.current) ) // Recorded once the agent is in: a path with nothing deployed never loads one. Not from a diff --git a/frontend/src/lib/components/flows/content/AgentResourceBar.svelte b/frontend/src/lib/components/flows/content/AgentResourceBar.svelte index 6d116cb79d..a5bdce1678 100644 --- a/frontend/src/lib/components/flows/content/AgentResourceBar.svelte +++ b/frontend/src/lib/components/flows/content/AgentResourceBar.svelte @@ -1,4 +1,5 @@