Beispiel #1
0
    def test_restriction(self):
        """JSONAlchemy - restriction"""
        from flask_login import login_user, logout_user
        from invenio.ext.login.legacy_user import UserInfo
        from invenio.modules.jsonalchemy.reader import Reader
        from invenio.modules.jsonalchemy.wrappers import SmartJson

        blob = {'_id': 1}

        json = Reader.translate(blob,
                                SmartJson,
                                model='test_access_base',
                                master_format='json',
                                namespace='testsuite')
        self.assertIsNotNone(json)
        self.assertTrue('restriction' in json)
        self.assertTrue('email' in json['restriction'])
        self.assertTrue(hasattr(json, 'is_authorized'))
        self.assertEqual(json.is_authorized()[0], 0)
        self.assertEqual(json.is_authorized(user_info=UserInfo(1))[0], 0)

        json['restriction']['email'] = UserInfo(1)['email']
        self.assertEqual(json.is_authorized()[0], 1)
        self.assertEqual(json.is_authorized(user_info=UserInfo(1))[0], 0)

        login_user(UserInfo(1))
        self.assertEqual(json.is_authorized()[0], 0)

        logout_user()
        self.assertEqual(json.is_authorized()[0], 1)
class OAuthUserProxy(object):
    """Proxy object to an Invenio User."""

    def __init__(self, user):
        self._user = user

    def __getattr__(self, name):
        """Pass any undefined attribute to the underlying object."""
        return getattr(self._user, name)

    def __getstate__(self):
        """Get state."""
        return self.id

    def __setstate__(self, state):
        """Set state."""
        self._user = UserInfo(state)

    @property
    def id(self):
        return self._user.get_id()

    def check_password(self, password):
        return self.password == password

    @classmethod
    def get_current_user(cls):
        return cls(current_user._get_current_object())
Beispiel #3
0
class OAuthUserProxy(object):
    """Proxy object to an Invenio User."""
    def __init__(self, user):
        """Initialize proxy object with user instance."""
        self._user = user

    def __getattr__(self, name):
        """Pass any undefined attribute to the underlying object."""
        return getattr(self._user, name)

    def __getstate__(self):
        """Return the id."""
        return self.id

    def __setstate__(self, state):
        """Set user info."""
        self._user = UserInfo(state)

    @property
    def id(self):
        """Return user identifier."""
        return self._user.get_id()

    def check_password(self, password):
        """Check user password."""
        return self.password == password

    @classmethod
    def get_current_user(cls):
        """Return an instance of current user object."""
        return cls(current_user._get_current_object())
Beispiel #4
0
class OAuthUserProxy(object):

    """Proxy object to an Invenio User."""

    def __init__(self, user):
        """Initialize proxy object with user instance."""
        self._user = user

    def __getattr__(self, name):
        """Pass any undefined attribute to the underlying object."""
        return getattr(self._user, name)

    def __getstate__(self):
        """Return the id."""
        return self.id

    def __setstate__(self, state):
        """Set user info."""
        self._user = UserInfo(state)

    @property
    def id(self):
        """Return user identifier."""
        return self._user.get_id()

    def check_password(self, password):
        """Check user password."""
        return self.password == password

    @classmethod
    def get_current_user(cls):
        """Return an instance of current user object."""
        return cls(current_user._get_current_object())
Beispiel #5
0
class OAuthUserProxy(object):
    """Proxy object to an Invenio User."""
    def __init__(self, user):
        self._user = user

    def __getattr__(self, name):
        """Pass any undefined attribute to the underlying object."""
        return getattr(self._user, name)

    def __getstate__(self):
        """Get state."""
        return self.id

    def __setstate__(self, state):
        """Set state."""
        self._user = UserInfo(state)

    @property
    def id(self):
        return self._user.get_id()

    def check_password(self, password):
        return self.password == password

    @classmethod
    def get_current_user(cls):
        return cls(current_user._get_current_object())
    def test_create(self):
        from invenio.ext.login.legacy_user import UserInfo
        from invenio.modules.deposit.models import Deposition

        user = UserInfo(uid=1)
        d = Deposition.create(user)
        assert d.type == self.DefaultType
        assert Deposition.get(d.id).type == self.DefaultType
        d = Deposition.create(user, type=self.AnotherType)
        assert d.type == self.AnotherType
        assert Deposition.get(d.id).type == self.AnotherType
    def test_create(self):
        """Test."""
        from invenio.ext.login.legacy_user import UserInfo
        from invenio_deposit.models import Deposition

        user = UserInfo(uid=1)
        d = Deposition.create(user)
        assert d.type == self.DefaultType
        assert Deposition.get(d.id).type == self.DefaultType
        d2 = Deposition.create(user, type=self.AnotherType)
        assert d2.type == self.AnotherType
        assert Deposition.get(d2.id).type == self.AnotherType

        # remove the records
        Deposition.delete(d)
        Deposition.delete(d2)
 def __setstate__(self, state):
     """Set state."""
     self._user = UserInfo(state)
Beispiel #9
0
 def __setstate__(self, state):
     """Set user info."""
     self._user = UserInfo(state)
Beispiel #10
0
 def __setstate__(self, state):
     self._user = UserInfo(state)