2022-05-08 00:07:55 +03:00
|
|
|
from app.classes.models.server_permissions import PermissionsServers
|
|
|
|
from app.classes.web.base_api_handler import BaseApiHandler
|
|
|
|
|
|
|
|
|
|
|
|
class ApiRolesRoleServersHandler(BaseApiHandler):
|
|
|
|
def get(self, role_id: str):
|
|
|
|
auth_data = self.authenticate_user()
|
|
|
|
if not auth_data:
|
|
|
|
return
|
|
|
|
(
|
|
|
|
_,
|
|
|
|
_,
|
|
|
|
_,
|
|
|
|
superuser,
|
|
|
|
_,
|
|
|
|
) = auth_data
|
|
|
|
|
2022-05-10 02:08:49 +03:00
|
|
|
# GET /api/v2/roles/role/servers?ids=true
|
|
|
|
get_only_ids = self.get_query_argument("ids", None) == "true"
|
|
|
|
|
2022-05-08 00:07:55 +03:00
|
|
|
if not superuser:
|
|
|
|
return self.finish_json(400, {"status": "error", "error": "NOT_AUTHORIZED"})
|
|
|
|
|
|
|
|
self.finish_json(
|
|
|
|
200,
|
|
|
|
{
|
|
|
|
"status": "ok",
|
2022-05-10 02:08:49 +03:00
|
|
|
"data": PermissionsServers.get_server_ids_from_role(role_id)
|
|
|
|
if get_only_ids
|
|
|
|
else self.controller.roles.get_server_ids_and_perms_from_role(role_id),
|
2022-05-08 00:07:55 +03:00
|
|
|
},
|
|
|
|
)
|