diff --git a/backend/.sqlx/query-5445083864b2b092b012e894bff7630a1d7b9deb8d33e9f909061f351f96844e.json b/backend/.sqlx/query-55cb03040bc2a8c53dd7fbb42bbdcc40f463cbc52d94ed9315cf9a547d4c89f2.json similarity index 95% rename from backend/.sqlx/query-5445083864b2b092b012e894bff7630a1d7b9deb8d33e9f909061f351f96844e.json rename to backend/.sqlx/query-55cb03040bc2a8c53dd7fbb42bbdcc40f463cbc52d94ed9315cf9a547d4c89f2.json index c6247a6bd0..0e29ef4745 100644 --- a/backend/.sqlx/query-5445083864b2b092b012e894bff7630a1d7b9deb8d33e9f909061f351f96844e.json +++ b/backend/.sqlx/query-55cb03040bc2a8c53dd7fbb42bbdcc40f463cbc52d94ed9315cf9a547d4c89f2.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT * FROM workspace_settings WHERE slack_team_id = $1", + "query": "SELECT * FROM workspace_settings WHERE slack_team_id = $1 AND slack_command_script IS NOT NULL", "describe": { "columns": [ { @@ -144,5 +144,5 @@ true ] }, - "hash": "5445083864b2b092b012e894bff7630a1d7b9deb8d33e9f909061f351f96844e" + "hash": "55cb03040bc2a8c53dd7fbb42bbdcc40f463cbc52d94ed9315cf9a547d4c89f2" } diff --git a/backend/.sqlx/query-f632ca2e17a3952fc45bd40a055a9442c35453dff95140d2f252c4fe6a14c6a4.json b/backend/.sqlx/query-f632ca2e17a3952fc45bd40a055a9442c35453dff95140d2f252c4fe6a14c6a4.json new file mode 100644 index 0000000000..5145efa595 --- /dev/null +++ b/backend/.sqlx/query-f632ca2e17a3952fc45bd40a055a9442c35453dff95140d2f252c4fe6a14c6a4.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT EXISTS (SELECT 1 \n FROM workspace_settings \n WHERE workspace_id <> $1 \n AND slack_command_script IS NOT NULL\n AND slack_team_id IS NOT NULL \n AND slack_team_id = (SELECT slack_team_id FROM workspace_settings WHERE workspace_id = $1))\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "exists", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + null + ] + }, + "hash": "f632ca2e17a3952fc45bd40a055a9442c35453dff95140d2f252c4fe6a14c6a4" +} diff --git a/backend/.sqlx/query-fde1760ca5dfc0dbee1f4fae5239ec28786f2d8517f5db5049ac0a4d20c2611e.json b/backend/.sqlx/query-fde1760ca5dfc0dbee1f4fae5239ec28786f2d8517f5db5049ac0a4d20c2611e.json new file mode 100644 index 0000000000..c968b5be99 --- /dev/null +++ b/backend/.sqlx/query-fde1760ca5dfc0dbee1f4fae5239ec28786f2d8517f5db5049ac0a4d20c2611e.json @@ -0,0 +1,23 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT EXISTS (SELECT 1 \n FROM workspace_settings \n WHERE workspace_id <> $1 \n AND slack_command_script IS NOT NULL\n AND slack_team_id = $2\n AND (SELECT slack_command_script IS NOT NULL FROM workspace_settings WHERE workspace_id = $1))\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "exists", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Text", + "Text" + ] + }, + "nullable": [ + null + ] + }, + "hash": "fde1760ca5dfc0dbee1f4fae5239ec28786f2d8517f5db5049ac0a4d20c2611e" +} diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index 9e08e60b69..2051d93f5c 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -721b9298e35b831b390b7311b791a5b526dee923 \ No newline at end of file +ada71ad279d7e917ab64476bbcae75dd377bb161 \ No newline at end of file diff --git a/backend/migrations/20240403083110_remove_team_id_constraint.down.sql b/backend/migrations/20240403083110_remove_team_id_constraint.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20240403083110_remove_team_id_constraint.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20240403083110_remove_team_id_constraint.up.sql b/backend/migrations/20240403083110_remove_team_id_constraint.up.sql new file mode 100644 index 0000000000..3a91c3384c --- /dev/null +++ b/backend/migrations/20240403083110_remove_team_id_constraint.up.sql @@ -0,0 +1,2 @@ +-- Add up migration script here +ALTER TABLE public.workspace_settings DROP CONSTRAINT workspace_settings_slack_team_id_key \ No newline at end of file diff --git a/backend/windmill-api/src/workspaces.rs b/backend/windmill-api/src/workspaces.rs index 12a43cfc30..6208462146 100644 --- a/backend/windmill-api/src/workspaces.rs +++ b/backend/windmill-api/src/workspaces.rs @@ -415,6 +415,30 @@ async fn edit_slack_command( ) -> Result { require_admin(is_admin, &username)?; let mut tx = db.begin().await?; + + if es.slack_command_script.is_some() { + let exists_slack_command_with_team_id = sqlx::query_scalar!( + r#" + SELECT EXISTS (SELECT 1 + FROM workspace_settings + WHERE workspace_id <> $1 + AND slack_command_script IS NOT NULL + AND slack_team_id IS NOT NULL + AND slack_team_id = (SELECT slack_team_id FROM workspace_settings WHERE workspace_id = $1)) + "#, + &w_id + ) + .fetch_one(&mut *tx) + .await?.unwrap_or(false); + + if exists_slack_command_with_team_id { + return Err(Error::BadRequest( + "A workspace connected to the same slack team already has a command script. Please remove it first." + .to_string(), + )); + } + } + sqlx::query!( "UPDATE workspace_settings SET slack_command_script = $1 WHERE workspace_id = $2", es.slack_command_script, @@ -2805,7 +2829,9 @@ async fn change_workspace_id( &rw.new_id, &rw.new_name, &old_id - ).execute(&mut *tx).await?; + ) + .execute(&mut *tx) + .await?; sqlx::query!( "UPDATE account SET workspace_id = $1 WHERE workspace_id = $2", @@ -3083,10 +3109,7 @@ async fn change_workspace_id( )) } -async fn get_usage( - Extension(db): Extension, - Path(w_id): Path, -) -> Result { +async fn get_usage(Extension(db): Extension, Path(w_id): Path) -> Result { let usage = sqlx::query_scalar!( " SELECT usage.usage FROM usage @@ -3099,4 +3122,4 @@ async fn get_usage( .await? .unwrap_or(0); Ok(usage.to_string()) -} \ No newline at end of file +} diff --git a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte index 479c4388a3..a57e1a1bd3 100644 --- a/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/workspace_settings/+page.svelte @@ -811,8 +811,10 @@

- The script or flow is permissioned as group "slack" that will be automatically created - after connection to Slack. + + The script or flow is permissioned as group "slack" that will be automatically created + after connection to Slack. +