Files
haproxy-wi/app/modules/common/common_classes.py
Aidaho 91802b3cd6 v8.1.3: Add dark theme support and update HAProxy management.
Introduce a dark theme for the web interface, enabling users to switch between themes seamlessly. Additionally, enhance HAProxy management by updating available versions and streamlining API routes for list management, ensuring smoother operations and integration.
2024-12-03 15:28:55 +03:00

51 lines
1.7 KiB
Python

from typing import Union
from flask import g
import app.modules.db.server as server_sql
import app.modules.roxywi.common as roxywi_common
from app.modules.roxywi.class_models import ServerRequest, GroupQuery, CredRequest, ChannelRequest, ListRequest
from app.middleware import get_user_params
class SupportClass:
def __init__(self, is_id=True):
self.is_id = is_id
@get_user_params()
def return_server_ip_or_id(self, server_id: Union[int, str]) -> Union[int, str]:
if isinstance(server_id, str):
try:
server = server_sql.get_server_by_ip(server_id)
except Exception as e:
raise e
else:
try:
server = server_sql.get_server(server_id)
except Exception as e:
raise e
try:
roxywi_common.is_user_has_access_to_group(g.user_params['user_id'], server.group_id)
except Exception as e:
roxywi_common.handler_exceptions_for_json_data(e, '')
if self.is_id:
return server.server_id
else:
return server.ip
@staticmethod
@get_user_params()
def return_group_id(body: Union[ServerRequest, CredRequest, GroupQuery, ChannelRequest, ListRequest]):
if body.group_id:
if g.user_params['role'] == 1:
return body.group_id
else:
try:
roxywi_common.is_user_has_access_to_group(g.user_params['user_id'], body.group_id)
return body.group_id
except Exception:
return int(g.user_params['group_id'])
else:
return int(g.user_params['group_id'])