diff --git a/.editorconfig b/.editorconfig index ce9dd4c0..5cc4d4f1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -38,7 +38,7 @@ indent_size = 4 # isort plugin configuration known_standard_library = mimetypes known_first_party = invenio_files_rest -known_third_party = invenio_access, invenio_admin, invenio_accounts, invenio_db, invenio_records, invenio_rest, invenio_records_files, invenio_records_ui +known_third_party = invenio_access, invenio_admin, invenio_accounts, invenio_db, invenio_rest multi_line_output = 2 default_section = THIRDPARTY diff --git a/invenio_files_rest/ext.py b/invenio_files_rest/ext.py index 91e5d9b8..ca200ab1 100644 --- a/invenio_files_rest/ext.py +++ b/invenio_files_rest/ext.py @@ -44,21 +44,6 @@ def __init__(self, app): """Initialize state.""" self.app = app - @cached_property - def record_file_factory(self): - """Load default storage factory.""" - r = load_or_import_from_config( - 'FILES_REST_RECORD_FILE_FACTORY', app=self.app) - if r is not None: - return r - else: - try: - get_distribution('invenio-records-files') - from invenio_records_files.utils import record_file_factory - return record_file_factory - except DistributionNotFound: - return lambda pid, record, filename: None - @cached_property def storage_factory(self): """Load default storage factory.""" diff --git a/invenio_files_rest/views.py b/invenio_files_rest/views.py index 708621a6..028d24f2 100644 --- a/invenio_files_rest/views.py +++ b/invenio_files_rest/views.py @@ -302,52 +302,6 @@ def decorate(*args, **kwargs): ) -# -# Records-UI integration -# -def file_download_ui(pid, record, **kwargs): - """File download view for a given record. - - Plug this method into your ``RECORDS_UI_ENDPOINTS`` configuration: - - .. code-block:: python - - RECORDS_UI_ENDPOINTS = dict( - recid=dict( - # ... - route='/records/', - view_imp='invenio_files_rest.views.file_download_ui', - record_class='invenio_records_files.api:Record', - ) - ) - - :param pid: The :class:`invenio_pidstore.models.PersistentIdentifier` - instance. - :param record: The record metadata. - """ - # Extract file from record. - fileobj = current_files_rest.record_file_factory( - pid, record, request.view_args.get('filename')) - - if not fileobj: - abort(404) - - obj = fileobj.obj - - # Check permissions - ObjectResource.check_object_permission(obj) - - # Send file. - return ObjectResource.send_object( - obj.bucket, obj, - expected_chksum=fileobj.get('checksum'), - logger_data=dict( - bucket_id=obj.bucket_id, - pid_type=pid.pid_type, - pid_value=pid.pid_value, - )) - - # # REST resources # diff --git a/setup.py b/setup.py index ac71253b..434b9301 100644 --- a/setup.py +++ b/setup.py @@ -40,8 +40,6 @@ 'invenio-accounts>=1.0.0a15', 'invenio-admin>=1.0.0a3', 'invenio-celery>=1.0.0a4', - 'invenio-records-files>=1.0.0a4', - 'invenio-records-ui>=1.0.0a5', 'isort>=4.2.2', 'mock>=1.3.0', 'pydocstyle>=1.0.0', diff --git a/tests/test_views_records_ui.py b/tests/test_views_records_ui.py deleted file mode 100644 index e80f37e9..00000000 --- a/tests/test_views_records_ui.py +++ /dev/null @@ -1,96 +0,0 @@ -# -*- coding: utf-8 -*- -# -# This file is part of Invenio. -# Copyright (C) 2016 CERN. -# -# Invenio is free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# Invenio is distributed in the hope that it will be -# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Invenio; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, -# MA 02111-1307, USA. -# -# In applying this license, CERN does not -# waive the privileges and immunities granted to it by virtue of its status -# as an Intergovernmental Organization or submit itself to any jurisdiction. - -"""Records-UI custom view func tests.""" - -from __future__ import absolute_import, print_function - -import uuid - -from flask import url_for -from invenio_pidstore import InvenioPIDStore -from invenio_pidstore.models import PersistentIdentifier, PIDStatus -from invenio_records import InvenioRecords -from invenio_records_files.api import Record, RecordsBuckets -from invenio_records_ui import InvenioRecordsUI - - -def test_file_download_ui(base_app, objects, db): - """Test get buckets.""" - app = base_app - app.config.update(dict( - RECORDS_UI_DEFAULT_PERMISSION_FACTORY=None, # No permission checking - RECORDS_UI_ENDPOINTS=dict( - recid=dict( - pid_type='recid', - route='/records/', - ), - recid_files=dict( - pid_type='recid', - route='/records//files/', - view_imp='invenio_files_rest.views.file_download_ui', - record_class='invenio_records_files.api:Record', - ), - ) - )) - InvenioRecords(app) - InvenioPIDStore(app) - InvenioRecordsUI(app) - - obj1 = objects[0] - - with app.app_context(): - # Record 1 - Live record - rec_uuid = uuid.uuid4() - PersistentIdentifier.create( - 'recid', '1', object_type='rec', object_uuid=rec_uuid, - status=PIDStatus.REGISTERED) - record = Record.create({ - 'title': 'Registered', - 'recid': 1, - '_files': [ - {'key': obj1.key, 'bucket': str(obj1.bucket_id), - 'checksum': 'invalid'}, - ] - }, id_=rec_uuid) - RecordsBuckets.create(record=record.model, bucket=obj1.bucket) - db.session.commit() - - main_url = url_for('invenio_records_ui.recid', pid_value='1') - file_url = url_for( - 'invenio_records_ui.recid_files', pid_value='1', filename=obj1.key) - no_file_url = url_for( - 'invenio_records_ui.recid_files', pid_value='1', filename='') - invalid_file_url = url_for( - 'invenio_records_ui.recid_files', pid_value='1', filename='no') - - with app.test_client() as client: - res = client.get(main_url) - assert res.status_code == 200 - res = client.get(file_url) - assert res.status_code == 200 - res = client.get(no_file_url) - assert res.status_code == 404 - res = client.get(invalid_file_url) - assert res.status_code == 404