diff --git a/api/tacticalrmm/core/utils.py b/api/tacticalrmm/core/utils.py index 003af6c449..5f96cb93e2 100644 --- a/api/tacticalrmm/core/utils.py +++ b/api/tacticalrmm/core/utils.py @@ -7,7 +7,7 @@ from base64 import b64encode from contextlib import suppress from requests.utils import requote_uri -from typing import TYPE_CHECKING, Any, Dict, List, Optional, cast, Tuple +from typing import TYPE_CHECKING, List, Optional, cast, Tuple import requests import websockets @@ -219,14 +219,17 @@ def make_alpha_numeric(s: str): def find_and_replace_db_values_str(*, text: str, instance): import re - from tacticalrmm.utils import RE_DB_VALUE, get_db_value + if not instance: + return text + + return_string = text + for string, model, prop in re.findall(RE_DB_VALUE, text): value = get_db_value(string=f"{model}.{prop}", instance=instance) - return text.replace(string, str(value)) - else: - return text + return_string = return_string.replace(string, str(value)) + return return_string def _run_url_rest_action(*, url: str, method, body: str, headers: str, instance=None): diff --git a/api/tacticalrmm/tacticalrmm/utils.py b/api/tacticalrmm/tacticalrmm/utils.py index 9c202709ba..6491c8ef59 100644 --- a/api/tacticalrmm/tacticalrmm/utils.py +++ b/api/tacticalrmm/tacticalrmm/utils.py @@ -296,7 +296,7 @@ def get_latest_trmm_ver() -> str: # regex for db data replacement # will return 3 groups of matches in a tuple when uses with re.findall # i.e. - {{client.name}}, client, name -RE_DB_VALUE = re.compile(r"(\{\{\s*(client|site|agent|global|alert)\.(.*)\s*\}\})") +RE_DB_VALUE = re.compile(r"(\{\{\s*(client|site|agent|global|alert)\.([\w\-\s]+)\s*\}\})") # Receives something like {{ client.name }} and a Model instance of Client, Site, or Agent. If an