Skip to content

Commit

Permalink
Fix email templates when renaming parent objects
Browse files Browse the repository at this point in the history
  • Loading branch information
rehoumir committed Sep 23, 2024
1 parent c0b854e commit 177da2c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
38 changes: 36 additions & 2 deletions project_rossum_deploy/commands/download/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,33 @@ async def check_schema_formula_fields_existence(remote_object: dict, path: Path)
...


async def check_email_template_existence(
client: ElisAPIClient, remote_object: dict, path: Path
):
try:
queue = await client._http_client.request_json(
method="GET", url=remote_object["queue"]
)
if not queue["workspace"]:
raise MissingParentObjectException
ws = await client._http_client.request_json(
method="GET", url=queue["workspace"]
)
except (APIClientError, MissingParentObjectException) as e:
if e.status_code != 404:
raise e

raise MissingParentObjectException

# Suffix = email_templates / <name>.json
compare_paths(
original_path=path,
ws=ws,
queue=queue,
suffix=Path(path.parent.name) / path.name,
)


async def remove_local_nonexistent_object(
path: Path,
client: ElisAPIClient,
Expand Down Expand Up @@ -210,6 +237,8 @@ async def remove_local_nonexistent_object(
await check_inbox_existence(client, remote_object, path)
elif object_type == Resource.Schema:
await check_schema_formula_fields_existence(remote_object, path)
elif object_type == Resource.EmailTemplate:
await check_email_template_existence(client, remote_object, path)

except (
APIClientError,
Expand Down Expand Up @@ -287,7 +316,11 @@ def compare_paths(original_path: Path, ws, queue, suffix):
queue_path_path = templatize_name_id(queue["name"], queue["id"])
path_parts = str(original_path).split("/")
latest_path = (
Path(*path_parts[:-4]) / ws_path_part / "queues" / queue_path_path / suffix
Path(*path_parts[: -5 if "email_templates" in str(suffix) else -4])
/ ws_path_part
/ "queues"
/ queue_path_path
/ suffix
)

# If the original path was absollut
Expand Down Expand Up @@ -348,7 +381,8 @@ async def determine_object_destination(
destination = settings.SOURCE_DIRNAME
else:
object_name, object_id = object["name"], object["id"]
user_decision = Confirm.ask(
# TODO: fix logic
user_decision = Confirm(
f'Should the {object_type} "{object_name}" ({object_id}) be in {settings.SOURCE_DIRNAME}? Otherwise, it will be understood as {settings.TARGET_DIRNAME}.'
)
destination = (
Expand Down
3 changes: 3 additions & 0 deletions tests/reference_project/prd_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_api_base: https://shared-eu2.rossum.app/api/v1
use_same_org_as_target: true
target_api_base: ''
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"app": null,
"payload_logging_enabled": false,
"timeout_s": 30,
"max_polling_time_s": 300,
"retry_count": 4,
"retry_count_for_polling_failure": 0,
"insecure_ssl": false,
"client_ssl_certificate": null,
"retry_on_any_non_2xx": false
Expand All @@ -54,5 +56,5 @@
"token_lifetime_s": null,
"hook_template": "https://shared-eu2.rossum.app/api/v1/hook_templates/30",
"modified_by": "https://shared-eu2.rossum.app/api/v1/users/285991",
"modified_at": "2024-08-14T13:42:23.661462Z"
"modified_at": "2024-09-17T06:50:38.010407Z"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
"app": null,
"payload_logging_enabled": false,
"timeout_s": 30,
"max_polling_time_s": 300,
"retry_count": 4,
"retry_count_for_polling_failure": 0,
"url": "https://shared-eu2.rossum.app/settings/extensions/create",
"secret": null,
"insecure_ssl": false,
Expand All @@ -45,5 +47,5 @@
"token_lifetime_s": null,
"hook_template": null,
"modified_by": "https://shared-eu2.rossum.app/api/v1/users/285991",
"modified_at": "2024-08-13T09:44:28.066752Z"
"modified_at": "2024-08-19T08:59:13.912998Z"
}
2 changes: 1 addition & 1 deletion tests/reference_project/source/organization.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"creator": "https://shared-eu2.rossum.app/api/v1/users/285991",
"settings": {},
"modified_by": "https://shared-eu2.rossum.app/api/v1/users/285991",
"modified_at": "2024-08-14T13:41:40.413544Z",
"modified_at": "2024-09-17T06:49:42.779725Z",
"sandbox": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -1202,5 +1202,5 @@
],
"metadata": {},
"modified_by": "https://shared-eu2.rossum.app/api/v1/users/285991",
"modified_at": "2024-08-14T13:39:55.612296Z"
"modified_at": "2024-09-17T06:47:15.546513Z"
}

0 comments on commit 177da2c

Please sign in to comment.