summaryrefslogtreecommitdiffstats
path: root/python/fatcat_web/entity_helpers.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2020-07-30 20:31:56 -0700
committerBryan Newbold <bnewbold@robocracy.org>2020-07-30 23:45:30 -0700
commit29593e492b632c8884c31993230d258d646e3d8c (patch)
tree377487ac715a48b0d5f2dc1e1d7752ea050ead50 /python/fatcat_web/entity_helpers.py
parentbedf147fecf7134fd22ea0ca7c94c5b7d4554416 (diff)
downloadfatcat-29593e492b632c8884c31993230d258d646e3d8c.tar.gz
fatcat-29593e492b632c8884c31993230d258d646e3d8c.zip
routes: handle case of viewing deleted entity in editgroup context
Eg, consider deleting an entity. When viewing the editgroup, want to be able to click the deleted entity and see the "deleted entity" page instead of a generic 404.
Diffstat (limited to 'python/fatcat_web/entity_helpers.py')
-rw-r--r--python/fatcat_web/entity_helpers.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/python/fatcat_web/entity_helpers.py b/python/fatcat_web/entity_helpers.py
index c9a57290..7156b9be 100644
--- a/python/fatcat_web/entity_helpers.py
+++ b/python/fatcat_web/entity_helpers.py
@@ -1,5 +1,6 @@
from flask import abort
+from fatcat_openapi_client import *
from fatcat_openapi_client.rest import ApiException, ApiValueError
from fatcat_tools.transforms import *
from fatcat_web import api
@@ -148,6 +149,26 @@ def generic_get_entity_revision(entity_type, revision_id):
except ApiValueError:
abort(400)
+def generic_deleted_entity(entity_type, ident):
+ if entity_type == 'container':
+ entity = ContainerEntity()
+ elif entity_type == 'creator':
+ entity = CreatorEntity()
+ elif entity_type == 'file':
+ entity = FileEntity()
+ elif entity_type == 'fileset':
+ entity = FilesetEntity()
+ elif entity_type == 'webcapture':
+ entity = WebcaptureEntity()
+ elif entity_type == 'release':
+ entity = ReleaseEntity()
+ elif entity_type == 'work':
+ entity = WorkEntity()
+ else:
+ raise NotImplementedError
+ entity.ident = ident
+ return entity
+
def generic_get_editgroup_entity(editgroup, entity_type, ident):
if entity_type == 'container':
edits = editgroup.edits.containers
@@ -166,14 +187,18 @@ def generic_get_editgroup_entity(editgroup, entity_type, ident):
else:
raise NotImplementedError
revision_id = None
+ edit = None
for e in edits:
if e.ident == ident:
revision_id = e.revision
edit = e
break
- if not revision_id:
+ if not edit:
# couldn't find relevant edit in this editgroup
abort(404)
+ if not revision_id:
+ # deletion, presumably
+ return generic_deleted_entity(entity_type, ident), edit
try:
entity = generic_get_entity_revision(entity_type, revision_id)