feat: slack team connected to multiple workspaces (#3500)

* feat: slack team connected to multiple workspaces

* chore: update ee ref
This commit is contained in:
HugoCasa
2024-04-03 17:47:23 +02:00
committed by GitHub
parent b332349f22
commit 6efaa199b4
8 changed files with 84 additions and 11 deletions
@@ -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"
}
@@ -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"
}
@@ -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"
}
+1 -1
View File
@@ -1 +1 @@
721b9298e35b831b390b7311b791a5b526dee923
ada71ad279d7e917ab64476bbcae75dd377bb161
@@ -0,0 +1 @@
-- Add down migration script here
@@ -0,0 +1,2 @@
-- Add up migration script here
ALTER TABLE public.workspace_settings DROP CONSTRAINT workspace_settings_slack_team_id_key
+29 -6
View File
@@ -415,6 +415,30 @@ async fn edit_slack_command(
) -> Result<String> {
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<DB>,
Path(w_id): Path<String>,
) -> Result<String> {
async fn get_usage(Extension(db): Extension<DB>, Path(w_id): Path<String>) -> Result<String> {
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())
}
}
@@ -811,8 +811,10 @@
<br /><br />
The script or flow is permissioned as group "slack" that will be automatically created
after connection to Slack.
<span class="font-bold text-xs">
The script or flow is permissioned as group "slack" that will be automatically created
after connection to Slack.
</span>
<br /><br />