-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* closes #1479
- Loading branch information
Showing
8 changed files
with
404 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2023 CERN. | ||
# | ||
# Invenio-RDM-Records is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""File Service API.""" | ||
from invenio_rdm_records.services.files.service import RDMFileService | ||
|
||
__all__ = ("RDMFileService",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2023 CERN. | ||
# | ||
# Invenio-RDM-Records is free software; you can redistribute it and/or modify | ||
# it under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""File Service API.""" | ||
from invenio_records_resources.services import FileService | ||
from invenio_records_resources.services.errors import FileKeyNotFoundError | ||
|
||
from invenio_rdm_records.services.errors import RecordDeletedException | ||
|
||
|
||
class RDMFileService(FileService): | ||
"""A service for adding files support to records.""" | ||
|
||
def _check_record_deleted_permissions(self, record, identity): | ||
"""Ensure that the record exists (not deleted) or raise.""" | ||
if record.is_draft: | ||
return | ||
if record.deletion_status.is_deleted: | ||
can_read_deleted = self.check_permission( | ||
identity, "read_deleted_files", record=record | ||
) | ||
if not can_read_deleted: | ||
raise RecordDeletedException(record) | ||
|
||
def _get_record(self, id_, identity, action, file_key=None): | ||
"""Get the associated record.""" | ||
record = super()._get_record(id_, identity, action, file_key) | ||
self._check_record_deleted_permissions(record, identity) | ||
|
||
return record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.