コード例 #1
0
 def put(self, request, team_name, *args, **kwargs):
     """管理员审核用户"""
     try:
         # 判断角色
         identity_list = team_services.get_user_perm_identitys_in_permtenant(
             user_id=request.user.user_id, tenant_name=team_name)
         if "owner" or "admin" in identity_list:
             user_id = request.data.get("user_id")
             action = request.data.get("action")
             join = apply_repo.get_applicants_by_id_team_name(
                 user_id=user_id, team_name=team_name)
             if action is True:
                 join.update(is_pass=1)
                 team = team_repo.get_team_by_team_name(team_name=team_name)
                 team_services.add_user_to_team_by_viewer(tenant=team,
                                                          user_id=user_id)
                 return Response(general_message(200, "join success",
                                                 "加入成功"),
                                 status=200)
             else:
                 join.update(is_pass=2)
                 return Response(general_message(200, "join rejected",
                                                 "拒绝成功"),
                                 status=200)
     except Exception as e:
         logger.exception(e)
         result = error_message(e.message)
         return Response(result, status=result["code"])
コード例 #2
0
 def create_applicants(self, user_id, team_name):
     applicant = apply_repo.get_applicants_by_id_team_name(user_id=user_id, team_name=team_name)
     if not applicant:
         team = team_repo.get_team_by_team_name(team_name=team_name)
         user = user_repo.get_by_user_id(user_id=user_id)
         info = {
             "user_id": user_id,
             "user_name": user.get_username(),
             "team_id": team.tenant_id,
             "team_name": team_name,
             "team_alias": team.tenant_alias,
             "apply_time": datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
         }
         return apply_repo.create_apply_info(**info)
     if applicant[0].is_pass == 0:
         raise ServiceHandleException(msg="already applied for it", msg_show="该团队已经申请过")
     if applicant[0].is_pass == 1:
         teams = team_repo.get_tenants_by_user_id(user_id)
         tnames = [team.tenant_name for team in teams]
         if team_name in tnames:
             raise ServiceHandleException(msg="already join for it", msg_show="您已加入该团队")
     applicant[0].apply_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
     applicant[0].is_pass = 0
     applicant[0].save()
     return applicant
コード例 #3
0
 def put(self, request, team_name, *args, **kwargs):
     """管理员审核用户"""
     user_id = request.data.get("user_id")
     action = request.data.get("action")
     role_ids = request.data.get("role_ids")
     join = apply_repo.get_applicants_by_id_team_name(user_id=user_id,
                                                      team_name=team_name)
     if action is True:
         join.update(is_pass=1)
         team = team_repo.get_team_by_team_name(team_name=team_name)
         team_services.add_user_to_team(tenant=team,
                                        user_id=user_id,
                                        role_ids=role_ids)
         # 发送通知
         info = "同意"
         self.send_user_message_for_apply_info(user_id=user_id,
                                               team_name=team.tenant_name,
                                               info=info)
         return Response(general_message(200, "join success", "加入成功"),
                         status=200)
     else:
         join.update(is_pass=2)
         info = "拒绝"
         self.send_user_message_for_apply_info(user_id=user_id,
                                               team_name=team_name,
                                               info=info)
         return Response(general_message(200, "join rejected", "拒绝成功"),
                         status=200)
コード例 #4
0
 def create_applicants(self, user_id, team_name):
     applicant = apply_repo.get_applicants_by_id_team_name(user_id=user_id, team_name=team_name)
     if not applicant:
         team = team_repo.get_team_by_team_name(team_name=team_name)
         user = user_repo.get_by_user_id(user_id=user_id)
         info = {
             "user_id": user_id,
             "user_name": user.get_username(),
             "team_id": team.tenant_id,
             "team_name": team_name,
             "team_alias": team.tenant_alias,
             "apply_time": datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
         }
         apply_repo.create_apply_info(**info)
         return info
     else:
         return None
コード例 #5
0
 def delete_applicants(self, user_id, team_name):
     applicant = apply_repo.get_applicants_by_id_team_name(
         user_id=user_id, team_name=team_name)
     return applicant.delete()