From 7bdc46057bd593d205fd2ba074ec5bb74899fa2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Tue, 13 Dec 2022 15:45:42 +0100 Subject: [PATCH] Change how the edit works in the config (UI) --- src/ui/src/Config.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ui/src/Config.py b/src/ui/src/Config.py index ea9910b61..38164982e 100644 --- a/src/ui/src/Config.py +++ b/src/ui/src/Config.py @@ -280,7 +280,7 @@ class Config: self.get_config(methods=False), self.get_services(methods=False) ) - def new_service(self, variables: dict) -> Tuple[str, int]: + def new_service(self, variables: dict, edit: bool = False) -> Tuple[str, int]: """Creates a new service from the given variables Parameters @@ -299,11 +299,14 @@ class Config: raise this if the service already exists """ services = self.get_services(methods=False) - for service in services: + for i, service in enumerate(services): if service["SERVER_NAME"] == variables["SERVER_NAME"] or service[ "SERVER_NAME" ] in variables["SERVER_NAME"].split(" "): - return f"Service {service['SERVER_NAME']} already exists.", 1 + if edit is False: + return f"Service {service['SERVER_NAME']} already exists.", 1 + + del services[i] services.append(variables) self.__gen_conf(self.get_config(methods=False), services) @@ -329,7 +332,11 @@ class Config: if error: return message, error - message, error = self.new_service(variables) + message, error = self.new_service(variables, edit=True) + + if error: + return message, error + return f"Configuration for {old_server_name} has been edited.", error def edit_global_conf(self, variables: dict) -> str: