Merge branch 'bug/pretzel-bug-cleanup' into 'dev'

Bug/pretzel bug cleanup

See merge request crafty-controller/crafty-4!287
This commit is contained in:
Iain Powrie 2022-06-02 13:04:43 +00:00
commit 3c7c753baa
5 changed files with 65 additions and 15 deletions

View File

@ -18,6 +18,7 @@ from app.classes.controllers.roles_controller import RolesController
from app.classes.controllers.server_perms_controller import ServerPermsController
from app.classes.controllers.servers_controller import ServersController
from app.classes.models.server_permissions import EnumPermissionsServer
from app.classes.shared.main_models import DatabaseShortcuts
from app.classes.models.users import HelperUsers
from app.classes.models.roles import HelperRoles
from app.classes.models.management import HelpersManagement
@ -88,11 +89,24 @@ class Controller:
server_path = os.path.join(full_temp, "server")
os.mkdir(server_path)
if exec_user["superuser"]:
auth_servers = self.servers.get_all_defined_servers()
defined_servers = self.servers.list_defined_servers()
user_servers = []
for server in defined_servers:
if server not in user_servers:
user_servers.append(
DatabaseShortcuts.get_data_obj(server.server_object)
)
auth_servers = user_servers
else:
user_servers = self.servers.get_authorized_servers(
defined_servers = self.servers.get_authorized_servers(
int(exec_user["user_id"])
)
user_servers = []
for server in defined_servers:
if server not in user_servers:
user_servers.append(
DatabaseShortcuts.get_data_obj(server.server_object)
)
auth_servers = []
for server in user_servers:
if (

View File

@ -17,6 +17,8 @@ class DatabaseBuilder:
logger.info("Fresh Install Detected - Creating Default Settings")
Console.info("Fresh Install Detected - Creating Default Settings")
default_data = self.helper.find_default_password()
# Reset this value if the DB has been dumped
self.helper.set_setting("apikey_secret", "random")
username = default_data.get("username", "admin")
password = default_data.get("password", "crafty")

View File

@ -398,6 +398,10 @@ class AjaxHandler(BaseHandler):
self.controller.rename_backup_dir(
server_id, new_server_id, new_server["server_uuid"]
)
try:
self.tasks_manager.remove_all_server_tasks(server_id)
except:
logger.info("No active tasks found for server")
self.controller.remove_server(server_id, True)
self.redirect("/panel/dashboard")
@ -416,6 +420,10 @@ class AjaxHandler(BaseHandler):
self.controller.rename_backup_dir(
server_id, new_server_id, new_server["server_uuid"]
)
try:
self.tasks_manager.remove_all_server_tasks(server_id)
except:
logger.info("No active tasks found for server")
self.controller.remove_server(server_id, True)
self.redirect("/panel/dashboard")

View File

@ -1108,13 +1108,18 @@ class PanelHandler(BaseHandler):
)
return
if exec_user["superuser"]:
page_data[
"servers_all"
] = self.controller.servers.get_all_defined_servers()
defined_servers = self.controller.servers.list_defined_servers()
else:
page_data[
"servers_all"
] = self.controller.servers.get_authorized_servers(exec_user["user_id"])
defined_servers = self.controller.servers.get_authorized_servers(
exec_user["user_id"]
)
page_servers = []
for server in defined_servers:
if server not in page_servers:
page_servers.append(
DatabaseShortcuts.get_data_obj(server.server_object)
)
page_data["servers_all"] = page_servers
page_data[
"permissions_all"
] = self.controller.server_perms.list_defined_permissions()
@ -1127,13 +1132,18 @@ class PanelHandler(BaseHandler):
role_id = self.get_argument("id", None)
page_data["role"] = self.controller.roles.get_role_with_servers(role_id)
if exec_user["superuser"]:
page_data[
"servers_all"
] = self.controller.servers.get_all_defined_servers()
defined_servers = self.controller.servers.list_defined_servers()
else:
page_data[
"servers_all"
] = self.controller.servers.get_authorized_servers(exec_user["user_id"])
defined_servers = self.controller.servers.get_authorized_servers(
exec_user["user_id"]
)
page_servers = []
for server in defined_servers:
if server not in page_servers:
page_servers.append(
DatabaseShortcuts.get_data_obj(server.server_object)
)
page_data["servers_all"] = page_servers
page_data[
"permissions_all"
] = self.controller.server_perms.list_defined_permissions()

View File

@ -236,7 +236,7 @@ class ServerHandler(BaseHandler):
server_port = server_data.get("server_port")
server_type = server_data.get("type")
self.controller.servers.create_server(
new_server_id = self.controller.servers.create_server(
new_server_name,
new_server_uuid,
new_server_path,
@ -248,6 +248,22 @@ class ServerHandler(BaseHandler):
server_type,
server_port,
)
if not exec_user["superuser"]:
new_server_uuid = self.controller.servers.get_server_data_by_id(
new_server_id
).get("server_uuid")
role_id = self.controller.roles.add_role(
f"Creator of Server with uuid={new_server_uuid}"
)
self.controller.server_perms.add_role_server(
new_server_id, role_id, "11111111"
)
self.controller.users.add_role_to_user(
exec_user["user_id"], role_id
)
self.controller.crafty_perms.add_server_creation(
exec_user["user_id"]
)
self.controller.servers.init_all_servers()