[MM-45991] Check and return JSON errors (#20735)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fdee1df6fe
Коммит
1738bd6e92
335
api4/group.go
335
api4/group.go
@@ -99,11 +99,11 @@ func getGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
group, err := c.App.GetGroup(c.Params.GroupId, &model.GetGroupOpts{
|
||||
group, appErr := c.App.GetGroup(c.Params.GroupId, &model.GetGroupOpts{
|
||||
IncludeMemberCount: c.Params.IncludeMemberCount,
|
||||
})
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -114,15 +114,15 @@ func getGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if lcErr := licensedAndConfiguredForGroupBySource(c.App, group.Source); lcErr != nil {
|
||||
lcErr.Where = "Api4.getGroup"
|
||||
c.Err = lcErr
|
||||
if appErr := licensedAndConfiguredForGroupBySource(c.App, group.Source); appErr != nil {
|
||||
appErr.Where = "Api4.getGroup"
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(group)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroup", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(group)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroup", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -131,8 +131,8 @@ func getGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func createGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var group *model.GroupWithUserIds
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&group); jsonErr != nil {
|
||||
c.SetInvalidParamWithErr("group", jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&group); err != nil {
|
||||
c.SetInvalidParamWithErr("group", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -141,9 +141,9 @@ func createGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if lcErr := licensedAndConfiguredForGroupBySource(c.App, group.Source); lcErr != nil {
|
||||
lcErr.Where = "Api4.createGroup"
|
||||
c.Err = lcErr
|
||||
if appErr := licensedAndConfiguredForGroupBySource(c.App, group.Source); appErr != nil {
|
||||
appErr.Where = "Api4.createGroup"
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -166,17 +166,17 @@ func createGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddEventParameter("group", group)
|
||||
|
||||
newGroup, err := c.App.CreateGroupWithUserIds(group)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
newGroup, appErr := c.App.CreateGroupWithUserIds(group)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.AddEventResultState(newGroup)
|
||||
auditRec.AddEventObjectType("group")
|
||||
js, jsonErr := json.Marshal(newGroup)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("createGroup", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(newGroup)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("createGroup", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
@@ -190,15 +190,16 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
group, err := c.App.GetGroup(c.Params.GroupId, nil)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
group, appErr := c.App.GetGroup(c.Params.GroupId, nil)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
if lcErr := licensedAndConfiguredForGroupBySource(c.App, group.Source); lcErr != nil {
|
||||
lcErr.Where = "Api4.patchGroup"
|
||||
c.Err = lcErr
|
||||
appErr = licensedAndConfiguredForGroupBySource(c.App, group.Source)
|
||||
if appErr != nil {
|
||||
appErr.Where = "Api4.patchGroup"
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -214,8 +215,8 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var groupPatch model.GroupPatch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&groupPatch); jsonErr != nil {
|
||||
c.SetInvalidParamWithErr("group", jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&groupPatch); err != nil {
|
||||
c.SetInvalidParamWithErr("group", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -257,17 +258,17 @@ func patchGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
group.Patch(&groupPatch)
|
||||
|
||||
group, err = c.App.UpdateGroup(group)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
group, appErr = c.App.UpdateGroup(group)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
auditRec.AddEventResultState(group)
|
||||
auditRec.AddEventObjectType("group")
|
||||
|
||||
b, marshalErr := json.Marshal(group)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.patchGroup", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(group)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.patchGroup", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -295,13 +296,13 @@ func linkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.createGroupSyncable", "api.io_error", nil, err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("Api4.createGroupSyncable", "api.io_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
group, groupErr := c.App.GetGroup(c.Params.GroupId, nil)
|
||||
if groupErr != nil {
|
||||
c.Err = groupErr
|
||||
group, appErr := c.App.GetGroup(c.Params.GroupId, nil)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -319,7 +320,7 @@ func linkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var patch *model.GroupSyncablePatch
|
||||
err = json.Unmarshal(body, &patch)
|
||||
if err != nil || patch == nil {
|
||||
c.SetInvalidParam(fmt.Sprintf("Group%s", syncableType.String()))
|
||||
c.SetInvalidParamWithErr(fmt.Sprintf("Group%s", syncableType), err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -330,7 +331,7 @@ func linkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
appErr := verifyLinkUnlinkPermission(c, syncableType, syncableID)
|
||||
appErr = verifyLinkUnlinkPermission(c, syncableType, syncableID)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
@@ -357,9 +358,9 @@ func linkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
||||
b, marshalErr := json.Marshal(groupSyncable)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.createGroupSyncable", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(groupSyncable)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.createGroupSyncable", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
@@ -394,15 +395,15 @@ func getGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
groupSyncable, err := c.App.GetGroupSyncable(c.Params.GroupId, syncableID, syncableType)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
groupSyncable, appErr := c.App.GetGroupSyncable(c.Params.GroupId, syncableID, syncableType)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(groupSyncable)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupSyncable", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(groupSyncable)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupSyncable", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -431,15 +432,15 @@ func getGroupSyncables(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
groupSyncables, err := c.App.GetGroupSyncables(c.Params.GroupId, syncableType)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
groupSyncables, appErr := c.App.GetGroupSyncables(c.Params.GroupId, syncableType)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(groupSyncables)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupSyncables", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(groupSyncables)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupSyncables", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -466,7 +467,7 @@ func patchGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.patchGroupSyncable", "api.io_error", nil, err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("Api4.patchGroupSyncable", "api.io_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -479,7 +480,7 @@ func patchGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var patch *model.GroupSyncablePatch
|
||||
err = json.Unmarshal(body, &patch)
|
||||
if err != nil || patch == nil {
|
||||
c.SetInvalidParam(fmt.Sprintf("Group[%s]Patch", syncableType.String()))
|
||||
c.SetInvalidParamWithErr(fmt.Sprintf("Group[%s]Patch", syncableType), err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -518,9 +519,9 @@ func patchGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.App.SyncRolesAndMembership(c.AppContext, syncableID, syncableType, false)
|
||||
})
|
||||
|
||||
b, marshalErr := json.Marshal(groupSyncable)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.patchGroupSyncable", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(groupSyncable)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.patchGroupSyncable", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
@@ -556,15 +557,15 @@ func unlinkGroupSyncable(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := verifyLinkUnlinkPermission(c, syncableType, syncableID)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
appErr := verifyLinkUnlinkPermission(c, syncableType, syncableID)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
_, err = c.App.DeleteGroupSyncable(c.Params.GroupId, syncableID, syncableType)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
_, appErr = c.App.DeleteGroupSyncable(c.Params.GroupId, syncableID, syncableType)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -610,15 +611,16 @@ func getGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
group, err := c.App.GetGroup(c.Params.GroupId, nil)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
group, appErr := c.App.GetGroup(c.Params.GroupId, nil)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
if lcErr := licensedAndConfiguredForGroupBySource(c.App, group.Source); lcErr != nil {
|
||||
lcErr.Where = "Api4.getGroupMembers"
|
||||
c.Err = lcErr
|
||||
appErr = licensedAndConfiguredForGroupBySource(c.App, group.Source)
|
||||
if appErr != nil {
|
||||
appErr.Where = "Api4.getGroupMembers"
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -627,21 +629,21 @@ func getGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
members, count, err := c.App.GetGroupMemberUsersPage(c.Params.GroupId, c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
members, count, appErr := c.App.GetGroupMemberUsersPage(c.Params.GroupId, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(struct {
|
||||
b, err := json.Marshal(struct {
|
||||
Members []*model.User `json:"members"`
|
||||
Count int `json:"total_member_count"`
|
||||
}{
|
||||
Members: members,
|
||||
Count: count,
|
||||
})
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupMembers", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -665,18 +667,18 @@ func getGroupStats(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
groupID := c.Params.GroupId
|
||||
count, err := c.App.GetGroupMemberCount(groupID)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
count, appErr := c.App.GetGroupMemberCount(groupID)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(model.GroupStats{
|
||||
b, err := json.Marshal(model.GroupStats{
|
||||
GroupID: groupID,
|
||||
TotalMemberCount: count,
|
||||
})
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupStats", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupStats", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -699,15 +701,15 @@ func getGroupsByUserId(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
groups, err := c.App.GetGroupsByUserId(c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
groups, appErr := c.App.GetGroupsByUserId(c.Params.UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(groups)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupsByUserId", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(groups)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupsByUserId", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -725,11 +727,12 @@ func getGroupsByChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
channel, err := c.App.GetChannel(c.AppContext, c.Params.ChannelId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
channel, appErr := c.App.GetChannel(c.AppContext, c.Params.ChannelId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
var permission *model.Permission
|
||||
if channel.Type == model.ChannelTypePrivate {
|
||||
permission = model.PermissionReadPrivateChannelGroups
|
||||
@@ -750,22 +753,21 @@ func getGroupsByChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
opts.PageOpts = &model.PageOpts{Page: c.Params.Page, PerPage: c.Params.PerPage}
|
||||
}
|
||||
|
||||
groups, totalCount, err := c.App.GetGroupsByChannel(c.Params.ChannelId, opts)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
groups, totalCount, appErr := c.App.GetGroupsByChannel(c.Params.ChannelId, opts)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(struct {
|
||||
b, err := json.Marshal(struct {
|
||||
Groups []*model.GroupWithSchemeAdmin `json:"groups"`
|
||||
Count int `json:"total_group_count"`
|
||||
}{
|
||||
Groups: groups,
|
||||
Count: totalCount,
|
||||
})
|
||||
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupsByChannel", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupsByChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -791,13 +793,13 @@ func getGroupsByTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
opts.PageOpts = &model.PageOpts{Page: c.Params.Page, PerPage: c.Params.PerPage}
|
||||
}
|
||||
|
||||
groups, totalCount, err := c.App.GetGroupsByTeam(c.Params.TeamId, opts)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
groups, totalCount, appErr := c.App.GetGroupsByTeam(c.Params.TeamId, opts)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(struct {
|
||||
b, err := json.Marshal(struct {
|
||||
Groups []*model.GroupWithSchemeAdmin `json:"groups"`
|
||||
Count int `json:"total_group_count"`
|
||||
}{
|
||||
@@ -805,8 +807,8 @@ func getGroupsByTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
Count: totalCount,
|
||||
})
|
||||
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupsByTeam", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupsByTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -833,20 +835,19 @@ func getGroupsAssociatedToChannelsByTeam(c *Context, w http.ResponseWriter, r *h
|
||||
opts.PageOpts = &model.PageOpts{Page: c.Params.Page, PerPage: c.Params.PerPage}
|
||||
}
|
||||
|
||||
groupsAssociatedByChannelID, err := c.App.GetGroupsAssociatedToChannelsByTeam(c.Params.TeamId, opts)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
groupsAssociatedByChannelID, appErr := c.App.GetGroupsAssociatedToChannelsByTeam(c.Params.TeamId, opts)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(struct {
|
||||
b, err := json.Marshal(struct {
|
||||
GroupsAssociatedToChannels map[string][]*model.GroupWithSchemeAdmin `json:"groups"`
|
||||
}{
|
||||
GroupsAssociatedToChannels: groupsAssociatedByChannelID,
|
||||
})
|
||||
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupsAssociatedToChannelsByTeam", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroupsAssociatedToChannelsByTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -867,9 +868,9 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// If they specify the group_source as custom when the feature is disabled, throw an error
|
||||
if lcErr := licensedAndConfiguredForGroupBySource(c.App, source); lcErr != nil {
|
||||
lcErr.Where = "Api4.getGroups"
|
||||
c.Err = lcErr
|
||||
if appErr := licensedAndConfiguredForGroupBySource(c.App, source); appErr != nil {
|
||||
appErr.Where = "Api4.getGroups"
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -888,9 +889,9 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if teamID != "" {
|
||||
_, err := c.App.GetTeam(teamID)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
_, appErr := c.App.GetTeam(teamID)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -898,9 +899,9 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if channelID != "" {
|
||||
channel, err := c.App.GetChannel(c.AppContext, channelID)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
channel, appErr := c.App.GetChannel(c.AppContext, channelID)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
var permission *model.Permission
|
||||
@@ -918,39 +919,41 @@ func getGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
sinceString := r.URL.Query().Get("since")
|
||||
if sinceString != "" {
|
||||
since, parseError := strconv.ParseInt(sinceString, 10, 64)
|
||||
if parseError != nil {
|
||||
c.SetInvalidParam("since")
|
||||
since, err := strconv.ParseInt(sinceString, 10, 64)
|
||||
if err != nil {
|
||||
c.SetInvalidParamWithErr("since", err)
|
||||
return
|
||||
}
|
||||
opts.Since = since
|
||||
}
|
||||
|
||||
groups, err := c.App.GetGroups(c.Params.Page, c.Params.PerPage, opts)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
groups, appErr := c.App.GetGroups(c.Params.Page, c.Params.PerPage, opts)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
var b []byte
|
||||
var marshalErr error
|
||||
var (
|
||||
b []byte
|
||||
err error
|
||||
)
|
||||
if c.Params.IncludeTotalCount {
|
||||
totalCount, countErr := c.App.Srv().Store.Group().GroupCount()
|
||||
if countErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroups", "api.custom_groups.count_err", nil, countErr.Error(), http.StatusInternalServerError)
|
||||
totalCount, cerr := c.App.Srv().Store.Group().GroupCount()
|
||||
if cerr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroups", "api.custom_groups.count_err", nil, "", http.StatusInternalServerError).Wrap(cerr)
|
||||
return
|
||||
}
|
||||
gwc := &model.GroupsWithCount{
|
||||
Groups: groups,
|
||||
TotalCount: totalCount,
|
||||
}
|
||||
b, marshalErr = json.Marshal(gwc)
|
||||
b, err = json.Marshal(gwc)
|
||||
} else {
|
||||
b, marshalErr = json.Marshal(groups)
|
||||
b, err = json.Marshal(groups)
|
||||
}
|
||||
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroups", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getGroups", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1006,9 +1009,9 @@ func addGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
group, err := c.App.GetGroup(c.Params.GroupId, nil)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
group, appErr := c.App.GetGroup(c.Params.GroupId, nil)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1017,9 +1020,10 @@ func addGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if lcErr := licensedAndConfiguredForGroupBySource(c.App, model.GroupSourceCustom); lcErr != nil {
|
||||
lcErr.Where = "Api4.deleteGroup"
|
||||
c.Err = lcErr
|
||||
appErr = licensedAndConfiguredForGroupBySource(c.App, model.GroupSourceCustom)
|
||||
if appErr != nil {
|
||||
appErr.Where = "Api4.deleteGroup"
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1029,8 +1033,8 @@ func addGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var newMembers *model.GroupModifyMembers
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&newMembers); jsonErr != nil {
|
||||
c.SetInvalidParamWithErr("addGroupMembers", jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&newMembers); err != nil {
|
||||
c.SetInvalidParamWithErr("addGroupMembers", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1038,15 +1042,15 @@ func addGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddEventParameter("addGroupMembers", newMembers)
|
||||
|
||||
members, err := c.App.UpsertGroupMembers(c.Params.GroupId, newMembers.UserIds)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
members, appErr := c.App.UpsertGroupMembers(c.Params.GroupId, newMembers.UserIds)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(members)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.addGroupMembers", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(members)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.addGroupMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
@@ -1059,9 +1063,9 @@ func deleteGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
group, err := c.App.GetGroup(c.Params.GroupId, nil)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
group, appErr := c.App.GetGroup(c.Params.GroupId, nil)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1070,9 +1074,10 @@ func deleteGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if lcErr := licensedAndConfiguredForGroupBySource(c.App, model.GroupSourceCustom); lcErr != nil {
|
||||
lcErr.Where = "Api4.deleteGroup"
|
||||
c.Err = lcErr
|
||||
appErr = licensedAndConfiguredForGroupBySource(c.App, model.GroupSourceCustom)
|
||||
if appErr != nil {
|
||||
appErr.Where = "Api4.deleteGroup"
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1082,8 +1087,8 @@ func deleteGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var deleteBody *model.GroupModifyMembers
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&deleteBody); jsonErr != nil {
|
||||
c.SetInvalidParamWithErr("deleteGroupMembers", jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&deleteBody); err != nil {
|
||||
c.SetInvalidParamWithErr("deleteGroupMembers", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1091,15 +1096,15 @@ func deleteGroupMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddEventParameter("deleteGroupMembers", deleteBody)
|
||||
|
||||
members, err := c.App.DeleteGroupMembers(c.Params.GroupId, deleteBody.UserIds)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
members, appErr := c.App.DeleteGroupMembers(c.Params.GroupId, deleteBody.UserIds)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(members)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.addGroupMembers", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(members)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.addGroupMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
|
||||
Ссылка в новой задаче
Block a user