Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service: display tombstone for deleted record's files #511

Closed

Conversation

jrcastro2
Copy link
Contributor

@jrcastro2 jrcastro2 commented Sep 20, 2023

The following endpoints display the tombstone page:

  • api/records/<pid>/files
  • api/records/<pid>/files/<key>
  • api/records/<pid>/media-files
  • api/records/<pid>/files/<key>/content
  • api/records/<pid>/files-archive

@@ -70,6 +74,36 @@ def __init__(self, error):
super().__init__(code=500, description=_("Internal server error"))


class HTTPJSONException(_HTTPJSONException):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was moved here from invenio-rdm-records as it's required in this module as well

@@ -69,3 +69,12 @@ def __init__(self, recid, file_key):
)
self.recid = recid
self.file_key = file_key


class RecordDeletedException(Exception):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was moved here from invenio-rdm-records as it's required in this module as well

@jrcastro2 jrcastro2 marked this pull request as ready for review September 20, 2023 12:52
@jrcastro2 jrcastro2 force-pushed the fix-files-tombstone branch 2 times, most recently from 5020004 to f01b418 Compare September 20, 2023 13:17
@@ -68,10 +68,11 @@ def _get_record(self, id_, identity, action, file_key=None):
#
# High-level API
#
def list_files(self, identity, id_):
def list_files(self, identity, id_, with_deleted=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are all the with_deleted params being checked against permissions? I guess we need a <action>_deleted permission to check if you can perform the action?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrcastro2 jrcastro2 force-pushed the fix-files-tombstone branch 4 times, most recently from 6be91de to 8102172 Compare September 25, 2023 13:05
"""List the files of a record."""
record = self._get_record(id_, identity, "read_files")

self._check_record_deleted(record, identity, include_deleted)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improvement: read_deleted_files can potentially be consolidated with read_files permission, we could avoid double permission check

@@ -63,11 +63,11 @@ def get_by_key(cls, record_id, key):
return cls(obj.data, model=obj)

@classmethod
def list_by_record(cls, record_id, with_deleted=False):
def list_by_record(cls, record_id, include_deleted=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately this might cause issues.
the with_deleted is coming from invenio_records and I think we are now hiding this functionality

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see also (got it while testing):
Screenshot 2023-09-25 at 17 02 04

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error seems to be due to missing the changes from invenio-app-rdm, probably you are missing the changes of the following PR . If not, please describe how can I reproduce it and I will fix it.

if errors:
body["errors"] = errors

# TODO: Revisit how to integrate error monitoring services. See issue #56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the issue #56?
It is not easy to understand well what is the issue here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! Thank you for pointing this out. This code was moved here from invenio-rdm-records. And apparently that was copied from flask-resources, I have updated the comment to point to the correct issue

invenio_records_resources/services/files/service.py Outdated Show resolved Hide resolved
Comment on lines +473 to +491
].record_cls.deletion_status.is_deleted = True
recid = example_file_record["id"]
file_to_initialise = [
{
"key": "article.txt",
"checksum": "md5:c785060c866796cc2a1708c997154c8e",
"size": 17, # 2kB
"metadata": {
"description": "Published article PDF.",
},
}
]
# Initialize file saving
result = file_service.init_files(identity_simple, recid, file_to_initialise)
assert result.to_dict()["entries"][0]["key"] == file_to_initialise[0]["key"]
# for to_file in to_files:
content = BytesIO(b"test file content")
result = file_service.set_file_content(
identity_simple,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normally I would say you should not be able to set_file_content on deleted record unless for some reason the admin's job requires it. I would ask the zenodo support team for their use cases
I see two options

  1. this endpoint should be protected by permissions, and only admin should be able to set content/commit - in this case we miss a test to check if normal user or owner of the record still can commit files
  2. nobody, even the admin/moderator (except superuse) should be able to commit or set content

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit out of scope for this issue, the goal is to hide the files of deleted records. The behaviour of who can update files of deleted records was not changed, at the moment it's only admins.

If we want to change this we should add the tests in invenio-rdm-records as here we mocking the permissions.

assert result.file_id == "article.txt"

# Delete file
result = file_service.delete_file(identity_simple, recid, "article.txt")
Copy link
Contributor

@kpsherva kpsherva Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we allow to an user (simple identity) to delete a file from deleted record? I don't think it should happen. Once the record is deleted, it should be "frozen", check if RFC has any info about this case: inveniosoftware/invenio-app-rdm#2289

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using mocked permissions here, that's why a simple identity can delete files, the real permissions set for rdm should be tested in invenio-rdm-records.

@jrcastro2
Copy link
Contributor Author

Closed as the functionality is implemented in invenio-rdm-records inveniosoftware/invenio-rdm-records#1490

@jrcastro2 jrcastro2 closed this Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

files: deleted records' files shouldn't return information
4 participants