Example #1
0
    def _add_bibdoc_files():
        from invenio.legacy.bibdocfile.api import BibRecDocs

        ctx = dict(
            zenodo_files=[f for f in BibRecDocs(
                kwargs['recid'], human_readable=True
            ).list_latest_files(
                list_hidden=False
            ) if not f.is_icon()],
            file_token=None,
        )

        token = request.args.get('token')
        if token:
            if SecretLink.validate_token(token,
                                         dict(recid=kwargs['recid'])):
                ctx["file_token"] = token
                return ctx
            else:
                pass  # Flash a message that token is invalid.

        ctx["zenodo_files"] = filter(
            lambda f: f.is_restricted(current_user)[0] == 0,
            ctx["zenodo_files"]
        )

        return ctx
Example #2
0
    def test_creation(self):
        """Test link creation."""
        from zenodo.modules.accessrequests.models import SecretLink

        from zenodo.modules.accessrequests.signals import \
            link_created

        with link_created.connected_to(self.get_receiver('created')):
            l = SecretLink.create("Test title", self.receiver, dict(recid=1),
                                  description="Test description")

            self.assertEqual(l.title, "Test title")
            self.assertEqual(l.description, "Test description")
            self.assertIsNone(l.expires_at)
            self.assertNotEqual(l.token, "")
            self.assertIsNotNone(self.called['created'])

            assert SecretLink.validate_token(l.token, dict(recid=1),)
            assert not SecretLink.validate_token(l.token, dict(recid=2))
Example #3
0
    def test_creation(self):
        """Test link creation."""
        from zenodo.modules.accessrequests.models import SecretLink

        from zenodo.modules.accessrequests.signals import \
            link_created

        with link_created.connected_to(self.get_receiver('created')):
            l = SecretLink.create("Test title",
                                  self.receiver,
                                  dict(recid=1),
                                  description="Test description")

            self.assertEqual(l.title, "Test title")
            self.assertEqual(l.description, "Test description")
            self.assertIsNone(l.expires_at)
            self.assertNotEqual(l.token, "")
            self.assertIsNotNone(self.called['created'])

            assert SecretLink.validate_token(
                l.token,
                dict(recid=1),
            )
            assert not SecretLink.validate_token(l.token, dict(recid=2))
Example #4
0
    def _add_bibdoc_files():
        from invenio.legacy.bibdocfile.api import BibRecDocs

        ctx = dict(
            zenodo_files=[
                f for f in BibRecDocs(kwargs['recid'], human_readable=True).
                list_latest_files(list_hidden=False) if not f.is_icon()
            ],
            file_token=None,
        )

        token = request.args.get('token')
        if token:
            if SecretLink.validate_token(token, dict(recid=kwargs['recid'])):
                ctx["file_token"] = token
                return ctx
            else:
                pass  # Flash a message that token is invalid.

        ctx["zenodo_files"] = filter(
            lambda f: f.is_restricted(current_user)[0] == 0,
            ctx["zenodo_files"])

        return ctx