Fix assorted black issues currently in dev

This commit is contained in:
Zedifus 2024-02-19 20:02:09 +00:00
parent 8e199dcd67
commit 0422a2ecdf
7 changed files with 173 additions and 151 deletions

View File

@ -172,9 +172,9 @@ class PermissionsServers:
RoleServers.server_id, RoleServers.permissions RoleServers.server_id, RoleServers.permissions
).where(RoleServers.role_id == role_id) ).where(RoleServers.role_id == role_id)
for role_server in role_servers: for role_server in role_servers:
permissions_dict[ permissions_dict[role_server.server_id_id] = (
role_server.server_id_id PermissionsServers.get_permissions(role_server.permissions)
] = PermissionsServers.get_permissions(role_server.permissions) )
return permissions_dict return permissions_dict
@staticmethod @staticmethod

View File

@ -345,15 +345,17 @@ class PanelHandler(BaseHandler):
self.controller.users.get_user_lang_by_id(exec_user["user_id"]) self.controller.users.get_user_lang_by_id(exec_user["user_id"])
), ),
"super_user": superuser, "super_user": superuser,
"api_key": { "api_key": (
"name": api_key.name, {
"created": api_key.created, "name": api_key.name,
"server_permissions": api_key.server_permissions, "created": api_key.created,
"crafty_permissions": api_key.crafty_permissions, "server_permissions": api_key.server_permissions,
"superuser": api_key.superuser, "crafty_permissions": api_key.crafty_permissions,
} "superuser": api_key.superuser,
if api_key is not None }
else None, if api_key is not None
else None
),
"superuser": superuser, "superuser": superuser,
} }
try: try:
@ -417,14 +419,14 @@ class PanelHandler(BaseHandler):
self.controller.first_login = False self.controller.first_login = False
if superuser: # TODO: Figure out a better solution if superuser: # TODO: Figure out a better solution
try: try:
page_data[ page_data["servers"] = (
"servers" self.controller.servers.get_all_servers_stats()
] = self.controller.servers.get_all_servers_stats() )
except IndexError: except IndexError:
self.controller.servers.stats.record_stats() self.controller.servers.stats.record_stats()
page_data[ page_data["servers"] = (
"servers" self.controller.servers.get_all_servers_stats()
] = self.controller.servers.get_all_servers_stats() )
else: else:
try: try:
user_auth = self.controller.servers.get_authorized_servers_stats( user_auth = self.controller.servers.get_authorized_servers_stats(
@ -454,19 +456,19 @@ class PanelHandler(BaseHandler):
for server_id in user_order[:]: for server_id in user_order[:]:
for server in un_used_servers[:]: for server in un_used_servers[:]:
if flag == 0: if flag == 0:
server["stats"][ server["stats"]["importing"] = (
"importing" self.controller.servers.get_import_status(
] = self.controller.servers.get_import_status( str(server["stats"]["server_id"]["server_id"])
str(server["stats"]["server_id"]["server_id"]) )
) )
server["stats"]["crashed"] = self.controller.servers.is_crashed( server["stats"]["crashed"] = self.controller.servers.is_crashed(
str(server["stats"]["server_id"]["server_id"]) str(server["stats"]["server_id"]["server_id"])
) )
try: try:
server["stats"][ server["stats"]["waiting_start"] = (
"waiting_start" self.controller.servers.get_waiting_start(
] = self.controller.servers.get_waiting_start( str(server["stats"]["server_id"]["server_id"])
str(server["stats"]["server_id"]["server_id"]) )
) )
except Exception as e: except Exception as e:
logger.error(f"Failed to get server waiting to start: {e}") logger.error(f"Failed to get server waiting to start: {e}")
@ -543,9 +545,9 @@ class PanelHandler(BaseHandler):
server_id server_id
) )
if not self.failed_server: if not self.failed_server:
page_data[ page_data["server_stats"] = (
"server_stats" self.controller.servers.get_server_stats_by_id(server_id)
] = self.controller.servers.get_server_stats_by_id(server_id) )
else: else:
server_temp_obj = self.controller.servers.get_server_data_by_id( server_temp_obj = self.controller.servers.get_server_data_by_id(
server_id server_id
@ -611,19 +613,19 @@ class PanelHandler(BaseHandler):
"Config": EnumPermissionsServer.CONFIG, "Config": EnumPermissionsServer.CONFIG,
"Players": EnumPermissionsServer.PLAYERS, "Players": EnumPermissionsServer.PLAYERS,
} }
page_data[ page_data["user_permissions"] = (
"user_permissions" self.controller.server_perms.get_user_id_permissions_list(
] = self.controller.server_perms.get_user_id_permissions_list( exec_user["user_id"], server_id
exec_user["user_id"], server_id )
) )
if not self.failed_server: if not self.failed_server:
page_data["server_stats"][ page_data["server_stats"]["crashed"] = (
"crashed" self.controller.servers.is_crashed(server_id)
] = self.controller.servers.is_crashed(server_id) )
if not self.failed_server: if not self.failed_server:
page_data["server_stats"][ page_data["server_stats"]["server_type"] = (
"server_type" self.controller.servers.get_server_type_by_id(server_id)
] = self.controller.servers.get_server_type_by_id(server_id) )
if not subpage: if not subpage:
for spage, perm in SUBPAGE_PERMS.items(): for spage, perm in SUBPAGE_PERMS.items():
@ -674,23 +676,23 @@ class PanelHandler(BaseHandler):
page_data["java_versions"] = page_java page_data["java_versions"] = page_java
if subpage == "backup": if subpage == "backup":
server_info = self.controller.servers.get_server_data_by_id(server_id) server_info = self.controller.servers.get_server_data_by_id(server_id)
page_data[ page_data["backup_config"] = (
"backup_config" self.controller.management.get_backup_config(server_id)
] = self.controller.management.get_backup_config(server_id) )
exclusions = [] exclusions = []
page_data[ page_data["exclusions"] = (
"exclusions" self.controller.management.get_excluded_backup_dirs(server_id)
] = self.controller.management.get_excluded_backup_dirs(server_id) )
page_data[ page_data["backing_up"] = (
"backing_up" self.controller.servers.get_server_instance_by_id(
] = self.controller.servers.get_server_instance_by_id( server_id
server_id ).is_backingup
).is_backingup )
page_data[ page_data["backup_stats"] = (
"backup_stats" self.controller.servers.get_server_instance_by_id(
] = self.controller.servers.get_server_instance_by_id( server_id
server_id ).send_backup_status()
).send_backup_status() )
# makes it so relative path is the only thing shown # makes it so relative path is the only thing shown
for file in page_data["exclusions"]: for file in page_data["exclusions"]:
if Helpers.is_os_windows(): if Helpers.is_os_windows():
@ -723,10 +725,10 @@ class PanelHandler(BaseHandler):
server_id, hours=(days * 24) server_id, hours=(days * 24)
) )
if subpage == "webhooks": if subpage == "webhooks":
page_data[ page_data["webhooks"] = (
"webhooks" self.controller.management.get_webhooks_by_server(
] = self.controller.management.get_webhooks_by_server( server_id, model=True
server_id, model=True )
) )
page_data["triggers"] = WebhookFactory.get_monitored_events() page_data["triggers"] = WebhookFactory.get_monitored_events()
@ -758,9 +760,9 @@ class PanelHandler(BaseHandler):
if not superuser: if not superuser:
self.redirect("/panel/error?error=Unauthorized access") self.redirect("/panel/error?error=Unauthorized access")
page_data["banned_players_html"] = get_banned_players_html() page_data["banned_players_html"] = get_banned_players_html()
page_data[ page_data["banned_players"] = (
"banned_players" self.controller.servers.get_banned_players(server_id)
] = self.controller.servers.get_banned_players(server_id) )
server_instance = self.controller.servers.get_server_instance_by_id( server_instance = self.controller.servers.get_server_instance_by_id(
server_id server_id
) )
@ -925,9 +927,9 @@ class PanelHandler(BaseHandler):
if item not in page_data["backgrounds"]: if item not in page_data["backgrounds"]:
page_data["backgrounds"].append(item) page_data["backgrounds"].append(item)
page_data["background"] = self.controller.cached_login page_data["background"] = self.controller.cached_login
page_data[ page_data["login_opacity"] = (
"login_opacity" self.controller.management.get_login_opacity()
] = self.controller.management.get_login_opacity() )
page_data["active_link"] = "custom_login" page_data["active_link"] = "custom_login"
template = "panel/custom_login.html" template = "panel/custom_login.html"
@ -959,13 +961,11 @@ class PanelHandler(BaseHandler):
page_data["servers"] = [] page_data["servers"] = []
page_data["servers_all"] = self.controller.servers.get_all_defined_servers() page_data["servers_all"] = self.controller.servers.get_all_defined_servers()
page_data["role-servers"] = [] page_data["role-servers"] = []
page_data[ page_data["permissions_all"] = (
"permissions_all" self.controller.crafty_perms.list_defined_crafty_permissions()
] = self.controller.crafty_perms.list_defined_crafty_permissions() )
page_data["permissions_list"] = set() page_data["permissions_list"] = set()
page_data[ page_data["quantity_server"] = (
"quantity_server"
] = (
self.controller.crafty_perms.list_all_crafty_permissions_quantity_limits() # pylint: disable=line-too-long self.controller.crafty_perms.list_all_crafty_permissions_quantity_limits() # pylint: disable=line-too-long
) )
page_data["languages"] = [] page_data["languages"] = []
@ -1007,10 +1007,10 @@ class PanelHandler(BaseHandler):
page_data["server_data"] = self.controller.servers.get_server_data_by_id( page_data["server_data"] = self.controller.servers.get_server_data_by_id(
server_id server_id
) )
page_data[ page_data["user_permissions"] = (
"user_permissions" self.controller.server_perms.get_user_id_permissions_list(
] = self.controller.server_perms.get_user_id_permissions_list( exec_user["user_id"], server_id
exec_user["user_id"], server_id )
) )
page_data["permissions"] = { page_data["permissions"] = {
"Commands": EnumPermissionsServer.COMMANDS, "Commands": EnumPermissionsServer.COMMANDS,
@ -1025,9 +1025,9 @@ class PanelHandler(BaseHandler):
page_data["server_stats"] = self.controller.servers.get_server_stats_by_id( page_data["server_stats"] = self.controller.servers.get_server_stats_by_id(
server_id server_id
) )
page_data["server_stats"][ page_data["server_stats"]["server_type"] = (
"server_type" self.controller.servers.get_server_type_by_id(server_id)
] = self.controller.servers.get_server_type_by_id(server_id) )
page_data["new_webhook"] = True page_data["new_webhook"] = True
page_data["webhook"] = {} page_data["webhook"] = {}
page_data["webhook"]["webhook_type"] = "Custom" page_data["webhook"]["webhook_type"] = "Custom"
@ -1061,10 +1061,10 @@ class PanelHandler(BaseHandler):
page_data["server_data"] = self.controller.servers.get_server_data_by_id( page_data["server_data"] = self.controller.servers.get_server_data_by_id(
server_id server_id
) )
page_data[ page_data["user_permissions"] = (
"user_permissions" self.controller.server_perms.get_user_id_permissions_list(
] = self.controller.server_perms.get_user_id_permissions_list( exec_user["user_id"], server_id
exec_user["user_id"], server_id )
) )
page_data["permissions"] = { page_data["permissions"] = {
"Commands": EnumPermissionsServer.COMMANDS, "Commands": EnumPermissionsServer.COMMANDS,
@ -1079,9 +1079,9 @@ class PanelHandler(BaseHandler):
page_data["server_stats"] = self.controller.servers.get_server_stats_by_id( page_data["server_stats"] = self.controller.servers.get_server_stats_by_id(
server_id server_id
) )
page_data["server_stats"][ page_data["server_stats"]["server_type"] = (
"server_type" self.controller.servers.get_server_type_by_id(server_id)
] = self.controller.servers.get_server_type_by_id(server_id) )
page_data["new_webhook"] = False page_data["new_webhook"] = False
page_data["webhook"] = self.controller.management.get_webhook_by_id( page_data["webhook"] = self.controller.management.get_webhook_by_id(
webhook_id webhook_id
@ -1121,10 +1121,10 @@ class PanelHandler(BaseHandler):
"Config": EnumPermissionsServer.CONFIG, "Config": EnumPermissionsServer.CONFIG,
"Players": EnumPermissionsServer.PLAYERS, "Players": EnumPermissionsServer.PLAYERS,
} }
page_data[ page_data["user_permissions"] = (
"user_permissions" self.controller.server_perms.get_user_id_permissions_list(
] = self.controller.server_perms.get_user_id_permissions_list( exec_user["user_id"], server_id
exec_user["user_id"], server_id )
) )
page_data["server_data"] = self.controller.servers.get_server_data_by_id( page_data["server_data"] = self.controller.servers.get_server_data_by_id(
server_id server_id
@ -1132,9 +1132,9 @@ class PanelHandler(BaseHandler):
page_data["server_stats"] = self.controller.servers.get_server_stats_by_id( page_data["server_stats"] = self.controller.servers.get_server_stats_by_id(
server_id server_id
) )
page_data["server_stats"][ page_data["server_stats"]["server_type"] = (
"server_type" self.controller.servers.get_server_type_by_id(server_id)
] = self.controller.servers.get_server_type_by_id(server_id) )
page_data["new_schedule"] = True page_data["new_schedule"] = True
page_data["schedule"] = {} page_data["schedule"] = {}
page_data["schedule"]["children"] = [] page_data["schedule"]["children"] = []
@ -1189,10 +1189,10 @@ class PanelHandler(BaseHandler):
"Config": EnumPermissionsServer.CONFIG, "Config": EnumPermissionsServer.CONFIG,
"Players": EnumPermissionsServer.PLAYERS, "Players": EnumPermissionsServer.PLAYERS,
} }
page_data[ page_data["user_permissions"] = (
"user_permissions" self.controller.server_perms.get_user_id_permissions_list(
] = self.controller.server_perms.get_user_id_permissions_list( exec_user["user_id"], server_id
exec_user["user_id"], server_id )
) )
page_data["server_data"] = self.controller.servers.get_server_data_by_id( page_data["server_data"] = self.controller.servers.get_server_data_by_id(
server_id server_id
@ -1200,9 +1200,9 @@ class PanelHandler(BaseHandler):
page_data["server_stats"] = self.controller.servers.get_server_stats_by_id( page_data["server_stats"] = self.controller.servers.get_server_stats_by_id(
server_id server_id
) )
page_data["server_stats"][ page_data["server_stats"]["server_type"] = (
"server_type" self.controller.servers.get_server_type_by_id(server_id)
] = self.controller.servers.get_server_type_by_id(server_id) )
page_data["new_schedule"] = False page_data["new_schedule"] = False
page_data["schedule"] = {} page_data["schedule"] = {}
page_data["schedule"]["server_id"] = server_id page_data["schedule"]["server_id"] = server_id
@ -1212,9 +1212,9 @@ class PanelHandler(BaseHandler):
page_data["schedule"]["name"] = schedule.name page_data["schedule"]["name"] = schedule.name
else: else:
page_data["schedule"]["name"] = "" page_data["schedule"]["name"] = ""
page_data["schedule"][ page_data["schedule"]["children"] = (
"children" self.controller.management.get_child_schedules(sch_id)
] = self.controller.management.get_child_schedules(sch_id) )
# We check here to see if the command is any of the default ones. # We check here to see if the command is any of the default ones.
# We do not want a user changing to a custom command # We do not want a user changing to a custom command
# and seeing our command there. # and seeing our command there.
@ -1280,16 +1280,16 @@ class PanelHandler(BaseHandler):
} }
if exec_user["superuser"]: if exec_user["superuser"]:
page_data["users"] = self.controller.users.get_all_users() page_data["users"] = self.controller.users.get_all_users()
page_data[ page_data["permissions_all"] = (
"permissions_all" self.controller.crafty_perms.list_defined_crafty_permissions()
] = self.controller.crafty_perms.list_defined_crafty_permissions() )
page_data[ page_data["permissions_list"] = (
"permissions_list" self.controller.crafty_perms.get_crafty_permissions_list(user_id)
] = self.controller.crafty_perms.get_crafty_permissions_list(user_id) )
page_data[ page_data["quantity_server"] = (
"quantity_server" self.controller.crafty_perms.list_crafty_permissions_quantity_limits(
] = self.controller.crafty_perms.list_crafty_permissions_quantity_limits( user_id
user_id )
) )
page_data["languages"] = [] page_data["languages"] = []
page_data["languages"].append( page_data["languages"].append(
@ -1349,12 +1349,12 @@ class PanelHandler(BaseHandler):
page_data["user"] = self.controller.users.get_user_by_id(user_id) page_data["user"] = self.controller.users.get_user_by_id(user_id)
page_data["api_keys"] = self.controller.users.get_user_api_keys(user_id) page_data["api_keys"] = self.controller.users.get_user_api_keys(user_id)
# self.controller.crafty_perms.list_defined_crafty_permissions() # self.controller.crafty_perms.list_defined_crafty_permissions()
page_data[ page_data["server_permissions_all"] = (
"server_permissions_all" self.controller.server_perms.list_defined_permissions()
] = self.controller.server_perms.list_defined_permissions() )
page_data[ page_data["crafty_permissions_all"] = (
"crafty_permissions_all" self.controller.crafty_perms.list_defined_crafty_permissions()
] = self.controller.crafty_perms.list_defined_crafty_permissions() )
if user_id is None: if user_id is None:
self.redirect("/panel/error?error=Invalid User ID") self.redirect("/panel/error?error=Invalid User ID")
@ -1442,9 +1442,9 @@ class PanelHandler(BaseHandler):
DatabaseShortcuts.get_data_obj(server.server_object) DatabaseShortcuts.get_data_obj(server.server_object)
) )
page_data["servers_all"] = page_servers page_data["servers_all"] = page_servers
page_data[ page_data["permissions_all"] = (
"permissions_all" self.controller.server_perms.list_defined_permissions()
] = self.controller.server_perms.list_defined_permissions() )
page_data["permissions_dict"] = {} page_data["permissions_dict"] = {}
template = "panel/panel_edit_role.html" template = "panel/panel_edit_role.html"
@ -1467,12 +1467,12 @@ class PanelHandler(BaseHandler):
DatabaseShortcuts.get_data_obj(server.server_object) DatabaseShortcuts.get_data_obj(server.server_object)
) )
page_data["servers_all"] = page_servers page_data["servers_all"] = page_servers
page_data[ page_data["permissions_all"] = (
"permissions_all" self.controller.server_perms.list_defined_permissions()
] = self.controller.server_perms.list_defined_permissions() )
page_data[ page_data["permissions_dict"] = (
"permissions_dict" self.controller.server_perms.get_role_permissions_dict(role_id)
] = self.controller.server_perms.get_role_permissions_dict(role_id) )
page_data["user-roles"] = user_roles page_data["user-roles"] = user_roles
page_data["users"] = self.controller.users.get_all_users() page_data["users"] = self.controller.users.get_all_users()

View File

@ -80,9 +80,13 @@ class ApiCraftyConfigIndexHandler(BaseApiHandler):
200, 200,
{ {
"status": "ok", "status": "ok",
"data": self.controller.roles.get_all_role_ids() "data": (
if get_only_ids self.controller.roles.get_all_role_ids()
else [model_to_dict(r) for r in self.controller.roles.get_all_roles()], if get_only_ids
else [
model_to_dict(r) for r in self.controller.roles.get_all_roles()
]
),
}, },
) )
@ -158,9 +162,13 @@ class ApiCraftyCustomizeIndexHandler(BaseApiHandler):
200, 200,
{ {
"status": "ok", "status": "ok",
"data": self.controller.roles.get_all_role_ids() "data": (
if get_only_ids self.controller.roles.get_all_role_ids()
else [model_to_dict(r) for r in self.controller.roles.get_all_roles()], if get_only_ids
else [
model_to_dict(r) for r in self.controller.roles.get_all_roles()
]
),
}, },
) )

