From 7c384d1f4512692be7d18ffd4c0976bdedbab01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 30 Jan 2018 15:49:57 +0100 Subject: [PATCH] Link refresh: allow refreshing links for soft-deleted projects. Since files aren't deleted (yet) when projects are deleted, it can happen that a file is refreshed but then cannot reference a deleted project. By removing the project ID from the PATCH, Eve doesn't have enough info to check this, and it'll work fine. --- pillar/api/file_storage/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pillar/api/file_storage/__init__.py b/pillar/api/file_storage/__init__.py index e8e18c54..7ebded7f 100644 --- a/pillar/api/file_storage/__init__.py +++ b/pillar/api/file_storage/__init__.py @@ -467,6 +467,12 @@ def generate_all_links(response, now): response['link_expires'] = now + datetime.timedelta(seconds=validity_secs) patch_info = remove_private_keys(response) + + # The project could have been soft-deleted, in which case it's fine to + # update the links to the file. However, Eve/Cerberus doesn't allow this; + # removing the 'project' key from the PATCH works around this. + patch_info.pop('project', None) + file_id = ObjectId(response['_id']) (patch_resp, _, _, _) = current_app.patch_internal('files', patch_info, _id=file_id)