diff options
| author | Frederick Muriuki Muriithi | 2026-08-27 10:33:18 -0500 |
|---|---|---|
| committer | Frederick Muriuki Muriithi | 2026-08-27 10:36:31 -0500 |
| commit | b128915f0e9258099f8881382dfb1307e8740d53 (patch) | |
| tree | d19556388b8f250336517e697d3e525fffdd32ae /gn_auth | |
| parent | 0e21fb99310dfdd776e9b974572ee231d8f8c75b (diff) | |
| download | gn-auth-b128915f0e9258099f8881382dfb1307e8740d53.tar.gz | |
Deprecate endpoint /auth/resources/<uuid:resource_id>/user/assign.
Diffstat (limited to 'gn_auth')
| -rw-r--r-- | gn_auth/auth/authorisation/resources/views.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/gn_auth/auth/authorisation/resources/views.py b/gn_auth/auth/authorisation/resources/views.py index f114476..01373ca 100644 --- a/gn_auth/auth/authorisation/resources/views.py +++ b/gn_auth/auth/authorisation/resources/views.py @@ -3,6 +3,7 @@ import time import json import logging import operator +import warnings import sqlite3 from uuid import UUID, uuid4 @@ -12,8 +13,13 @@ from functools import reduce from werkzeug.exceptions import BadRequest from authlib.jose import jwt from authlib.integrations.flask_oauth2.errors import _HTTPException -from flask import (make_response, request, jsonify, Response, - Blueprint, current_app as app) +from flask import (request, + jsonify, + url_for, + Response, + Blueprint, + make_response, + current_app as app) import gn_libs.privileges.resources from gn_auth.auth.requests import request_json @@ -317,6 +323,11 @@ def resource_users(resource_id: UUID): @require_oauth("profile group resource role") def assign_role_to_user(resource_id: UUID) -> Response: """Assign a role on the specified resource to a user.""" + warnings.warn( + f"The function `{__name__}.assign_role_to_user` is deprecated. Please " + " use `gn_auth.auth.authorisation.users.views.assign_user_role`", + DeprecationWarning, + stacklevel=2) with require_oauth.acquire("profile group resource role") as _token: try: form = request_json() @@ -339,7 +350,15 @@ def assign_role_to_user(resource_id: UUID) -> Response: except AssertionError as aserr: raise AuthorisationError(aserr.args[0]) from aserr - return jsonify(with_db_connection(__assign__)) + new_uri = url_for( + "oauth2.users.assign_user_role", + user_id=str(_token.user.user_id) + ).replace(str(_token.user.user_id), "<uuid:user_id>") + return jsonify({ + **with_db_connection(__assign__), + "DeprecationWarning": ( + "This endpoint is deprecated and will be removed. Please use " + f"the {new_uri} endpoint.")}) @resources.route("<uuid:resource_id>/user/unassign", methods=["POST"]) @require_oauth("profile group resource role") |