View File

@ -36,9 +36,13 @@ class ApiCraftyConfigServerDirHandler(BaseApiHandler):
200, 200,
{ {
"status": "ok", "status": "ok",
"data": self.controller.roles.get_all_role_ids() "data": (
if get_only_ids self.controller.roles.get_all_role_ids()
else [model_to_dict(r) for r in self.controller.roles.get_all_roles()], if get_only_ids
else [
model_to_dict(r) for r in self.controller.roles.get_all_roles()
]
),
}, },
) )

View File

@ -87,9 +87,13 @@ class ApiRolesIndexHandler(BaseApiHandler):
200, 200,
{ {
"status": "ok", "status": "ok",
"data": self.controller.roles.get_all_role_ids() "data": (
if get_only_ids self.controller.roles.get_all_role_ids()
else [model_to_dict(r) for r in self.controller.roles.get_all_roles()], if get_only_ids
else [
model_to_dict(r) for r in self.controller.roles.get_all_roles()
]
),
}, },
) )

View File

@ -25,8 +25,12 @@ class ApiRolesRoleServersHandler(BaseApiHandler):
200, 200,
{ {
"status": "ok", "status": "ok",
"data": PermissionsServers.get_server_ids_from_role(role_id) "data": (
if get_only_ids PermissionsServers.get_server_ids_from_role(role_id)
else self.controller.roles.get_server_ids_and_perms_from_role(role_id), if get_only_ids
else self.controller.roles.get_server_ids_and_perms_from_role(
role_id
)
),
}, },
) )

View File

@ -118,15 +118,17 @@ class ServerHandler(BaseHandler):
"lang_page": Helpers.get_lang_page( "lang_page": Helpers.get_lang_page(
self.controller.users.get_user_lang_by_id(exec_user["user_id"]) self.controller.users.get_user_lang_by_id(exec_user["user_id"])
), ),
"api_key": { "api_key": (
"name": api_key.name, {
"created": api_key.created, "name": api_key.name,
"server_permissions": api_key.server_permissions, "created": api_key.created,
"crafty_permissions": api_key.crafty_permissions, "server_permissions": api_key.server_permissions,
"superuser": api_key.superuser, "crafty_permissions": api_key.crafty_permissions,
} "superuser": api_key.superuser,
if api_key is not None }
else None, if api_key is not None
else None
),
"superuser": superuser, "superuser": superuser,
} }