コード例 #1
0
ファイル: space.py プロジェクト: coco413/walle-web
    def put(self, space_id, action=None):
        """
        update environment
        /environment/<int:id>

        :return:
        """
        super(SpaceAPI, self).put()

        if action and action == 'switch':
            return self.switch(space_id)
        current_app.logger.info(json.loads(request.form['members']))
        form = SpaceForm(request.form, csrf_enabled=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)

            # a new type to update a model
            ret = space.update(data)
            # create group
            if 'members' in request.form:
                MemberModel(group_id=space_id).update_group(members=json.loads(request.form['members']))
            return self.render_json(data=space.item())
        else:
            return self.render_json(code=-1, message=form.errors)
コード例 #2
0
    def list(self):
        """
        用户组列表
        /group/

        :return:
        """
        page = int(request.args.get('page', 0))
        page = page - 1 if page else 0
        size = int(request.args.get('size', 10))
        kw = request.values.get('kw', '')
        space_model = SpaceModel()
        space_list, count = space_model.list(page=page, size=size, kw=kw)
        return self.list_json(list=space_list,
                              count=count,
                              enable_create=permission.enable_role(OWNER))

        group_model, count = SpaceModel().query_paginate(
            page=page, limit=size, filter_name_dict=filter)
        groups = []
        for group_info in group_model:
            group_sub = MemberModel.query \
                .filter_by(group_id=group_info.id) \
                .count()

            group_info = group_info.to_json()
            group_info['users'] = group_sub
            group_info['group_id'] = group_info['id']
            group_info['group_name'] = group_info['name']
            groups.append(group_info)
        return self.list_json(list=groups, count=count)
コード例 #3
0
ファイル: space.py プロジェクト: ye854526102/walle-web
    def put(self, space_id, action=None):
        """
        update environment
        /environment/<int:id>

        :return:
        """
        super(SpaceAPI, self).put()

        if action and action == 'switch':
            return self.switch(space_id)
        current_app.logger.info(json.loads(request.form['members']))
        form = SpaceForm(request.form, csrf_enabled=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)

            # a new type to update a model
            ret = space.update(data)
            # create group
            if 'members' in request.form:
                MemberModel(group_id=space_id).update_group(members=json.loads(request.form['members']))
            return self.render_json(data=space.item())
        else:
            return self.render_json(code=-1, message=form.errors)
コード例 #4
0
ファイル: space.py プロジェクト: wenfy2018/walle-web
    def post(self):
        """
        create a space
        /environment/

        :return:
        """
        super(SpaceAPI, self).post()

        form = SpaceForm(request.form, csrf_enabled=False)
        # return self.render_json(code=-1, data = form.form2dict())
        if form.validate_on_submit():
            # create space
            space_new = SpaceModel()
            data = form.form2dict()
            id = space_new.add(data)
            if not id:
                return self.render_json(code=-1)

            current_app.logger.info(request.json)
            # create group
            data['role'] = OWNER
            members = [data]
            MemberModel(group_id=id).update_group(members=members)
            return self.render_json(data=space_new.item())
        else:
            return self.render_json(code=-1, message=form.errors)
コード例 #5
0
    def update(self, space_id):
        form = SpaceForm(request.form, csrf=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)
            member_model = MemberModel(group_id=space_id)
            old_owner = space.user_id
            new_owner = data['user_id']
            # a new type to update a model
            space.update(data)

            if str(old_owner) != str(new_owner):
                # owner has changed
                member_model.change_owner(old_owner, new_owner)

            # create group
            current_owner = {"user_id": new_owner, "role": OWNER}
            if 'members' in request.form:
                members = json.loads(request.form['members'])
                members.append(current_owner)
                member_model.update_group(members=members)
            return self.render_json(data=space.item())
        else:
            return self.render_error(code=Code.form_error, message=form.errors)
コード例 #6
0
ファイル: group.py プロジェクト: heartshare/walle-web
    def list(self):
        """
        用户组列表
        /group/

        :return:
        """
        page = int(request.args.get('page', 0))
        page = page - 1 if page else 0
        size = int(request.args.get('size', 10))
        kw = request.values.get('kw', '')
        space_model = SpaceModel()
        space_list, count = space_model.list(page=page, size=size, kw=kw)
        return self.list_json(list=space_list, count=count, enable_create=permission.role_upper_owner())

        group_model, count = SpaceModel().query_paginate(page=page, limit=size, filter_name_dict=filter)
        groups = []
        for group_info in group_model:
            group_sub = MemberModel.query \
                .filter_by(group_id=group_info.id) \
                .count()

            group_info = group_info.to_json()
            group_info['users'] = group_sub
            group_info['group_id'] = group_info['id']
            group_info['group_name'] = group_info['name']
            groups.append(group_info)
        return self.list_json(list=groups, count=count)
