chore: Update server configuration handling in services function to handle potential tries to delete a non ui service

This commit is contained in:
Théophile Diot 2024-05-29 15:20:41 +01:00
parent 713f7a1bf9
commit d560b6bb37
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06

View file

@ -945,9 +945,9 @@ def services():
if "SERVER_NAME" not in variables:
variables["SERVER_NAME"] = variables["OLD_SERVER_NAME"]
config = app.config["CONFIG"].get_config(methods=False, with_drafts=True)
config = app.config["CONFIG"].get_config(methods=True, with_drafts=True)
server_name = variables["SERVER_NAME"].split(" ")[0]
was_draft = config.get(f"{server_name}_IS_DRAFT", "no") == "yes"
was_draft = config.get(f"{server_name}_IS_DRAFT", {"value": "no"})["value"] == "yes"
operation = request.form["operation"]
# Get all variables starting with custom_config and delete them from variables
custom_configs = []
@ -992,7 +992,7 @@ def services():
if (
variable in variables
and variable != "SERVER_NAME"
and value == config.get(f"{server_name}_{variable}" if request.form["operation"] == "edit" else variable, None)
and value == config.get(f"{server_name}_{variable}" if request.form["operation"] == "edit" else variable, {"value": None})["value"]
):
del variables[variable]
@ -1023,6 +1023,9 @@ def services():
if error:
error_message(f"Error while deleting the service {request.form['SERVER_NAME']}")
if config.get(f"{request.form['SERVER_NAME'].split(' ')[0]}_SERVER_NAME", {"method": "scheduler"})["method"] != "ui":
return redirect_flash_error("The service cannot be deleted because it has not been created with the UI.", "services", True)
error = 0
curr_changes = app.config["DB"].check_changes()