aboutsummaryrefslogtreecommitdiff
path: root/gn_auth/auth/authorisation/resources
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-09-27 09:46:58 +0300
committerFrederick Muriuki Muriithi2023-09-27 09:46:58 +0300
commit78eb3fd12e31d22b53c9cdf5b7b0299befd86be3 (patch)
tree0b92ac9e6a68a2daff8c8b699763bdae432b331e /gn_auth/auth/authorisation/resources
parent5d3dffd703822b019f39e7b898758085b88b4809 (diff)
downloadgn-auth-78eb3fd12e31d22b53c9cdf5b7b0299befd86be3.tar.gz
Bug: Fix issue with viewing resources of type "group".
Diffstat (limited to 'gn_auth/auth/authorisation/resources')
-rw-r--r--gn_auth/auth/authorisation/resources/models.py3
-rw-r--r--gn_auth/auth/authorisation/resources/views.py24
2 files changed, 12 insertions, 15 deletions
diff --git a/gn_auth/auth/authorisation/resources/models.py b/gn_auth/auth/authorisation/resources/models.py
index a16ca16..bca2ff9 100644
--- a/gn_auth/auth/authorisation/resources/models.py
+++ b/gn_auth/auth/authorisation/resources/models.py
@@ -182,7 +182,8 @@ def resource_data(conn, resource, offset: int = 0, limit: Optional[int] = None)
"mrna": mrna_resource_data,
"genotype": genotype_resource_data,
"phenotype": phenotype_resource_data,
- "system": lambda *args: tuple()
+ "system": lambda *args: tuple(),
+ "group": lambda *args: tuple()
}
with db.cursor(conn) as cursor:
return tuple(
diff --git a/gn_auth/auth/authorisation/resources/views.py b/gn_auth/auth/authorisation/resources/views.py
index f609303..de2fd6c 100644
--- a/gn_auth/auth/authorisation/resources/views.py
+++ b/gn_auth/auth/authorisation/resources/views.py
@@ -163,11 +163,9 @@ def resource_users(resource_id: uuid.UUID):
user_id = uuid.UUID(row["user_id"])
user = users_n_roles.get(user_id, {}).get(
"user", User(user_id, row["email"], row["name"]))
- role = GroupRole(
- uuid.UUID(row["group_role_id"]),
- resource_owner(conn, resource),
- Role(uuid.UUID(row["role_id"]), row["role_name"],
- bool(int(row["user_editable"])), tuple()))
+ role = Role(
+ uuid.UUID(row["role_id"]), row["role_name"],
+ bool(int(row["user_editable"])), tuple())
return {
**users_n_roles,
user_id: {
@@ -180,15 +178,13 @@ def resource_users(resource_id: uuid.UUID):
}
}
cursor.execute(
- "SELECT g.*, u.*, r.*, gr.group_role_id "
- "FROM groups AS g INNER JOIN "
- "group_users AS gu ON g.group_id=gu.group_id "
- "INNER JOIN users AS u ON gu.user_id=u.user_id "
- "INNER JOIN group_user_roles_on_resources AS guror "
- "ON u.user_id=guror.user_id INNER JOIN roles AS r "
- "ON guror.role_id=r.role_id "
- "INNER JOIN group_roles AS gr ON r.role_id=gr.role_id "
- "WHERE guror.resource_id=?",
+ "SELECT g.*, u.*, r.* "
+ "FROM groups AS g INNER JOIN group_users AS gu "
+ "ON g.group_id=gu.group_id INNER JOIN users AS u "
+ "ON gu.user_id=u.user_id INNER JOIN user_roles AS ur "
+ "ON u.user_id=ur.user_id INNER JOIN roles AS r "
+ "ON ur.role_id=r.role_id "
+ "WHERE ur.resource_id=?",
(str(resource_id),))
return reduce(__organise_users_n_roles__, cursor.fetchall(), {})
raise AuthorisationError(