コード例 #7
0
ファイル: space.py プロジェクト: coco413/walle-web
    def post(self):
        """
        create a space
        /environment/

        :return:
        """
        super(SpaceAPI, self).post()

        form = SpaceForm(request.form, csrf_enabled=False)
        # return self.render_json(code=-1, data = form.form2dict())
        if form.validate_on_submit():
            # create space
            space_new = SpaceModel()
            data = form.form2dict()
            id = space_new.add(data)
            if not id:
                return self.render_json(code=-1)

            current_app.logger.info(request.json)
            # create group
            data['role'] = OWNER
            members = [data]
            MemberModel(group_id=id).update_group(members=members)
            return self.render_json(data=space_new.item())
        else:
            return self.render_json(code=-1, message=form.errors)
コード例 #8
0
ファイル: space.py プロジェクト: wenfy2018/walle-web
    def item(self, space_id):
        """
        获取某个用户组

        :param id:
        :return:
        """

        space_model = SpaceModel(id=space_id)
        space_info = space_model.item()
        if not space_info:
            return self.render_json(code=-1)
        return self.render_json(data=space_info)
コード例 #9
0
ファイル: space.py プロジェクト: wenfy2018/walle-web
    def delete(self, space_id):
        """
        remove an environment
        /environment/<int:id>

        :return:
        """
        super(SpaceAPI, self).delete()

        space_model = SpaceModel(id=space_id)
        space_model.remove(space_id)

        return self.render_json(message='')
コード例 #10
0
ファイル: space.py プロジェクト: coco413/walle-web
    def item(self, space_id):
        """
        获取某个用户组

        :param id:
        :return:
        """

        space_model = SpaceModel(id=space_id)
        space_info = space_model.item()
        if not space_info:
            return self.render_json(code=-1)
        return self.render_json(data=space_info)
コード例 #11
0
ファイル: space.py プロジェクト: coco413/walle-web
    def delete(self, space_id):
        """
        remove an environment
        /environment/<int:id>

        :return:
        """
        super(SpaceAPI, self).delete()

        space_model = SpaceModel(id=space_id)
        space_model.remove(space_id)

        return self.render_json(message='')
コード例 #12
0
ファイル: space.py プロジェクト: ye854526102/walle-web
    def list(self, space_id=None):
        """
        fetch space list

        :return:
        """
        page = int(request.args.get('page', 0))
        page = page - 1 if page else 0
        size = int(request.args.get('size', 10))
        kw = request.values.get('kw', '')

        space_model = SpaceModel()
        space_list, count = space_model.list(page=page, size=size, kw=kw)
        return self.list_json(list=space_list, count=count, enable_create=permission.enable_role(OWNER))
コード例 #13
0
ファイル: space.py プロジェクト: coco413/walle-web
    def list(self, space_id=None):
        """
        fetch space list

        :return:
        """
        page = int(request.args.get('page', 0))
        page = page - 1 if page else 0
        size = int(request.args.get('size', 10))
        kw = request.values.get('kw', '')

        space_model = SpaceModel()
        space_list, count = space_model.list(page=page, size=size, kw=kw)
        return self.list_json(list=space_list, count=count, enable_create=permission.enable_role(OWNER))
コード例 #14
0
ファイル: space.py プロジェクト: vissssa/walle-web
    def update(self, space_id):
        form = SpaceForm(request.form, csrf_enabled=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)

            # a new type to update a model
            ret = space.update(data)
            # create group
            if 'members' in request.form:
                MemberModel(group_id=space_id).update_group(members=json.loads(request.form['members']))
            return self.render_json(data=space.item())
        else:
            return self.render_json(code=-1, message=form.errors)
コード例 #15
0
ファイル: space.py プロジェクト: heartshare/walle-web
    def update(self, space_id):
        form = SpaceForm(request.form, csrf=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)

            # a new type to update a model
            ret = space.update(data)
            # create group
            if 'members' in request.form:
                MemberModel(group_id=space_id).update_group(members=json.loads(request.form['members']))
            return self.render_json(data=space.item())
        else:
            return self.render_error(code=Code.form_error, message=form.errors)
コード例 #16
0
ファイル: deployer.py プロジェクト: yangbinnnn/walle-web
    def end(self, success=True, update_status=True):
        if update_status:
            status = TaskModel.status_success if success else TaskModel.status_fail
            current_app.logger.info('success:%s, status:%s' %
                                    (success, status))
            TaskModel().get_by_id(self.task_id).update({
                'status':
                status,
                'link_id':
                self.release_version,
                'ex_link_id':
                self.previous_release_version,
            })

            space_id = self.project_info['space_id']
            space_info = SpaceModel(id=space_id).item()
            task_url = Notice.task_url(project_space=space_info['name'],
                                       task_id=self.task_id)
            notice_info = {
                'title': '',
                'username': current_user.username,
                'project_name': self.project_info['name'],
                'task_url': task_url,
                'task_id': self.task_id,
                'task_title': self.taskMdl.get('name'),
                'task_name': self.taskMdl.get('name'),
                'branch': self.taskMdl.get('branch'),
                'commit': self.taskMdl.get('commit_id'),
                'tag': self.taskMdl.get('tag'),
                'repo_mode': self.project_info['repo_mode'],
            }
            notice = Notice.create(self.project_info['notice_type'])
            if success:
                notice_info['title'] = '上线部署成功'
                notice.deploy_task(project_info=self.project_info,
                                   notice_info=notice_info)
            else:
                notice_info['title'] = '上线部署失败'
                notice.deploy_task(project_info=self.project_info,
                                   notice_info=notice_info)

        # 清理本地
        self.cleanup_local()
        if success:
            emit('success', {
                'event': 'finish',
                'data': {
                    'message': '部署完成,辛苦了,为你的努力喝彩!'
                }
            },
                 room=self.task_id)
        else:
            emit('fail', {
                'event': 'finish',
                'data': {
                    'message': Code.code_msg[Code.deploy_fail]
                }
            },
                 room=self.task_id)
コード例 #17
0
    def update(self, space_id):
        form = SpaceForm(request.form, csrf=False)
        form.set_id(space_id)
        if form.validate_on_submit():
            space = SpaceModel().get_by_id(space_id)
            data = form.form2dict()
            current_app.logger.info(data)

            # a new type to update a model
            ret = space.update(data)
            # create group
            member = {"user_id": data['user_id'], "role": OWNER}
            if 'members' in request.form:
                members = json.loads(request.form['members'])
                members.append(member)
            MemberModel(group_id=space_id).update_group(members=members)
            return self.render_json(data=space.item())
        else:
            return self.render_error(code=Code.form_error, message=form.errors)
コード例 #18
0
ファイル: task.py プロジェクト: yangbinnnn/walle-web
    def post(self):
        """
        create a task
        /task/
        :return:
        """
        super(TaskAPI, self).post()

        form = TaskForm(request.form, csrf=False)
        if form.validate_on_submit():
            task_new = TaskModel()
            data = form.form2dict()
            task_new_info = task_new.add(data)
            if not task_new_info:
                return self.render_json(code=-1)

            # 待审核
            try:
                if task_new_info['status'] == TaskModel.status_new:
                    project_info = ProjectModel(
                        id=task_new_info['project_id']).item()
                    space_id = project_info['space_id']
                    space_info = SpaceModel(id=space_id).item()
                    task_url = Notice.task_url(
                        project_space=space_info['name'],
                        task_id=task_new_info['id'])
                    notice_info = {
                        'title': '新上线单需要审核',
                        'username': current_user.username,
                        'project_name': project_info['name'],
                        'task_id': task_new_info['id'],
                        'task_url': task_url,
                        'task_name': task_new_info['name'],
                        'branch': task_new_info['branch'],
                        'commit': task_new_info['commit_id'],
                        'tag': task_new_info['tag'],
                        'repo_mode': project_info['repo_mode'],
                    }
                    Notice.create(Notice.by_dingding).audit_task(
                        project_info, notice_info)
            except:
                pass

            return self.render_json(data=task_new_info)
        else:
            return self.render_error(code=Code.form_error, message=form.errors)