diff options
Diffstat (limited to 'gn_auth/auth')
| -rw-r--r-- | gn_auth/auth/authorisation/resources/system/views.py | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/gn_auth/auth/authorisation/resources/system/views.py b/gn_auth/auth/authorisation/resources/system/views.py index d7a57a9..23ea6e9 100644 --- a/gn_auth/auth/authorisation/resources/system/views.py +++ b/gn_auth/auth/authorisation/resources/system/views.py @@ -1,7 +1,8 @@ """Views relating to `System` resource(s).""" import logging +import warnings from dataclasses import asdict -from flask import request, jsonify, Blueprint, current_app as app +from flask import request, jsonify, Blueprint, make_response, current_app as app from gn_libs import sqlite3 as authdb @@ -13,6 +14,8 @@ from .models import user_roles_on_system logger = logging.getLogger(__name__) system = Blueprint("system", __name__) +_SUCCESSOR = "/auth/resource/system/roles" + @system.route("/roles") def system_roles(): @@ -25,10 +28,21 @@ def system_roles(): "INNER JOIN role_privileges AS rp ON r.role_id=rp.role_id " "INNER JOIN privileges AS p ON rp.privilege_id=p.privilege_id " "WHERE r.role_name='public-view'") - return jsonify(tuple( - asdict(role) for role in db_rows_to_roles(cursor.fetchall()))) + roles_data = tuple( + asdict(role) for role in db_rows_to_roles(cursor.fetchall())) + else: + with require_oauth.acquire("profile group") as the_token: + roles_data = tuple( + asdict(role) for role in + user_roles_on_system(conn, the_token.user)) - with require_oauth.acquire("profile group") as the_token: - return jsonify(tuple( - asdict(role) for role in - user_roles_on_system(conn, the_token.user))) + resp = make_response(jsonify(roles_data)) + if "/resource/" not in request.path: + resp.headers["Deprecation"] = "true" + resp.headers["Link"] = f'<{_SUCCESSOR}>; rel="successor-version"' + warnings.warn( + ("The endpoint `/auth/system/roles` is deprecated -- please use " + "`/auth/resource/system/roles` instead."), + category=DeprecationWarning, + stacklevel=2) + return resp |
