Пример #1
0
    def update(self, user):
        user_to_update = self.user_model.query.get(user.id)

        if not user_to_update:
            raise NoResultFound(user.id, User.__name__)

        roles = models.UserRole.query.filter(
            models.UserRole.id.in_([role.id for role in user.roles])).all()

        if not roles:
            raise NoResultFound([role.id for role in user.roles], 'UserRole')

        try:
            user_to_update.name = user.name
            user_to_update.roles = roles

            self.session.add(user_to_update)
            self.session.commit()

        except exc.IntegrityError as e:
            self.session.rollback()

            if 'unique' in str(e).lower():
                raise NotUnique('User already exist')
            raise

        except exc.SQLAlchemyError:
            self.session.rollback()
            raise DbError()

        return self._to_domain_model(user_to_update)
Пример #2
0
    def check_password(self, user, password):
        result = self.user_model.query.get(user.id)

        if not result:
            raise NoResultFound(id, User.__name__)

        return result.check_password(password)
Пример #3
0
    def save(self, user, password):
        roles = models.UserRole.query.filter(
            models.UserRole.id.in_([role.id for role in user.roles])).all()

        if not roles:
            raise NoResultFound([role.id for role in user.roles], 'UserRole')

        try:
            new_user = self.user_model(name=user.name, roles=roles, password=password)
            self.session.add(new_user)
            self.session.commit()

        except exc.IntegrityError as e:
            self.session.rollback()

            if 'unique' in str(e).lower():
                raise NotUnique('User already exist')

            raise

        except exc.SQLAlchemyError:
            self.session.rollback()
            raise DbError()

        return self._to_domain_model(new_user)
    def one(self, id):
        result = self.role_model.query.get(id)

        if not result:
            raise NoResultFound(id, UserRole.__name__)

        return UserRole(id=result.id, name=result.name)
Пример #5
0
    def one(self, id):
        result = self.user_model.query.get(id)

        if not result:
            raise NoResultFound(id, User.__name__)

        return self._to_domain_model(result)
    def one(self, id):
        status = self.status_model.query.get(id)

        if not status:
            raise NoResultFound(id, TaskStatus.__name__)

        return TaskStatus(id=status.id, name=status.name)
Пример #7
0
    def update(self, task):
        task_to_update = self.task_model.query.get(task.id)

        if not task_to_update:
            raise NoResultFound(task.id, Task.__name__)

        doer_id = None

        if task.doer:
            doer_id = task.doer.id
            doer = models.User.query.get(doer_id)
            if not doer:
                raise NoResultFound(doer_id, 'User')

        creator = models.User.query.get(task.creator.id)

        if not creator:
            raise NoResultFound(task.creator.id, 'User')

        if not models.TaskStatus.query.get(task.status.id):
            raise NoResultFound(task.status.id, 'TaskStatus')

        try:
            task_to_update.status_id = task.status.id
            task_to_update.creator_id = task.creator.id

            task_to_update.doer_id = doer_id

            task_to_update.content = task.content
            task_to_update.name = task.name

            self.session.add(task_to_update)
            self.session.commit()

        except exc.IntegrityError as e:
            self.session.rollback()

            if 'unique' in str(e).lower():
                raise NotUnique('Task already exist')
            raise

        except exc.SQLAlchemyError:
            self.session.rollback()
            raise DbError()

        return self._to_domain_model(task_to_update)
    def delete(self, id):
        status = self.status_model.query.get(id)

        if not status:
            raise NoResultFound(id, TaskStatus.__name__)

        try:
            self.session.delete(status)
            self.session.commit()

        except exc.IntegrityError as e:
            self.session.rollback()

            if 'foreign' in str(e).lower():
                raise CannotBeDeleted('Cannot delete status')
            raise

        except exc.SQLAlchemyError:
            self.session.rollback()
            raise DbError()

        return TaskStatus(id=id, name=status.name)
Пример #9
0
    def delete(self, id):
        result = self.task_model.query.get(id)

        if not result:
            raise NoResultFound(id, Task.__name__)

        try:
            task = self._to_domain_model(result)
            self.session.delete(result)
            self.session.commit()

        except exc.IntegrityError as e:
            self.session.rollback()

            if 'foreign' in str(e).lower():
                raise CannotBeDeleted('Cannot delete task')
            raise

        except exc.SQLAlchemyError:
            self.session.rollback()
            raise DbError()

        return task
    def delete(self, id):
        role_to_delete = self.role_model.query.get(id)

        if not role_to_delete:
            raise NoResultFound(id, UserRole.__name__)

        try:
            role = UserRole(id=role_to_delete.id, name=role_to_delete.name)
            self.session.delete(role_to_delete)
            self.session.commit()

        except exc.IntegrityError as e:
            self.session.rollback()

            if 'foreign' in str(e).lower():
                raise CannotBeDeleted('Cannot delete role')
            raise

        except exc.SQLAlchemyError:
            self.session.rollback()
            raise DbError()

        return role
    def update(self, role):
        role_to_update = self.role_model.query.get(role.id)

        if not role_to_update:
            raise NoResultFound(role.id, UserRole.__name__)

        try:
            role_to_update.name = role.name
            self.session.add(role_to_update)
            self.session.commit()

        except exc.IntegrityError as e:
            self.session.rollback()

            if 'unique' in str(e).lower():
                raise NotUnique('Role already exist')
            raise

        except exc.SQLAlchemyError:
            self.session.rollback()
            raise DbError()

        return UserRole(id=role_to_update.id, name=role_to_update.name)
Пример #12
0
    def delete(self, id):
        user = self.user_model.query.get(id)

        if not user:
            raise NoResultFound(id, User.__name__)

        rv = self._to_domain_model(user)

        try:
            self.session.delete(user)
            self.session.commit()

        except exc.IntegrityError as e:
            self.session.rollback()

            if 'foreign' in str(e).lower():
                raise CannotBeDeleted('Cannot delete user')
            raise

        except exc.SQLAlchemyError:
            self.session.rollback()
            raise DbError()

        return rv
    def update(self, status):
        status_to_update = self.status_model.query.get(status.id)

        if not status_to_update:
            raise NoResultFound(status.id, TaskStatus.__name__)

        try:
            status_to_update.name = status.name

            self.session.add(status_to_update)
            self.session.commit()

        except exc.IntegrityError as e:
            self.session.rollback()

            if 'unique' in str(e).lower():
                raise NotUnique('Status already exist')
            raise

        except exc.SQLAlchemyError:
            self.session.rollback()
            raise DbError()

        return TaskStatus(id=status_to_update.id, name=status_to_update.name)