Пример #1
0
    def post(self, request, enterprise_id, *args, **kwargs):

        tenant_name = request.data.get("tenant_name", None)
        user_name = request.data.get("user_name", None)
        email = request.data.get("email", None)
        password = request.data.get("password", None)
        re_password = request.data.get("re_password", None)
        role_ids = request.data.get("role_ids", None)
        phone = request.data.get("phone", None)
        real_name = request.data.get("real_name", None)
        tenant = team_services.get_tenant_by_tenant_name(tenant_name)
        if len(password) < 8:
            result = general_message(400, "len error", "密码长度最少为8位")
            return Response(result)
        # check user info
        is_pass, msg = user_services.check_params(user_name, email, password,
                                                  re_password,
                                                  request.user.enterprise_id)
        if not is_pass:
            result = general_message(403, "user information is not passed",
                                     msg)
            return Response(result)
        client_ip = user_services.get_client_ip(request)
        enterprise = enterprise_services.get_enterprise_by_enterprise_id(
            enterprise_id)
        # create user
        oauth_instance, _ = user_services.check_user_is_enterprise_center_user(
            request.user.user_id)

        if oauth_instance:
            user = user_services.create_enterprise_center_user_set_password(
                user_name, email, password, "admin add", enterprise, client_ip,
                phone, real_name, oauth_instance)
        else:
            user = user_services.create_user_set_password(
                user_name, email, password, "admin add", enterprise, client_ip,
                phone, real_name)
        result = general_message(200, "success", "添加用户成功")
        if tenant:
            create_perm_param = {
                "user_id": user.user_id,
                "tenant_id": tenant.ID,
                "identity": "",
                "enterprise_id": enterprise.ID,
            }
            team_repo.create_team_perms(**create_perm_param)
            if role_ids:
                user_kind_role_service.update_user_roles(
                    kind="team",
                    kind_id=tenant.tenant_id,
                    user=user,
                    role_ids=role_ids)
                user.is_active = True
                user.save()
                result = general_message(200, "success", "添加用户成功")
        return Response(result)
Пример #2
0
 def post(self, request, enterprise_id, *args, **kwargs):
     tenant_name = request.data.get("tenant_name", None)
     user_name = request.data.get("user_name", None)
     email = request.data.get("email", None)
     password = request.data.get("password", None)
     re_password = request.data.get("re_password", None)
     role_ids = request.data.get("role_ids", None)
     if len(password) < 8:
         result = general_message(400, "len error", "密码长度最少为8位")
         return Response(result)
         # 校验用户信息
     is_pass, msg = user_services.check_params(user_name, email, password,
                                               re_password)
     if not is_pass:
         result = general_message(403, "user information is not passed",
                                  msg)
         return Response(result)
     client_ip = user_services.get_client_ip(request)
     enterprise = enterprise_services.get_enterprise_by_enterprise_id(
         enterprise_id)
     # 创建用户
     user = user_services.create_user_set_password(user_name, email,
                                                   password, "admin add",
                                                   enterprise, client_ip)
     result = general_message(200, "success", "添加用户成功")
     if role_ids:
         try:
             role_id_list = [int(id) for id in role_ids.split(",")]
         except Exception as e:
             logger.exception(e)
             code = 400
             result = general_message(code, "params is empty", "参数格式不正确")
             return Response(result, status=code)
         for id in role_id_list:
             if id not in team_services.get_all_team_role_id(
                     tenant_name=tenant_name):
                 code = 400
                 result = general_message(code, "The role does not exist",
                                          "该角色在团队中不存在")
                 return Response(result, status=code)
         # 创建用户团队关系表
         if tenant_name:
             team_services.create_tenant_role(user_id=user.user_id,
                                              tenant_name=tenant_name,
                                              role_id_list=role_id_list)
         user.is_active = True
         user.save()
         result = general_message(200, "success", "添加用户成功")
     return Response(result)
Пример #3
0
    def post(self, request, *args, **kwargs):
        """
        parameters:
            - name: tenant_name
              description: 租户名称
              required: true
              type: string
              paramType: path
            - name: user_name
              description: 用户名
              required: true
              type: string
              paramType: form
            - name: phone
              description: 手机号
              required: true
              type: string
              paramType: form
            - name: email
              description: 邮件地址
              required: true
              type: string
              paramType: form
            - name: password
              description: 密码
              required: true
              type: string
              paramType: form
            - name: re_password
              description: 重复密码
              required: true
              type: string
              paramType: form
            - name: identity
              description: 用户在租户的身份
              required: true
              type: string
              paramType: form

        """
        tenant_name = request.data.get("tenant_name", None)
        user_name = request.data.get("user_name", None)
        email = request.data.get("email", None)
        password = request.data.get("password", None)
        re_password = request.data.get("re_password", None)
        role_ids = request.data.get("role_ids", None)
        if len(password) < 8:
            result = general_message(400, "len error", "密码长度最少为8位")
            return Response(result)
        if not tenant_name:
            result = general_message(400, "not tenant", "团队不能为空")
            return Response(result)
        if role_ids and tenant_name:
            team = team_services.get_tenant_by_tenant_name(tenant_name)
            if not team:
                raise ServiceHandleException(msg_show="团队不存在",
                                             msg="no found team",
                                             status_code=404)
            # 校验用户信息
            user_services.check_params(user_name, email, password, re_password,
                                       self.user.enterprise_id)
            client_ip = user_services.get_client_ip(request)
            enterprise = console_enterprise_service.get_enterprise_by_enterprise_id(
                self.user.enterprise_id)
            # 创建用户
            user = user_services.create_user_set_password(
                user_name, email, password, "admin add", enterprise, client_ip)
            # 创建用户团队关系表
            team_services.add_user_role_to_team(tenant=team,
                                                user_ids=[user.user_id],
                                                role_ids=role_ids)
            user.is_active = True
            user.save()
            result = general_message(200, "success", "添加用户成功")
        else:
            result = general_message(400, "not role", "创建用户时角色不能为空")
        return Response(result)