예제 #1
0
    def test_by_user_and_perm(self, db_session):
        add_user(db_session)
        user_permission = UserPermissionService.by_user_and_perm(
            1, "root", db_session=db_session)

        assert user_permission.user_id == 1
        assert user_permission.perm_name == "root"
예제 #2
0
 def test_get(self, db_session):
     user = add_user(db_session)
     perm = UserPermissionService.get(user_id=user.id,
                                      perm_name='root',
                                      db_session=db_session)
     assert perm.user_id == user.id
     assert perm.perm_name == 'root'
예제 #3
0
    def test_by_user_and_perm_wrong_permname(self, db_session):
        add_user(db_session)
        user_permission = UserPermissionService.by_user_and_perm(
            1, "wrong", db_session=db_session
        )

        assert user_permission is None
예제 #4
0
 def test_get(self, db_session):
     user = add_user(db_session)
     perm = UserPermissionService.get(
         user_id=user.id, perm_name="root", db_session=db_session
     )
     assert perm.user_id == user.id
     assert perm.perm_name == "root"
예제 #5
0
    def test_by_user_and_perm(self, db_session):
        add_user(db_session)
        user_permission = UserPermissionService.by_user_and_perm(
            1, "root", db_session=db_session
        )

        assert user_permission.user_id == 1
        assert user_permission.perm_name == "root"
예제 #6
0
    def by_user_and_perm(cls, user_id, perm_name, db_session=None):
        """

        .. deprecated:: 0.8

        :param user_id:
        :param perm_name:
        :param db_session:
        :return:
        """
        db_session = get_db_session(db_session)
        return UserPermissionService.by_user_and_perm(
            user_id=user_id, perm_name=perm_name, db_session=db_session)
예제 #7
0
 def permission_delete(self, user, permission):
     permission_inst = UserPermissionService.by_user_and_perm(
         user.id, permission.perm_name, db_session=self.request.dbsession)
     if permission_inst:
         log.info('user_permission_delete',
                  extra={
                      'user_id': user.id,
                      'user_name': user.user_name,
                      'permission': permission.perm_name
                  })
         user.user_permissions.remove(permission_inst)
         self.request.session.flash({
             'msg':
             self.translate(_('Permission withdrawn from user.')),
             'level':
             'success'
         })
예제 #8
0
    def test_by_user_and_perm_wrong_permname(self, db_session):
        add_user(db_session)
        user_permission = UserPermissionService.by_user_and_perm(
            1, "wrong", db_session=db_session)

        assert user_permission is None
예제 #9
0
 def permission_get(self, user, permission):
     permission = UserPermissionService.by_user_and_perm(
         user.id, permission, db_session=self.request.dbsession)
     if not permission:
         raise pyramid.httpexceptions.HTTPNotFound()
     return permission