Skip to content

Commit

Permalink
fix extra_perms for schedule light
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Feb 13, 2025
1 parent a814024 commit 86d45c6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions backend/windmill-api/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,11 @@ async fn fix_job_completed_index(db: &DB) -> Result<(), Error> {
.await?;
});

run_windmill_migration!("v2_jobs_rls", &db, |tx| {
sqlx::query!("ALTER TABLE v2_job ENABLE ROW LEVEL SECURITY")
.execute(db)
.await?;
});
// run_windmill_migration!("v2_jobs_rls", &db, |tx| {
// sqlx::query!("ALTER TABLE v2_job ENABLE ROW LEVEL SECURITY")
// .execute(db)
// .await?;
// });

Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion backend/windmill-api/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ pub struct ScheduleLight {
pub script_path: String,
pub is_flow: bool,
pub summary: Option<String>,
pub extra_perms: serde_json::Value,
}
async fn list_schedule(
authed: ApiAuthed,
Expand All @@ -351,7 +352,7 @@ async fn list_schedule(
let mut tx = user_db.begin(&authed).await?;
let (per_page, offset) = paginate(Pagination { per_page: lsq.per_page, page: lsq.page });
let mut sqlb = SqlBuilder::select_from("schedule")
.field("workspace_id, path, edited_by, edited_at, schedule, timezone, enabled, script_path, is_flow, summary")
.field("workspace_id, path, edited_by, edited_at, schedule, timezone, enabled, script_path, is_flow, summary, extra_perms")
.order_by("edited_at", true)
.and_where("workspace_id = ?".bind(&w_id))
.offset(offset)
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/lib/components/SharedBadge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
let username = $userStore?.username ?? ''
let pgroups = $userStore?.pgroups ?? []
let pusername = `u/${username}`
let extraPermsKeys = Object.keys(extraPerms)
let extraPermsKeys = Object.keys(extraPerms ?? {})
if (pusername in extraPermsKeys) {
if (extraPerms[pusername]) {
if (extraPerms?.[pusername]) {
kind = 'write'
} else {
kind = 'read'
}
reason = 'This item was shared to you personally'
} else {
let writeGroup = pgroups.find((x) => extraPermsKeys.includes(x) && extraPerms[x])
let writeGroup = pgroups.find((x) => extraPermsKeys.includes(x) && extraPerms?.[x])
if (writeGroup) {
kind = 'write'
reason = `This item was write shared to the group ${writeGroup} which you are a member of`
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export function displayDate(
}
const dateChoices: Intl.DateTimeFormatOptions = displayDate
? {
day: 'numeric',
month: 'numeric'
}
day: 'numeric',
month: 'numeric'
}
: {}
return date.toLocaleString(undefined, {
...timeChoices,
Expand Down Expand Up @@ -351,7 +351,7 @@ export function removeItemAll<T>(arr: T[], value: T) {
}

export function emptyString(str: string | undefined | null): boolean {
return str === undefined || str === null || str === ''
return str === undefined || str === null || str === ''
}

export function emptyStringTrimmed(str: string | undefined | null): boolean {
Expand Down Expand Up @@ -705,18 +705,18 @@ export function canWrite(
if (user?.is_admin || user?.is_super_admin) {
return true
}
let keys = Object.keys(extra_perms)
let keys = Object.keys(extra_perms ?? {})
if (!user) {
return false
}
if (isObviousOwner(path, user)) {
return true
}
let userOwner = `u/${user.username}`
if (keys.includes(userOwner) && extra_perms[userOwner]) {
if (keys.includes(userOwner) && extra_perms?.[userOwner]) {
return true
}
if (user.pgroups.findIndex((x) => keys.includes(x) && extra_perms[x]) != -1) {
if (user.pgroups.findIndex((x) => keys.includes(x) && extra_perms?.[x]) != -1) {
return true
}
if (user.folders.findIndex((x) => path.startsWith('f/' + x + '/') && user.folders[x]) != -1) {
Expand Down Expand Up @@ -846,7 +846,7 @@ export async function tryEvery({
try {
await tryCode()
break
} catch (err) {}
} catch (err) { }
i++
}
if (i >= times) {
Expand Down

0 comments on commit 86d45c6

Please sign in to comment.