about summary refs log tree commit diff
path: root/gn3/auth
diff options
context:
space:
mode:
Diffstat (limited to 'gn3/auth')
-rw-r--r--gn3/auth/authorisation/groups.py11
-rw-r--r--gn3/auth/authorisation/views.py12
2 files changed, 22 insertions, 1 deletions
diff --git a/gn3/auth/authorisation/groups.py b/gn3/auth/authorisation/groups.py
index bbabd44..3367b57 100644
--- a/gn3/auth/authorisation/groups.py
+++ b/gn3/auth/authorisation/groups.py
@@ -145,3 +145,14 @@ def is_group_leader(cursor: db.DbCursor, user: User, group: Group):
     role_names = tuple(row[0] for row in cursor.fetchall())
 
     return "group-leader" in role_names
+
+def all_groups(conn: db.DbConnection) -> Maybe[Sequence[Group]]:
+    """Retrieve all existing groups"""
+    with db.cursor(conn) as cursor:
+        cursor.execute("SELECT * FROM groups")
+        res = cursor.fetchall()
+        if res:
+            return Just(tuple(
+                Group(row["group_id"], row["group_name"]) for row in res))
+
+    return Nothing
diff --git a/gn3/auth/authorisation/views.py b/gn3/auth/authorisation/views.py
index 9f0b68b..d2f7d47 100644
--- a/gn3/auth/authorisation/views.py
+++ b/gn3/auth/authorisation/views.py
@@ -8,8 +8,8 @@ from flask import request, jsonify, current_app
 from gn3.auth import db
 from gn3.auth.blueprint import oauth2
 
-from .groups import user_group
 from .errors import UserRegistrationError
+from .groups import user_group, all_groups
 from .roles import assign_default_roles, user_roles as _user_roles
 
 from ..authentication.oauth2.resource_server import require_oauth
@@ -115,3 +115,13 @@ def register_user():
 
     raise Exception(
         "unknown_error", "The system experienced an unexpected error.")
+
+@oauth2.route("/groups", methods=["GET"])
+@require_oauth("profile")
+def groups():
+    """Return the list of groups that exist."""
+    with db.connection(current_app.config["AUTH_DB"]) as conn:
+        the_groups = all_groups(conn)
+        print(f"The groups: {the_groups}")
+
+    return jsonify([])