-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8f67c9
commit f7e6d5b
Showing
13 changed files
with
879 additions
and
420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/postgres-database/src/simcore_postgres_database/utils_sql.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def assemble_array_groups(user_group_ids: list[int]) -> str: | ||
return ( | ||
"array[]::text[]" | ||
if len(user_group_ids) == 0 | ||
else f"""array[{', '.join(f"'{group_id}'" for group_id in user_group_ids)}]""" | ||
) |
30 changes: 30 additions & 0 deletions
30
packages/postgres-database/src/simcore_postgres_database/utils_workspaces_sql.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from simcore_postgres_database.models.groups import user_to_groups | ||
from simcore_postgres_database.models.workspaces_access_rights import ( | ||
workspaces_access_rights, | ||
) | ||
from sqlalchemy import func | ||
from sqlalchemy.dialects.postgresql import BOOLEAN, INTEGER | ||
from sqlalchemy.sql import Subquery, select | ||
|
||
|
||
def create_my_workspace_access_rights_subquery(user_id: int) -> Subquery: | ||
return ( | ||
select( | ||
workspaces_access_rights.c.workspace_id, | ||
func.json_build_object( | ||
"read", | ||
func.max(workspaces_access_rights.c.read.cast(INTEGER)).cast(BOOLEAN), | ||
"write", | ||
func.max(workspaces_access_rights.c.write.cast(INTEGER)).cast(BOOLEAN), | ||
"delete", | ||
func.max(workspaces_access_rights.c.delete.cast(INTEGER)).cast(BOOLEAN), | ||
).label("my_access_rights"), | ||
) | ||
.select_from( | ||
workspaces_access_rights.join( | ||
user_to_groups, user_to_groups.c.gid == workspaces_access_rights.c.gid | ||
) | ||
) | ||
.where(user_to_groups.c.uid == user_id) | ||
.group_by(workspaces_access_rights.c.workspace_id) | ||
).subquery("my_workspace_access_rights_subquery") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.