add client adding logic
This commit is contained in:
@@ -202,6 +202,7 @@ func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Reques
|
||||
ctx := request.Context()
|
||||
|
||||
var group Group
|
||||
group.Id = affectedGroupId
|
||||
groupPtr, err := CacheGetGroup(affectedGroupId)
|
||||
if err == nil {
|
||||
group = *groupPtr
|
||||
@@ -225,10 +226,28 @@ func HttpHandleGroupAddClient(response http.ResponseWriter, request *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
usersToAdd := strings.SplitN(usersToAddString, ",", remainingUsersCount+1)
|
||||
if len(usersToAdd) == 0 {
|
||||
userIdStrings := strings.SplitN(usersToAddString, ",", remainingUsersCount+1)
|
||||
if len(userIdStrings) == 0 {
|
||||
http.Error(response, "no users to add", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
clientIds := make([]uint32, 0, len(userIdStrings))
|
||||
for _, s := range userIdStrings {
|
||||
id, err := ConvertStringUint32(strings.TrimSpace(s))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
clientIds = append(clientIds, id)
|
||||
}
|
||||
if len(clientIds) == 0 {
|
||||
http.Error(response, "no valid users", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
err = DbAddClientsToGroup(ctx, group.Id, clientIds)
|
||||
if err != nil {
|
||||
http.Error(response, "internal server error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user