Fixing get_authorized_server

This commit is contained in:
Silversthorn 2022-05-26 23:19:59 +02:00
parent 6fae395185
commit 3b4253de9b
4 changed files with 27 additions and 16 deletions

View File

@ -10,6 +10,7 @@ from typing_extensions import Self
from app.classes.controllers.roles_controller import RolesController
from app.classes.shared.singleton import Singleton
from app.classes.shared.server import Server
from app.classes.shared.console import Console
from app.classes.shared.helpers import Helpers
@ -25,7 +26,6 @@ from app.classes.models.server_permissions import (
PermissionsServers,
EnumPermissionsServer,
)
from app.classes.shared.singleton import Singleton
logger = logging.getLogger(__name__)
@ -244,7 +244,12 @@ class ServersController(metaclass=Singleton):
user.role_id
)
for role in role_servers:
server_data.append(HelperServers.get_server_data_by_id(role.server_id))
# server_data.append(HelperServers.get_server_data_by_id(role.server_id))
server_data.append(
ServersController().get_server_instance_by_id(
role.server_id.server_id
)
)
return server_data
@ -294,7 +299,7 @@ class ServersController(metaclass=Singleton):
srv: Server = server
latest = srv.stats_helper.get_latest_server_stats()
key_permissions = PermissionsServers.get_api_key_permissions_list(
api_key, server.get("server_id")
api_key, server.server_id
)
if EnumPermissionsServer.COMMANDS in key_permissions:
user_command_permission = True
@ -302,7 +307,7 @@ class ServersController(metaclass=Singleton):
user_command_permission = False
server_data.append(
{
"server_data": server,
"server_data": DatabaseShortcuts.get_data_obj(server.server_object),
"stats": latest,
"user_command_permission": user_command_permission,
}
@ -319,7 +324,7 @@ class ServersController(metaclass=Singleton):
latest = srv.stats_helper.get_latest_server_stats()
# TODO
user_permissions = PermissionsServers.get_user_id_permissions_list(
user_id, server.get("server_id")
user_id, server.server_id
)
if EnumPermissionsServer.COMMANDS in user_permissions:
user_command_permission = True
@ -327,7 +332,7 @@ class ServersController(metaclass=Singleton):
user_command_permission = False
server_data.append(
{
"server_data": server,
"server_data": DatabaseShortcuts.get_data_obj(server.server_object),
"stats": latest,
"user_command_permission": user_command_permission,
}

View File

@ -3,16 +3,13 @@ import logging
import datetime
import typing as t
from playhouse.shortcuts import model_to_dict
import typing as t
from peewee import DoesNotExist
from playhouse.shortcuts import model_to_dict
from app.classes.models.servers import Servers, HelperServers
from app.classes.shared.helpers import Helpers
from app.classes.shared.main_models import DatabaseShortcuts
from app.classes.shared.migration import MigrationManager
try:
@ -193,7 +190,7 @@ class HelperServerStats:
.get(self.database)
)
try:
return model_to_dict(latest)
return DatabaseShortcuts.get_data_obj(latest)
except IndexError:
return {}
@ -205,7 +202,7 @@ class HelperServerStats:
.limit(1)
.first(self.database)
)
return model_to_dict(stats)
return DatabaseShortcuts.get_data_obj(stats)
def server_id_exists(self):
# self.select_database(self.server_id)

View File

@ -58,3 +58,7 @@ class DatabaseShortcuts:
def return_db_rows(model):
data = [model_to_dict(row) for row in model]
return data
@staticmethod
def get_data_obj(obj):
return model_to_dict(obj)

View File

@ -22,6 +22,7 @@ from app.classes.models.server_permissions import EnumPermissionsServer
from app.classes.models.crafty_permissions import EnumPermissionsCrafty
from app.classes.models.management import HelpersManagement
from app.classes.shared.helpers import Helpers
from app.classes.shared.main_models import DatabaseShortcuts
from app.classes.web.base_handler import BaseHandler
logger = logging.getLogger(__name__)
@ -254,15 +255,19 @@ class PanelHandler(BaseHandler):
for server_id in user_order[:]:
for server in defined_servers[:]:
if str(server["server_id"]) == str(server_id):
page_servers.append(server)
if str(server.server_id) == str(server_id):
page_servers.append(
DatabaseShortcuts.get_data_obj(server.server_object)
)
user_order.remove(server_id)
defined_servers.remove(server)
for server in defined_servers:
server_ids.append(str(server["server_id"]))
server_ids.append(str(server.server_id))
if server not in page_servers:
page_servers.append(server)
page_servers.append(
DatabaseShortcuts.get_data_obj(server.server_object)
)
for server_id in user_order[:]:
# remove IDs in list that user no longer has access to
if str(server_id) not in server_ids: