コード例 #1
0
ファイル: service_share.py プロジェクト: sunshine2995/console
 def post(self, request, team_name, group_id, *args, **kwargs):
     """
     生成分享订单,会验证是否能够分享
     ---
     parameter:
         - name: team_name
           description: 团队名
           required: true
           type: string
           paramType: path
         - name: group_id
           description: 应用组id
           required: true
           type: string
           paramType: path
     """
     try:
         if group_id == "-1":
             code = 400
             result = general_message(400, "group id error", "未分组应用不可分享")
             return Response(result, status=code)
         team_id = self.team.tenant_id
         group_count = group_repo.get_group_count_by_team_id_and_group_id(team_id=team_id, group_id=group_id)
         if group_count == 0:
             code = 400
             result = general_message(code, "group is not yours!", "这个应用组不是你的!")
             return Response(result, status=code)
         # 判断是否满足分享条件
         data = share_service.check_service_source(
             team=self.team,
             team_name=team_name,
             group_id=group_id,
             region_name=self.response_region)
         if data and data["code"] == 400:
             return Response(data, status=data["code"])
         # 判断是否有未完成订单
         share_record = share_service.get_service_share_record_by_group_id(group_id)
         if share_record:
             if not share_record.is_success and share_record.step < 3:
                 result = general_message(20021, "share record not complete", "之前有分享流程未完成",
                                          bean=share_record.to_dict())
                 return Response(result, status=200)
         fields_dict = {
             "group_share_id": make_uuid(),
             "group_id": group_id,
             "team_name": team_name,
             "is_success": False,
             "step": 1,
             "create_time": datetime.datetime.now(),
             "update_time": datetime.datetime.now()
         }
         service_share_record = share_service.create_service_share_record(**fields_dict)
         result = general_message(200, "create success", "创建成功", bean=service_share_record.to_dict())
         return Response(result, status=200)
     except Exception as e:
         logger.exception(e)
         result = error_message(e.message)
         return Response(result, status=500)
コード例 #2
0
    def post(self, request, team_name, plugin_id, *args, **kwargs):
        """
        创建分享插件记录
        ---
        parameter:
            - name: team_name
              description: 团队名
              required: true
              type: string
              paramType: path
            - name: plugin_id
              description: 插件id
              required: true
              type: string
              paramType: path
            - name: build_version
              description: 构建版本
              required: true
              type: string
              paramType: path
        """
        team_id = self.team.tenant_id

        plugin = plugin_repo.get_plugin_by_plugin_id(team_id, plugin_id)
        if not plugin:
            return Response(general_message(404, 'plugin not exist', '插件不存在'))

        share_record = share_service.get_service_share_record_by_group_id(
            plugin_id)
        if share_record:
            if not share_record.is_success and share_record.step < 3:
                result = general_message(20021,
                                         "share not complete",
                                         "有分享流程未完成",
                                         bean=share_record.to_dict())
                return Response(result, status=200)

        status, msg, msg_show = market_plugin_service.check_plugin_share_condition(
            self.team, plugin_id, self.response_region)
        if status != 200:
            return Response(general_message(status, msg, msg_show),
                            status=status)

        record = {
            "group_share_id": make_uuid(),
            "group_id": plugin_id,
            "team_name": team_name,
            "is_success": False,
            "step": 1,
        }
        service_share_record = share_service.create_service_share_record(
            **record)
        result = general_message(200,
                                 "create success",
                                 "创建成功",
                                 bean=service_share_record.to_dict())
        return Response(result, status=200)