Skip to content

Commit

Permalink
Merge pull request #218 from nightly-labs/database_fixed
Browse files Browse the repository at this point in the history
Database fixed
  • Loading branch information
dzlk17 authored Oct 17, 2024
2 parents af32303 + a005cde commit c245751
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions database/src/tables/user_app_privileges/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl Db {
)>,
DbError,
> {
// 17.10.2024 Hubert: "If this ever breaks, I will write comments."
let query = format!(
"WITH RelevantTeams AS (
SELECT DISTINCT t.team_id, t.team_name, t.personal, t.subscription,
Expand All @@ -124,17 +125,16 @@ impl Db {
LEFT JOIN {REGISTERED_APPS_TABLE_NAME} ra ON t.team_id = ra.team_id
LEFT JOIN {USER_APP_PRIVILEGES_TABLE_NAME} uap ON ra.app_id = uap.app_id AND uap.user_id = $1
JOIN {USERS_TABLE_NAME} gu ON t.team_admin_id = gu.user_id
WHERE (t.team_admin_id = $1 OR uap.user_id = $1) AND ra.deactivated_at IS NULL AND t.deactivated_at IS NULL
WHERE (t.team_admin_id = $1 OR uap.user_id = $1) AND t.deactivated_at IS NULL
)
SELECT rt.team_id, rt.team_name, rt.personal, rt.subscription, rt.registration_timestamp,
rt.team_admin_email, rt.team_admin_id, ra.app_id, ra.app_name, ra.whitelisted_domains,
ra.ack_public_keys, ra.registration_timestamp AS app_registration_timestamp,
uap.user_id, uap.privilege_level, uap.creation_timestamp AS privilege_creation_timestamp,
rt.user_joined_team_timestamp, ra.deactivated_at
FROM RelevantTeams rt
LEFT JOIN {REGISTERED_APPS_TABLE_NAME} ra ON rt.team_id = ra.team_id
LEFT JOIN {REGISTERED_APPS_TABLE_NAME} ra ON rt.team_id = ra.team_id AND ra.deactivated_at IS NULL
LEFT JOIN {USER_APP_PRIVILEGES_TABLE_NAME} uap ON ra.app_id = uap.app_id AND uap.user_id = $1
WHERE ra.deactivated_at IS NULL
ORDER BY rt.team_id, ra.app_id"
);

Expand Down

0 comments on commit c245751

Please sign in to comment.