Example #1
0
def get_record_documents(recid, filename):
    """Yield LegacyBibDoc files from Documents."""
    from invenio_records.api import get_record
    from invenio_documents.api import Document
    from invenio.legacy.bibdocfile.api import decompose_file

    record = get_record(recid)
    duuids = [uuid for (k, uuid) in record.get('_documents', [])
              if k == filename]

    for duuid in duuids:
        document = Document.get_document(duuid)
        if not document.is_authorized(current_user):
            current_app.logger.info(
                "Unauthorized access to /{recid}/files/{filename} "
                "({document}) by {current_user}".format(
                    recid=recid, filename=filename, document=document,
                    current_user=current_user))
            continue

        if document.get('linked', False) and (
                document.get('uri').startswith('http://') or
                document.get('uri').startswith('https://')):
            url = document.get('uri')
        else:
            url = url_for('record.file', recid=recid, filename=filename)

        (dummy, name, superformat) = decompose_file(filename)

        class LegacyBibDoc(object):

            def __init__(self, **kwargs):
                for key, value in kwargs.items():
                    setattr(self, key, value)

            def get_full_path(self):
                return document.get('uri')

            def get_recid(self):
                return recid

        yield LegacyBibDoc(name=name, superformat=superformat, url=url)
 def setUp(self):
     """Run before the test."""
     from invenio_documents.api import Document
     self.document = Document.create({'title': 'J.A.R.V.I.S'})
     self.path = tempfile.mkdtemp()
 def setUp(self):
     """Run before the test."""
     from invenio_documents.api import Document
     self.document = Document.create({'title': 'Test restrictions'})
Example #4
0
 def setUp(self):
     """Run before the test."""
     from invenio_documents.api import Document
     self.document = Document.create({'title': 'Test restrictions'})