From 410f8b6fb8a7f8b71c15a2c3cfe967c8b9f91b24 Mon Sep 17 00:00:00 2001 From: devketanpro Date: Tue, 27 Feb 2024 21:31:23 +0530 Subject: [PATCH] FIX: Link in the author approval throws error 500 if the article contains images [TGA-83] --- server/tga/sign_off/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/tga/sign_off/utils.py b/server/tga/sign_off/utils.py index 490145e..3778f97 100644 --- a/server/tga/sign_off/utils.py +++ b/server/tga/sign_off/utils.py @@ -131,11 +131,11 @@ def get_css_filename(): def modify_asset_urls(item, author_id: ObjectId): pattern = re.compile('\/api\/upload-raw\/(.*?)"') - new_body_html = item["body_html"] + new_body_html = item.get("body_html", "") url_prefix = "/api/upload-raw/" url_prefix_len = len(url_prefix) - for asset_filename in re.findall(pattern, item["body_html"]): + for asset_filename in re.findall(pattern, item.get("body_html", "")): asset_token = gen_jwt_for_approval_request(asset_filename, author_id, "upload-raw", token_expiration=3600) new_body_html = new_body_html.replace( url_prefix + asset_filename, f"/api/sign_off_requests/upload-raw/{asset_token}" @@ -148,6 +148,11 @@ def modify_asset_urls(item, author_id: ObjectId): continue for size_name, rendition in (association.get("renditions") or {}).items(): rendition_href = rendition["href"] + + if "s3.amazonaws.com" in rendition_href: + # Skip modification, if it is pointing to Amazon S3 + continue + asset_filename = rendition_href[rendition_href.index(url_prefix) + url_prefix_len :] asset_token = gen_jwt_for_approval_request(asset_filename, author_id, "upload-raw", token_expiration=3600) rendition["href"] = rendition_href.replace(