aboutsummaryrefslogtreecommitdiff
path: root/gn_auth/auth/authorisation/resources/models.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-09-13 11:19:52 +0300
committerFrederick Muriuki Muriithi2023-09-26 03:44:29 +0300
commitdd759423739dafebe1d2ce7adb9fc1230ae0ee9d (patch)
tree56238b7d50f369a05bdeee4ca08b2e3d3f79c9b8 /gn_auth/auth/authorisation/resources/models.py
parent5f42365bb856a8272a27a127e9cd7e6e28971b42 (diff)
downloadgn-auth-dd759423739dafebe1d2ce7adb9fc1230ae0ee9d.tar.gz
Raise exception if no group for `resource_group`
Rather than using pymonad's Maybe monad and dealing with the complexity it introduces, raise an exception if there is no group found for the given resource.
Diffstat (limited to 'gn_auth/auth/authorisation/resources/models.py')
-rw-r--r--gn_auth/auth/authorisation/resources/models.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/gn_auth/auth/authorisation/resources/models.py b/gn_auth/auth/authorisation/resources/models.py
index 93a1aff..783bf8a 100644
--- a/gn_auth/auth/authorisation/resources/models.py
+++ b/gn_auth/auth/authorisation/resources/models.py
@@ -384,7 +384,7 @@ def save_resource(
raise AuthorisationError(
"You do not have the appropriate privileges to edit this resource.")
-def resource_group(conn: db.DbConnection, resource: Resource) -> Maybe[Group]:
+def resource_group(conn: db.DbConnection, resource: Resource) -> Group:
"""Return the group that owns the resource."""
with db.cursor(conn) as cursor:
cursor.execute(
@@ -394,9 +394,9 @@ def resource_group(conn: db.DbConnection, resource: Resource) -> Maybe[Group]:
(str(resource.resource_id),))
row = cursor.fetchone()
if row:
- return Just(Group(
+ return Group(
UUID(row["group_id"]),
row["group_name"],
- json.loads(row["group_metadata"])))
+ json.loads(row["group_metadata"]))
- return Nothing
+ raise MissingGroupError("Resource has no 'owning' group.")