Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add users API to get and delete users #223

Merged
merged 3 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion superset/initialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def init_views(self) -> None:
from superset.queries.saved_queries.api import SavedQueryRestApi
from superset.reports.api import ReportScheduleRestApi
from superset.reports.logs.api import ReportExecutionLogRestApi
from superset.security.api import SecurityRestApi
from superset.security.api import SecurityRestApi, UsersApi
from superset.views.access_requests import AccessRequestsModelView
from superset.views.alerts import AlertView, ReportView
from superset.views.annotations import (
Expand Down Expand Up @@ -215,6 +215,7 @@ def init_views(self) -> None:
appbuilder.add_api(ReportScheduleRestApi)
appbuilder.add_api(ReportExecutionLogRestApi)
appbuilder.add_api(SavedQueryRestApi)
appbuilder.add_api(UsersApi)
#
# Setup regular views
#
Expand Down
36 changes: 36 additions & 0 deletions superset/security/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@
from flask import request, Response
from flask_appbuilder import expose
from flask_appbuilder.api import BaseApi, safe
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_appbuilder.security.decorators import permission_name, protect
from flask_wtf.csrf import generate_csrf
from marshmallow import EXCLUDE, fields, post_load, Schema, ValidationError
from marshmallow_enum import EnumField

from superset import security_manager
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.embedded_dashboard.commands.exceptions import (
EmbeddedDashboardNotFoundError,
)
from superset.extensions import event_logger
from superset.security.guest_token import GuestTokenResourceType
from superset.views.base_api import BaseSupersetModelRestApi

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -160,3 +164,35 @@ def guest_token(self) -> Response:
return self.response_400(message=error.message)
except ValidationError as error:
return self.response_400(message=error.messages)


class UsersApi(BaseSupersetModelRestApi):
datamodel = SQLAInterface(security_manager.user_model)

resource_name = "users"
method_permission_name = MODEL_API_RW_METHOD_PERMISSION_MAP
include_route_methods = {RouteMethod.GET_LIST, RouteMethod.GET, RouteMethod.DELETE}
openapi_spec_tag = "Users"

list_columns = [
"id",
"first_name",
"last_name",
"username",
"active",
"email",
"last_login",
"login_count",
"fail_login_count",
"roles",
]
show_columns = list_columns
edit_columns = ["first_name", "last_name", "active", "email"]
add_columns = [
"first_name",
"last_name",
"username",
"password",
"active",
"email",
]