MM-63619: improve Groups API error semantics (#30961)
Instead of 5xx errors, return `http.StatusInvalidRequest` when adding or deleting invalid user ids from groups. Fixes: https://mattermost.atlassian.net/browse/MM-63619
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
935b8902a8
Коммит
d80d575f6c
@@ -274,13 +274,13 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = model.NewAppError("Api4.patchGroup", "api.ldap_groups.existing_reserved_name_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
//check if a user already has this group name
|
||||
// check if a user already has this group name
|
||||
user, _ := c.App.GetUserByUsername(*groupPatch.Name)
|
||||
if user != nil {
|
||||
c.Err = model.NewAppError("Api4.patchGroup", "api.ldap_groups.existing_user_name_error", nil, "", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
//check if a mentionable group already has this name
|
||||
// check if a mentionable group already has this name
|
||||
searchOpts := model.GroupSearchOpts{
|
||||
FilterAllowReference: true,
|
||||
}
|
||||
@@ -914,7 +914,6 @@ func getGroupsByTeamCommon(c *Context, r *http.Request) ([]byte, *model.AppError
|
||||
Groups: groups,
|
||||
Count: totalCount,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("Api4.getGroupsByTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
@@ -1346,6 +1345,13 @@ func addGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, userID := range newMembers.UserIds {
|
||||
if !model.IsValidId(userID) {
|
||||
c.SetInvalidParamWithDetails("user_id", fmt.Sprintf("UserID %s is invalid", userID))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
auditRec := c.MakeAuditRecord("addGroupMembers", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
audit.AddEventParameter(auditRec, "addGroupMembers_userids", newMembers.UserIds)
|
||||
@@ -1414,6 +1420,13 @@ func deleteGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, userID := range deleteBody.UserIds {
|
||||
if !model.IsValidId(userID) {
|
||||
c.SetInvalidParamWithDetails("user_id", fmt.Sprintf("UserID %s is invalid", userID))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
auditRec := c.MakeAuditRecord("deleteGroupMembers", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
audit.AddEventParameter(auditRec, "deleteGroupMembers_userids", deleteBody.UserIds)
|
||||
|
||||
Ссылка в новой задаче
Block a user