Beispiel #1
0
    def delete(self, id, user_id):

        user_group_dao = UserGroupDao(self.db_session())
        user_group = user_group_dao.retrieve(id=id)
        if user_group is None:
            return self.error_response('User group {} not found'.format(id), http.NOT_FOUND_404)

        user_dao = UserDao(self.db_session())
        user = user_dao.retrieve(id=user_id)
        if user is None:
            return self.error_response('User {} not found'.format(id), http.NOT_FOUND_404)

        if user in user_group.users:
            user_group.users.remove(user)
            user_group = user_group_dao.save(user_group)

        return self.response(user_group.to_dict())
Beispiel #2
0
    def put(self, id):

        parser = reqparse.RequestParser()
        parser.add_argument('name', type=str, location='json')
        parser.add_argument('is_visible', type=bool, location='json')
        args = parser.parse_args()

        user_group_dao = UserGroupDao(self.db_session())
        user_group = user_group_dao.retrieve(id=id)
        if user_group is None:
            return self.error_response('User group {} not found'.format(id), http.NOT_FOUND_404)

        if args.get('name'):
            user_group.name = args['name']

        user_group = user_group_dao.save(user_group)

        return self.response(user_group.to_dict())