chore: get embedded user with roles and permissions (#19813)

* feat: get user roles endpoint

* add tests

* fix test

* get user with permission and roles with full user

* frontend

* type juggling

* the hash slinging slasher

* user reducer and action

* make it happy

* result

* lint

Co-authored-by: Lily Kuang <lily@preset.io>
This commit is contained in:
David Aaron Suddjian
2022-05-03 12:58:06 -07:00
committed by GitHub
parent 7657e42cff
commit 7f8279b4b3
12 changed files with 143 additions and 20 deletions

View File

@@ -18,6 +18,8 @@ from flask import g, Response
from flask_appbuilder.api import BaseApi, expose, safe
from flask_jwt_extended.exceptions import NoAuthorizationError
from superset.views.utils import bootstrap_user_data
from .schemas import UserResponseSchema
user_response_schema = UserResponseSchema()
@@ -59,3 +61,33 @@ class CurrentUserRestApi(BaseApi):
return self.response_401()
return self.response(200, result=user_response_schema.dump(g.user))
@expose("/roles/", methods=["GET"])
@safe
def get_my_roles(self) -> Response:
"""Get the user roles corresponding to the agent making the request
---
get:
description: >-
Returns the user roles corresponding to the agent making the request,
or returns a 401 error if the user is unauthenticated.
responses:
200:
description: The current user
content:
application/json:
schema:
type: object
properties:
result:
$ref: '#/components/schemas/UserResponseSchema'
401:
$ref: '#/components/responses/401'
"""
try:
if g.user is None or g.user.is_anonymous:
return self.response_401()
except NoAuthorizationError:
return self.response_401()
user = bootstrap_user_data(g.user, include_perms=True)
return self.response(200, result=user)