MCPcopy Create free account
hub / github.com/53AI/53AIHub / BatchAddInternalUsers

Function BatchAddInternalUsers

api/controller/user.go:1019–1076  ·  view source on GitHub ↗

BatchAddInternalUsers adds multiple internal users @Summary Batch add internal users @Description Add multiple internal users to the system @Tags User @Accept json @Produce json @Security BearerAuth @Param request body BatchAddInternalUserRequest true "Batch internal user data" @Success 200 {object}

(c *gin.Context)

Source from the content-addressed store, hash-verified

1017// @Failure 500 {object} model.CommonResponse "System error"
1018// @Router /api/users/internal/batch [post]
1019func BatchAddInternalUsers(c *gin.Context) {
1020 var batchRequest BatchAddInternalUserRequest
1021 if err := c.ShouldBindJSON(&batchRequest); err != nil {
1022 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(err))
1023 return
1024 }
1025
1026 eid := config.GetEID(c)
1027 if eid <= 0 {
1028 c.JSON(http.StatusOK, model.ParamError.ToNewErrorResponse(model.InvalidEnterpriseID))
1029 return
1030 }
1031
1032 nicknames := make([]string, len(batchRequest.Users))
1033 users := make([]service.InternalUserInfo, len(batchRequest.Users))
1034 for i, user := range batchRequest.Users {
1035 users[i] = service.InternalUserInfo{
1036 Username: user.Username,
1037 Nickname: user.Nickname,
1038 Dids: user.Dids,
1039 Password: user.Password,
1040 }
1041 nicknames[i] = user.Nickname
1042 }
1043
1044 userService := service.UserService{}
1045 result, err := userService.BatchAddInternalUsers(eid, users)
1046 if err != nil {
1047 c.JSON(http.StatusInternalServerError, model.DBError.ToResponse(err))
1048 return
1049 }
1050
1051 if len(result.Failed) > 0 && len(result.Success) == 0 {
1052 c.JSON(http.StatusOK, model.ParamError.ToResponse(BatchAddInternalUserResponse{
1053 Success: result.Success,
1054 Failed: result.Failed,
1055 }))
1056 return
1057 }
1058
1059 model.LogEntityChange(
1060 fmt.Sprintf("账号【%s】", strings.Join(nicknames, "; ")),
1061 model.SystemLogActionCreate,
1062 eid,
1063 config.GetUserId(c),
1064 config.GetUserNickname(c),
1065 model.SystemLogModuleInternalUser,
1066 nil,
1067 nil,
1068 utils.GetClientIP(c),
1069 nil,
1070 )
1071
1072 c.JSON(http.StatusOK, model.Success.ToResponse(BatchAddInternalUserResponse{
1073 Success: result.Success,
1074 Failed: result.Failed,
1075 }))
1076}

Callers

nothing calls this directly

Calls 4

BatchAddInternalUsersMethod · 0.95
ToResponseMethod · 0.80
GetEIDMethod · 0.80
ToNewErrorResponseMethod · 0.80

Tested by

no test coverage detected