Esempio n. 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
Esempio n. 2
0
    def test_get_absolute_url(self):
        """Test absolute url."""
        from zenodo.modules.accessrequests.models import SecretLink

        l = SecretLink.create("Testing", self.receiver, dict(recid=1))
        url = l.get_absolute_url('record.metadata')
        assert "/record/1?" in url
        assert "token={0}".format(l.token) in url
Esempio n. 3
0
    def test_get_absolute_url(self):
        """Test absolute url."""
        from zenodo.modules.accessrequests.models import SecretLink

        l = SecretLink.create("Testing", self.receiver, dict(recid=1))
        url = l.get_absolute_url('record.metadata')
        assert "/record/1?" in url
        assert "token={0}".format(l.token) in url
Esempio n. 4
0
    def test_expired(self):
        """Test link expiry date."""
        from zenodo.modules.accessrequests.models import SecretLink

        l = SecretLink.create(
            "Test title", self.receiver, dict(recid=123456),
            description="Test description",
            expires_at=datetime.now()-timedelta(days=1))
        assert l.is_expired()
        assert not l.is_valid()

        l = SecretLink.create(
            "Test title", self.receiver, dict(recid=123456),
            description="Test description",
            expires_at=datetime.now()+timedelta(days=1))
        assert not l.is_expired()
        assert l.is_valid()
Esempio n. 5
0
    def test_expired(self):
        """Test link expiry date."""
        from zenodo.modules.accessrequests.models import SecretLink

        l = SecretLink.create("Test title",
                              self.receiver,
                              dict(recid=123456),
                              description="Test description",
                              expires_at=datetime.now() - timedelta(days=1))
        assert l.is_expired()
        assert not l.is_valid()

        l = SecretLink.create("Test title",
                              self.receiver,
                              dict(recid=123456),
                              description="Test description",
                              expires_at=datetime.now() + timedelta(days=1))
        assert not l.is_expired()
        assert l.is_valid()
Esempio n. 6
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))
Esempio n. 7
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))
Esempio n. 8
0
    def test_query_by_owner(self):
        """Test query by owner."""
        from zenodo.modules.accessrequests.models import SecretLink

        self.assertEqual(SecretLink.query_by_owner(self.receiver).count(), 0)
        self.assertEqual(SecretLink.query_by_owner(self.sender).count(), 0)

        SecretLink.create("Testing", self.receiver, dict(recid=1))

        self.assertEqual(SecretLink.query_by_owner(self.receiver).count(), 1)
        self.assertEqual(SecretLink.query_by_owner(self.sender).count(), 0)
Esempio n. 9
0
    def test_revoked(self):
        """Test link revocation."""
        from zenodo.modules.accessrequests.models import SecretLink

        from zenodo.modules.accessrequests.signals import \
            link_revoked

        with link_revoked.connected_to(self.get_receiver('revoked')):
            l = SecretLink.create("Test title",
                                  self.receiver,
                                  dict(recid=123456),
                                  description="Test description")
            assert not l.is_revoked()
            assert l.is_valid()
            l.revoke()
            assert l.is_revoked()
            assert not l.is_valid()

            self.assertIsNotNone(self.called['revoked'])

            self.assertFalse(l.revoke())
Esempio n. 10
0
    def test_revoked(self):
        """Test link revocation."""
        from zenodo.modules.accessrequests.models import SecretLink

        from zenodo.modules.accessrequests.signals import \
            link_revoked

        with link_revoked.connected_to(self.get_receiver('revoked')):
            l = SecretLink.create(
                "Test title", self.receiver, dict(recid=123456),
                description="Test description"
            )
            assert not l.is_revoked()
            assert l.is_valid()
            l.revoke()
            assert l.is_revoked()
            assert not l.is_valid()

            self.assertIsNotNone(self.called['revoked'])

            self.assertFalse(l.revoke())
Esempio n. 11
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
Esempio n. 12
0
    def test_query_by_owner(self):
        """Test query by owner."""
        from zenodo.modules.accessrequests.models import SecretLink

        self.assertEqual(
            SecretLink.query_by_owner(self.receiver).count(),
            0)
        self.assertEqual(
            SecretLink.query_by_owner(self.sender).count(),
            0)

        SecretLink.create("Testing", self.receiver, dict(recid=1))

        self.assertEqual(
            SecretLink.query_by_owner(self.receiver).count(),
            1)
        self.assertEqual(
            SecretLink.query_by_owner(self.sender).count(),
            0)