aboutsummaryrefslogtreecommitdiff
path: root/gn_auth/auth/authorisation/privileges/views.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-06-10 15:22:20 -0500
committerFrederick Muriuki Muriithi2024-06-10 16:45:12 -0500
commitfa7452e4f08352526257d1f0dc5181302a55d3e2 (patch)
tree2a62f5f94d0da4808b469becff71e9ebb62784a9 /gn_auth/auth/authorisation/privileges/views.py
parent99023088e70c6db684785ab6a1a8b11331058efd (diff)
downloadgn-auth-fa7452e4f08352526257d1f0dc5181302a55d3e2.tar.gz
Provide some endpoints for privileges.
Diffstat (limited to 'gn_auth/auth/authorisation/privileges/views.py')
-rw-r--r--gn_auth/auth/authorisation/privileges/views.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/privileges/views.py b/gn_auth/auth/authorisation/privileges/views.py
new file mode 100644
index 0000000..d50e5cb
--- /dev/null
+++ b/gn_auth/auth/authorisation/privileges/views.py
@@ -0,0 +1,32 @@
+"""Routes for privileges."""
+from dataclasses import asdict
+
+from werkzeug.exceptions import NotFound
+from flask import jsonify, Blueprint, current_app as app
+
+from gn_auth.auth.db import sqlite3 as db
+
+from .models import all_privileges, privilege_by_id
+
+privileges = Blueprint("privileges", __name__)
+
+@privileges.route("/", methods=["GET"])
+@privileges.route("/list", methods=["GET"])
+def list_privileges():
+ """List all the available privileges."""
+ with db.connection(app.config["AUTH_DB"]) as conn:
+ _privileges = all_privileges(conn)
+
+ return jsonify(_privileges if bool(_privileges) else []), 200
+
+@privileges.route("/<privilege_id>/", methods=["GET"])
+@privileges.route("/<privilege_id>/view", methods=["GET"])
+def view_privilege(privilege_id: str):
+ """View details of a single privilege"""
+ with db.connection(app.config["AUTH_DB"]) as conn:
+ _privilege = privilege_by_id(conn, privilege_id)
+
+ if bool(_privilege):
+ return jsonify(_privilege)
+
+ raise NotFound(f"No privilege exists with ID '{privilege_id}'")