fix permissioned_as from username

This commit is contained in:
Ruben Fiszel
2023-01-17 12:49:24 +01:00
parent 40d566ab8e
commit d708b6faa5
8 changed files with 26 additions and 27 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ use windmill_audit::{audit_log, ActionKind};
use windmill_common::{
apps::ListAppQuery,
error::{to_anyhow, Error, JsonResult, Result},
users::owner_to_token_owner,
users::username_to_permissioned_as,
utils::{
http_get_from_hub, list_elems_from_hub, not_found_if_none, paginate, Pagination, StripPath,
},
@@ -610,7 +610,7 @@ async fn execute_component(
})?;
(
username.clone(),
owner_to_token_owner(&username, false),
username_to_permissioned_as(&username),
email,
)
}
+2 -2
View File
@@ -230,7 +230,7 @@ async fn create_flow(
serde_json::Map::new(),
&authed.username,
&authed.email,
windmill_common::users::owner_to_token_owner(&authed.username, false),
windmill_common::users::username_to_permissioned_as(&authed.username),
None,
None,
None,
@@ -377,7 +377,7 @@ async fn update_flow(
serde_json::Map::new(),
&authed.username,
&authed.email,
windmill_common::users::owner_to_token_owner(&authed.username, false),
windmill_common::users::username_to_permissioned_as(&authed.username),
None,
None,
None,
+2 -2
View File
@@ -19,7 +19,7 @@ use itertools::Itertools;
use windmill_audit::{audit_log, ActionKind};
use windmill_common::{
error::{self, Error, JsonResult, Result},
users::owner_to_token_owner,
users::username_to_permissioned_as,
utils::{not_found_if_none, paginate, Pagination},
};
@@ -145,7 +145,7 @@ async fn create_folder(
let mut tx = user_db.begin(&authed).await?;
check_name_conflict(&mut tx, &w_id, &ng.name).await?;
let owner = owner_to_token_owner(&authed.username, false);
let owner = username_to_permissioned_as(&authed.username);
let owners = &ng.owners.unwrap_or(vec![owner.clone()]);
if let Some(extra_perms) = ng.extra_perms.clone() {
+2 -2
View File
@@ -16,9 +16,9 @@ use axum::{
Json, Router,
};
use windmill_audit::{audit_log, ActionKind};
use windmill_common::users::username_to_permissioned_as;
use windmill_common::{
error::{Error, JsonResult, Result},
users::owner_to_token_owner,
utils::{not_found_if_none, paginate, Pagination},
};
@@ -199,7 +199,7 @@ async fn create_group(
w_id,
ng.name,
ng.summary,
serde_json::json!({owner_to_token_owner(&authed.username, false): true})
serde_json::json!({username_to_permissioned_as(&authed.username): true})
)
.execute(&mut tx)
.await?;
+8 -13
View File
@@ -29,7 +29,7 @@ use windmill_common::{
flows::FlowValue,
oauth2::HmacSha256,
scripts::{ScriptHash, ScriptLang},
users::owner_to_token_owner,
users::username_to_permissioned_as,
utils::{not_found_if_none, now_from_db, paginate, require_admin, Pagination, StripPath},
};
use windmill_queue::{get_queued_job, push, JobKind, JobPayload, QueuedJob, RawCode};
@@ -1132,11 +1132,6 @@ pub async fn run_flow_by_path(
let scheduled_for = run_query.get_scheduled_for(&mut tx).await?;
let args = run_query.add_include_headers(headers, args.unwrap_or_default());
let permissioned_as = if authed.username.contains('@') {
authed.username.clone()
} else {
owner_to_token_owner(&authed.username, false)
};
let (uuid, tx) = push(
tx,
&w_id,
@@ -1144,7 +1139,7 @@ pub async fn run_flow_by_path(
args,
&authed.username,
&authed.email,
permissioned_as,
username_to_permissioned_as(&authed.username),
scheduled_for,
None,
run_query.parent_job,
@@ -1179,7 +1174,7 @@ pub async fn run_job_by_path(
args,
&authed.username,
&authed.email,
owner_to_token_owner(&authed.username, false),
username_to_permissioned_as(&authed.username),
scheduled_for,
None,
run_query.parent_job,
@@ -1291,7 +1286,7 @@ pub async fn run_wait_result_job_by_path(
args,
&authed.username,
&authed.email,
owner_to_token_owner(&authed.username, false),
username_to_permissioned_as(&authed.username),
scheduled_for,
None,
run_query.parent_job,
@@ -1327,7 +1322,7 @@ pub async fn run_wait_result_job_by_hash(
args,
&authed.username,
&authed.email,
owner_to_token_owner(&authed.username, false),
username_to_permissioned_as(&authed.username),
scheduled_for,
None,
run_query.parent_job,
@@ -1381,7 +1376,7 @@ async fn run_preview_job(
args,
&authed.username,
&authed.email,
owner_to_token_owner(&authed.username, false),
username_to_permissioned_as(&authed.username),
scheduled_for,
None,
None,
@@ -1414,7 +1409,7 @@ async fn run_preview_flow_job(
args,
&authed.username,
&authed.email,
owner_to_token_owner(&authed.username, false),
username_to_permissioned_as(&authed.username),
scheduled_for,
None,
None,
@@ -1449,7 +1444,7 @@ pub async fn run_job_by_hash(
args,
&authed.username,
&authed.email,
owner_to_token_owner(&authed.username, false),
username_to_permissioned_as(&authed.username),
scheduled_for,
None,
run_query.parent_job,
+2 -2
View File
@@ -36,7 +36,7 @@ use windmill_common::{
to_i64, HubScript, ListScriptQuery, ListableScript, NewScript, Script, ScriptHash,
ScriptKind, ScriptLang,
},
users::owner_to_token_owner,
users::username_to_permissioned_as,
utils::{
list_elems_from_hub, not_found_if_none, paginate, require_admin, Pagination, StripPath,
},
@@ -374,7 +374,7 @@ async fn create_script(
serde_json::Map::new(),
&authed.username,
&authed.email,
owner_to_token_owner(&authed.username, false),
username_to_permissioned_as(&authed.username),
None,
None,
None,
+6 -3
View File
@@ -6,7 +6,10 @@
* LICENSE-AGPL for a copy of the license.
*/
pub fn owner_to_token_owner(user: &str, is_group: bool) -> String {
let prefix = if is_group { 'g' } else { 'u' };
format!("{}/{}", prefix, user)
pub fn username_to_permissioned_as(user: &str) -> String {
if user.contains('@') {
user.to_string()
} else {
format!("u/{}", user)
}
}
+2 -1
View File
@@ -13,6 +13,7 @@ use sqlx::{query_scalar, Postgres, Transaction};
use windmill_common::{
error::{self, Result},
schedule::Schedule,
users::username_to_permissioned_as,
utils::{now_from_db, StripPath},
};
@@ -80,7 +81,7 @@ pub async fn push_scheduled_job<'c>(
args,
&schedule_to_user(&schedule.path),
&schedule.email,
format!("u/{}", schedule.edited_by),
username_to_permissioned_as(&schedule.edited_by),
Some(next),
Some(schedule.path.clone()),
None,