mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-20 10:15:29 +01:00
bf59e2de6c
* Add basic role routes * Add API v2 404 handler * Add API v2 home handler pointing to the wiki * Add tons more todos * Add get_*_columns and get_*_column functions for many db models * Modify and add tons of model and controller functions
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
from app.classes.web.base_api_handler import BaseApiHandler
|
|
|
|
|
|
class ApiRolesRoleUsersHandler(BaseApiHandler):
|
|
def get(self, role_id: str):
|
|
auth_data = self.authenticate_user()
|
|
if not auth_data:
|
|
return
|
|
(
|
|
_,
|
|
_,
|
|
_,
|
|
superuser,
|
|
_,
|
|
) = auth_data
|
|
|
|
if not superuser:
|
|
return self.finish_json(400, {"status": "error", "error": "NOT_AUTHORIZED"})
|
|
|
|
all_user_ids = self.controller.users.get_all_user_ids()
|
|
|
|
user_roles = {}
|
|
for user_id in all_user_ids:
|
|
user_roles_list = self.controller.users.get_user_roles_names(user_id)
|
|
user_roles[user_id] = user_roles_list
|
|
|
|
role = self.controller.roles.get_role(role_id)
|
|
|
|
user_ids = []
|
|
|
|
for user_id in all_user_ids:
|
|
for role_user in user_roles[user_id]:
|
|
if role_user == role["role_name"]:
|
|
user_ids.append(user_id)
|
|
|
|
self.finish_json(200, {"status": "ok", "data": user_ids})
|