[MM-45991] Check and return JSON errors (#20735)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fdee1df6fe
Коммит
1738bd6e92
@@ -1891,23 +1891,23 @@ func channelMembersMinusGroupMembers(c *Context, w http.ResponseWriter, r *http.
|
||||
return
|
||||
}
|
||||
|
||||
users, totalCount, err := c.App.ChannelMembersMinusGroupMembers(
|
||||
users, totalCount, appErr := c.App.ChannelMembersMinusGroupMembers(
|
||||
c.Params.ChannelId,
|
||||
groupIDs,
|
||||
c.Params.Page,
|
||||
c.Params.PerPage,
|
||||
)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(&model.UsersWithGroupsAndCount{
|
||||
b, err := json.Marshal(&model.UsersWithGroupsAndCount{
|
||||
Users: users,
|
||||
Count: totalCount,
|
||||
})
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.channelMembersMinusGroupMembers", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.channelMembersMinusGroupMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1932,15 +1932,15 @@ func channelMemberCountsByGroup(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
|
||||
includeTimezones := r.URL.Query().Get("include_timezones") == "true"
|
||||
|
||||
channelMemberCounts, err := c.App.GetMemberCountsByGroup(app.WithMaster(context.Background()), c.Params.ChannelId, includeTimezones)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
channelMemberCounts, appErr := c.App.GetMemberCountsByGroup(app.WithMaster(context.Background()), c.Params.ChannelId, includeTimezones)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(channelMemberCounts)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.channelMemberCountsByGroup", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(channelMemberCounts)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.channelMemberCountsByGroup", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1963,21 +1963,21 @@ func getChannelModerations(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
|
||||
}
|
||||
|
||||
channelModerations, err := c.App.GetChannelModerationsForChannel(c.AppContext, channel)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
channelModerations, appErr := c.App.GetChannelModerationsForChannel(c.AppContext, channel)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(channelModerations)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getChannelModerations", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(channelModerations)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getChannelModerations", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2024,9 +2024,9 @@ func patchChannelModerations(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
auditRec.AddEventParameter("patch", channelModerationsPatch)
|
||||
|
||||
b, marshalErr := json.Marshal(channelModerations)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.patchChannelModerations", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(channelModerations)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.patchChannelModerations", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@ func getCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
categories, err := c.App.GetSidebarCategoriesForTeamForUser(c.AppContext, c.Params.UserId, c.Params.TeamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
categories, appErr := c.App.GetSidebarCategoriesForTeamForUser(c.AppContext, c.Params.UserId, c.Params.TeamId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
categoriesJSON, jsonErr := json.Marshal(categories)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getCategoriesForTeamForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
categoriesJSON, err := json.Marshal(categories)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getCategoriesForTeamForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -70,9 +70,9 @@ func createCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
|
||||
return
|
||||
}
|
||||
|
||||
categoryJSON, jsonErr := json.Marshal(category)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("createCategoryForTeamForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
categoryJSON, err := json.Marshal(category)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("createCategoryForTeamForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -92,13 +92,16 @@ func getCategoryOrderForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
|
||||
return
|
||||
}
|
||||
|
||||
order, err := c.App.GetSidebarCategoryOrder(c.AppContext, c.Params.UserId, c.Params.TeamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
order, appErr := c.App.GetSidebarCategoryOrder(c.AppContext, c.Params.UserId, c.Params.TeamId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
w.Write([]byte(model.ArrayToJSON(order)))
|
||||
err := json.NewEncoder(w).Encode(order)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func updateCategoryOrderForTeamForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -145,15 +148,15 @@ func getCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
categories, err := c.App.GetSidebarCategory(c.AppContext, c.Params.CategoryId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
categories, appErr := c.App.GetSidebarCategory(c.AppContext, c.Params.CategoryId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
categoriesJSON, jsonErr := json.Marshal(categories)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getCategoryForTeamForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
categoriesJSON, err := json.Marshal(categories)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getCategoryForTeamForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -199,9 +202,9 @@ func updateCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
|
||||
return
|
||||
}
|
||||
|
||||
categoriesJSON, jsonErr := json.Marshal(categories)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("updateCategoriesForTeamForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
categoriesJSON, err := json.Marshal(categories)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("updateCategoriesForTeamForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -210,12 +213,12 @@ func updateCategoriesForTeamForUser(c *Context, w http.ResponseWriter, r *http.R
|
||||
}
|
||||
|
||||
func validateSidebarCategory(c *Context, teamId, userId string, category *model.SidebarCategoryWithChannels) *model.AppError {
|
||||
channels, err := c.App.GetChannelsForTeamForUser(c.AppContext, teamId, userId, &model.ChannelSearchOpts{
|
||||
channels, appErr := c.App.GetChannelsForTeamForUser(c.AppContext, teamId, userId, &model.ChannelSearchOpts{
|
||||
IncludeDeleted: true,
|
||||
LastDeleteAt: 0,
|
||||
})
|
||||
if err != nil {
|
||||
return model.NewAppError("validateSidebarCategory", "api.invalid_channel", nil, err.Error(), http.StatusBadRequest)
|
||||
if appErr != nil {
|
||||
return model.NewAppError("validateSidebarCategory", "api.invalid_channel", nil, "", http.StatusBadRequest).Wrap(appErr)
|
||||
}
|
||||
|
||||
category.Channels = validateSidebarCategoryChannels(c, userId, category.Channels, channels)
|
||||
@@ -295,9 +298,9 @@ func updateCategoryForTeamForUser(c *Context, w http.ResponseWriter, r *http.Req
|
||||
return
|
||||
}
|
||||
|
||||
categoryJSON, jsonErr := json.Marshal(categories[0])
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("updateCategoryForTeamForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
categoryJSON, err := json.Marshal(categories[0])
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("updateCategoryForTeamForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ func getSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
json, err := json.Marshal(subscription)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getSubscription", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getSubscription", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -125,38 +125,38 @@ func changeSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
bodyBytes, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
var subscriptionChange *model.SubscriptionChange
|
||||
if err = json.Unmarshal(bodyBytes, &subscriptionChange); err != nil {
|
||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
currentSubscription, appErr := c.App.Cloud().GetSubscription(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
||||
return
|
||||
}
|
||||
|
||||
changedSub, err := c.App.Cloud().ChangeSubscription(c.AppContext.Session().UserId, currentSubscription.ID, subscriptionChange)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(changedSub)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.changeSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Log failures for purchase confirmation email, but don't show an error to the user so as not to confuse them
|
||||
// At this point, the upgrade is complete.
|
||||
if nErr := c.App.SendUpgradeConfirmationEmail(); nErr != nil {
|
||||
c.Logger.Error("Error sending purchase confirmation email")
|
||||
if appErr := c.App.SendUpgradeConfirmationEmail(); appErr != nil {
|
||||
c.Logger.Error("Error sending purchase confirmation email", mlog.Err(appErr))
|
||||
}
|
||||
|
||||
w.Write(json)
|
||||
@@ -176,26 +176,26 @@ func requestCloudTrial(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
// check if the email needs to be set
|
||||
bodyBytes, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
// this value will not be empty when both emails (user admin and CWS customer) are not business email and
|
||||
// we need to request a new email from the user via the request business email modal
|
||||
var startTrialRequest *model.StartCloudTrialRequest
|
||||
if err = json.Unmarshal(bodyBytes, &startTrialRequest); err != nil {
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
changedSub, err := c.App.Cloud().RequestCloudTrial(c.AppContext.Session().UserId, startTrialRequest.SubscriptionID, startTrialRequest.Email)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(changedSub)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -215,36 +215,37 @@ func validateBusinessEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
user, userErr := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if userErr != nil {
|
||||
c.Err = model.NewAppError("Api4.validateBusinessEmail", "api.cloud.request_error", nil, "", http.StatusInternalServerError)
|
||||
user, appErr := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.validateBusinessEmail", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
||||
return
|
||||
}
|
||||
|
||||
bodyBytes, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
var emailToValidate *model.ValidateBusinessEmailRequest
|
||||
if err := json.Unmarshal(bodyBytes, &emailToValidate); err != nil {
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
err = json.Unmarshal(bodyBytes, &emailToValidate)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.requestCloudTrial", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
emailErr := c.App.Cloud().ValidateBusinessEmail(user.Id, emailToValidate.Email)
|
||||
if emailErr != nil {
|
||||
c.Err = model.NewAppError("Api4.validateBusinessEmail", "api.cloud.request_error", nil, emailErr.Error(), http.StatusForbidden)
|
||||
err = c.App.Cloud().ValidateBusinessEmail(user.Id, emailToValidate.Email)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.validateBusinessEmail", "api.cloud.request_error", nil, "", http.StatusForbidden).Wrap(err)
|
||||
emailResp := model.ValidateBusinessEmailResponse{IsValid: false}
|
||||
if err := json.NewEncoder(w).Encode(emailResp); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
return
|
||||
}
|
||||
emailResp := model.ValidateBusinessEmailResponse{IsValid: true}
|
||||
if err := json.NewEncoder(w).Encode(emailResp); err != nil {
|
||||
mlog.Warn("Error while writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error while writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,28 +305,27 @@ func getCloudProducts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
products, err := c.App.Cloud().GetCloudProducts(c.AppContext.Session().UserId, includeLegacyProducts)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudProducts", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getCloudProducts", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
byteProductsData, err := json.Marshal(products)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudProducts", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getCloudProducts", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionSysconsoleReadBilling) {
|
||||
|
||||
sanitizedProducts := []model.UserFacingProduct{}
|
||||
err = json.Unmarshal(byteProductsData, &sanitizedProducts)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudProducts", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getCloudProducts", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
byteSanitizedProductsData, err := json.Marshal(sanitizedProducts)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudProducts", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getCloudProducts", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -344,13 +344,13 @@ func getCloudLimits(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
limits, err := c.App.Cloud().GetCloudLimits(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudLimits", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getCloudLimits", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(limits)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudLimits", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getCloudLimits", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -370,13 +370,13 @@ func getCloudCustomer(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
customer, err := c.App.Cloud().GetCloudCustomer(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudCustomer", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getCloudCustomer", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(customer)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getCloudCustomer", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getCloudCustomer", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -396,25 +396,25 @@ func updateCloudCustomer(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
bodyBytes, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomer", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomer", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
var customerInfo *model.CloudCustomerInfo
|
||||
if err = json.Unmarshal(bodyBytes, &customerInfo); err != nil {
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomer", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomer", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
customer, appErr := c.App.Cloud().UpdateCloudCustomer(c.AppContext.Session().UserId, customerInfo)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomer", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomer", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(customer)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomer", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomer", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -434,25 +434,25 @@ func updateCloudCustomerAddress(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
|
||||
bodyBytes, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomerAddress", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomerAddress", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
var address *model.Address
|
||||
if err = json.Unmarshal(bodyBytes, &address); err != nil {
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomerAddress", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomerAddress", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
customer, appErr := c.App.Cloud().UpdateCloudCustomerAddress(c.AppContext.Session().UserId, address)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomerAddress", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomerAddress", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(customer)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomerAddress", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.updateCloudCustomerAddress", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -475,13 +475,13 @@ func createCustomerPayment(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
intent, err := c.App.Cloud().CreateCustomerPayment(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(intent)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -506,19 +506,19 @@ func confirmCustomerPayment(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
|
||||
bodyBytes, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.confirmCustomerPayment", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.confirmCustomerPayment", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
var confirmRequest *model.ConfirmPaymentMethodRequest
|
||||
if err = json.Unmarshal(bodyBytes, &confirmRequest); err != nil {
|
||||
c.Err = model.NewAppError("Api4.confirmCustomerPayment", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.confirmCustomerPayment", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
err = c.App.Cloud().ConfirmCustomerPayment(c.AppContext.Session().UserId, confirmRequest)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.createCustomerPayment", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -540,13 +540,13 @@ func getInvoicesForSubscription(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
|
||||
invoices, appErr := c.App.Cloud().GetInvoicesForSubscription(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getInvoicesForSubscription", "api.cloud.request_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getInvoicesForSubscription", "api.cloud.request_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(invoices)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getInvoicesForSubscription", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getInvoicesForSubscription", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
infos := c.App.GetClusterStatus()
|
||||
js, jsonErr := json.Marshal(infos)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getClusterStatus", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(infos)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getClusterStatus", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
|
||||
@@ -417,9 +417,9 @@ func listCommandAutocompleteSuggestions(c *Context, w http.ResponseWriter, r *ht
|
||||
}
|
||||
userInput = strings.TrimPrefix(userInput, "/")
|
||||
|
||||
commands, err := c.App.ListAutocompleteCommands(c.Params.TeamId, c.AppContext.T)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
commands, appErr := c.App.ListAutocompleteCommands(c.Params.TeamId, c.AppContext.T)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -436,9 +436,9 @@ func listCommandAutocompleteSuggestions(c *Context, w http.ResponseWriter, r *ht
|
||||
|
||||
suggestions := c.App.GetSuggestions(c.AppContext, commandArgs, commands, roleId)
|
||||
|
||||
js, jsonErr := json.Marshal(suggestions)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("listCommandAutocompleteSuggestions", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(suggestions)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("listCommandAutocompleteSuggestions", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
|
||||
106
api4/config.go
106
api4/config.go
@@ -108,9 +108,10 @@ func configReload(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
c.SetInvalidParam("config")
|
||||
var cfg *model.Config
|
||||
err := json.NewDecoder(r.Body).Decode(&cfg)
|
||||
if err != nil || cfg == nil {
|
||||
c.SetInvalidParamWithErr("config", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -132,14 +133,13 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var err1 error
|
||||
cfg, err1 = config.Merge(appCfg, cfg, &utils.MergeConfig{
|
||||
cfg, err = config.Merge(appCfg, cfg, &utils.MergeConfig{
|
||||
StructFieldFilter: func(structField reflect.StructField, base, patch reflect.Value) bool {
|
||||
return writeFilter(c, structField)
|
||||
},
|
||||
})
|
||||
if err1 != nil {
|
||||
c.Err = model.NewAppError("updateConfig", "api.config.update_config.restricted_merge.app_error", nil, err1.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("updateConfig", "api.config.update_config.restricted_merge.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -156,8 +156,8 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
*cfg.PluginSettings.MarketplaceURL = *appCfg.PluginSettings.MarketplaceURL
|
||||
}
|
||||
|
||||
if err := c.App.CheckFreemiumLimitsForConfigSave(appCfg, cfg); err != nil {
|
||||
c.Err = err
|
||||
if appErr := c.App.CheckFreemiumLimitsForConfigSave(appCfg, cfg); appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -173,33 +173,33 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.App.HandleMessageExportConfig(cfg, appCfg)
|
||||
|
||||
if err := cfg.IsValid(); err != nil {
|
||||
c.Err = err
|
||||
if appErr := cfg.IsValid(); appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
oldCfg, newCfg, err := c.App.SaveConfig(cfg, true)
|
||||
oldCfg, newCfg, appErr := c.App.SaveConfig(cfg, true)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
diffs, err := config.Diff(oldCfg, newCfg)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
diffs, diffErr := config.Diff(oldCfg, newCfg)
|
||||
if diffErr != nil {
|
||||
c.Err = model.NewAppError("updateConfig", "api.config.update_config.diff.app_error", nil, diffErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("updateConfig", "api.config.update_config.diff.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.AddEventPriorState(&diffs)
|
||||
|
||||
newCfg.Sanitize()
|
||||
|
||||
cfg, mergeErr := config.Merge(&model.Config{}, newCfg, &utils.MergeConfig{
|
||||
cfg, err = config.Merge(&model.Config{}, newCfg, &utils.MergeConfig{
|
||||
StructFieldFilter: func(structField reflect.StructField, base, patch reflect.Value) bool {
|
||||
return readFilter(c, structField)
|
||||
},
|
||||
})
|
||||
if mergeErr != nil {
|
||||
c.Err = model.NewAppError("updateConfig", "api.config.update_config.restricted_merge.app_error", nil, mergeErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("updateConfig", "api.config.update_config.restricted_merge.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -210,9 +210,9 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
if c.App.Channels().License() != nil && *c.App.Channels().License().Features.Cloud {
|
||||
js, jsonErr := cfg.ToJSONFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("updateConfig", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := cfg.ToJSONFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("updateConfig", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
@@ -259,9 +259,10 @@ func getEnvironmentConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
c.SetInvalidParam("config")
|
||||
var cfg *model.Config
|
||||
err := json.NewDecoder(r.Body).Decode(&cfg)
|
||||
if err != nil || cfg == nil {
|
||||
c.SetInvalidParamWithErr("config", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -298,8 +299,8 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := c.App.CheckFreemiumLimitsForConfigSave(appCfg, cfg); err != nil {
|
||||
c.Err = err
|
||||
if appErr := c.App.CheckFreemiumLimitsForConfigSave(appCfg, cfg); appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -315,30 +316,29 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.App.HandleMessageExportConfig(cfg, appCfg)
|
||||
}
|
||||
|
||||
updatedCfg, mergeErr := config.Merge(appCfg, cfg, &utils.MergeConfig{
|
||||
updatedCfg, err := config.Merge(appCfg, cfg, &utils.MergeConfig{
|
||||
StructFieldFilter: filterFn,
|
||||
})
|
||||
|
||||
if mergeErr != nil {
|
||||
c.Err = model.NewAppError("patchConfig", "api.config.update_config.restricted_merge.app_error", nil, mergeErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err := updatedCfg.IsValid()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
c.Err = model.NewAppError("patchConfig", "api.config.update_config.restricted_merge.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
oldCfg, newCfg, err := c.App.SaveConfig(updatedCfg, true)
|
||||
appErr := updatedCfg.IsValid()
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
oldCfg, newCfg, appErr := c.App.SaveConfig(updatedCfg, true)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
diffs, err := config.Diff(oldCfg, newCfg)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
diffs, diffErr := config.Diff(oldCfg, newCfg)
|
||||
if diffErr != nil {
|
||||
c.Err = model.NewAppError("patchConfig", "api.config.patch_config.diff.app_error", nil, diffErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("patchConfig", "api.config.patch_config.diff.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -348,21 +348,21 @@ func patchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec.Success()
|
||||
|
||||
cfg, mergeErr = config.Merge(&model.Config{}, newCfg, &utils.MergeConfig{
|
||||
cfg, err = config.Merge(&model.Config{}, newCfg, &utils.MergeConfig{
|
||||
StructFieldFilter: func(structField reflect.StructField, base, patch reflect.Value) bool {
|
||||
return readFilter(c, structField)
|
||||
},
|
||||
})
|
||||
if mergeErr != nil {
|
||||
c.Err = model.NewAppError("patchConfig", "api.config.patch_config.restricted_merge.app_error", nil, mergeErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("patchConfig", "api.config.patch_config.restricted_merge.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
if c.App.Channels().License() != nil && *c.App.Channels().License().Features.Cloud {
|
||||
js, jsonErr := cfg.ToJSONFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("patchConfig", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := cfg.ToJSONFiltered(model.ConfigAccessTagType, model.ConfigAccessTagCloudRestrictable)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("patchConfig", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
|
||||
@@ -35,9 +35,10 @@ func localGetConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func localUpdateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
c.SetInvalidParam("config")
|
||||
var cfg *model.Config
|
||||
err := json.NewDecoder(r.Body).Decode(&cfg)
|
||||
if err != nil || cfg == nil {
|
||||
c.SetInvalidParamWithErr("config", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -56,15 +57,15 @@ func localUpdateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.App.HandleMessageExportConfig(cfg, appCfg)
|
||||
|
||||
err := cfg.IsValid()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
appErr := cfg.IsValid()
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
oldCfg, newCfg, err := c.App.SaveConfig(cfg, true)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
oldCfg, newCfg, appErr := c.App.SaveConfig(cfg, true)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -87,9 +88,10 @@ func localUpdateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func localPatchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
if cfg == nil {
|
||||
c.SetInvalidParam("config")
|
||||
var cfg *model.Config
|
||||
err := json.NewDecoder(r.Body).Decode(&cfg)
|
||||
if err != nil || cfg == nil {
|
||||
c.SetInvalidParamWithErr("config", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -114,21 +116,21 @@ func localPatchConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := updatedCfg.IsValid()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
appErr := updatedCfg.IsValid()
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
oldCfg, newCfg, err := c.App.SaveConfig(updatedCfg, true)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
oldCfg, newCfg, appErr := c.App.SaveConfig(updatedCfg, true)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
diffs, diffErr := config.Diff(oldCfg, newCfg)
|
||||
if diffErr != nil {
|
||||
c.Err = model.NewAppError("patchConfig", "api.config.patch_config.diff.app_error", nil, diffErr.Error(), http.StatusInternalServerError)
|
||||
diffs, err := config.Diff(oldCfg, newCfg)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("patchConfig", "api.config.patch_config.diff.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.AddEventPriorState(&diffs)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/audit"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (api *API) InitDataRetention() {
|
||||
@@ -34,15 +35,15 @@ func (api *API) InitDataRetention() {
|
||||
func getGlobalPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
// No permission check required.
|
||||
|
||||
policy, err := c.App.GetGlobalRetentionPolicy()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
policy, appErr := c.App.GetGlobalRetentionPolicy()
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(policy)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getGlobalPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(policy)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getGlobalPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
@@ -57,15 +58,15 @@ func getPolicies(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
limit := c.Params.PerPage
|
||||
offset := c.Params.Page * limit
|
||||
|
||||
policies, err := c.App.GetRetentionPolicies(offset, limit)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
policies, appErr := c.App.GetRetentionPolicies(offset, limit)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(policies)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getPolicies", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(policies)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getPolicies", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
@@ -77,14 +78,19 @@ func getPoliciesCount(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
count, err := c.App.GetRetentionPoliciesCount()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
count, appErr := c.App.GetRetentionPoliciesCount()
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
body := map[string]int64{"total_count": count}
|
||||
b, _ := json.Marshal(body)
|
||||
w.Write(b)
|
||||
|
||||
body := struct {
|
||||
TotalCount int64 `json:"total_count"`
|
||||
}{count}
|
||||
err := json.NewEncoder(w).Encode(body)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func getPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -94,15 +100,15 @@ func getPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
c.RequirePolicyId()
|
||||
policy, err := c.App.GetRetentionPolicy(c.Params.PolicyId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
policy, appErr := c.App.GetRetentionPolicy(c.Params.PolicyId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(policy)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(policy)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
@@ -123,17 +129,17 @@ func createPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
newPolicy, err := c.App.CreateRetentionPolicy(&policy)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
newPolicy, appErr := c.App.CreateRetentionPolicy(&policy)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.AddEventResultState(newPolicy)
|
||||
auditRec.AddEventObjectType("policy")
|
||||
js, jsonErr := json.Marshal(newPolicy)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("createPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(newPolicy)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("createPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
@@ -159,18 +165,18 @@ func patchPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
policy, err := c.App.PatchRetentionPolicy(&patch)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
policy, appErr := c.App.PatchRetentionPolicy(&patch)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
auditRec.AddEventResultState(policy)
|
||||
auditRec.AddEventObjectType("retention_policy")
|
||||
|
||||
js, jsonErr := json.Marshal(policy)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("patchPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(policy)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("patchPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.Success()
|
||||
@@ -209,15 +215,15 @@ func getTeamsForPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
limit := c.Params.PerPage
|
||||
offset := c.Params.Page * limit
|
||||
|
||||
teams, err := c.App.GetTeamsForRetentionPolicy(policyId, offset, limit)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
teams, appErr := c.App.GetTeamsForRetentionPolicy(policyId, offset, limit)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, jsonErr := json.Marshal(teams)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getTeamsForPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(teams)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getTeamsForPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(b)
|
||||
@@ -232,24 +238,24 @@ func searchTeamsInPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var props model.TeamSearch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
|
||||
c.SetInvalidParamWithErr("team_search", jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&props); err != nil {
|
||||
c.SetInvalidParamWithErr("team_search", err)
|
||||
return
|
||||
}
|
||||
|
||||
props.PolicyID = model.NewString(c.Params.PolicyId)
|
||||
props.IncludePolicyID = model.NewBool(true)
|
||||
|
||||
teams, _, err := c.App.SearchAllTeams(&props)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
teams, _, appErr := c.App.SearchAllTeams(&props)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
c.App.SanitizeTeams(*c.AppContext.Session(), teams)
|
||||
|
||||
js, jsonErr := json.Marshal(teams)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchTeamsInPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(teams)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("searchTeamsInPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
@@ -323,15 +329,15 @@ func getChannelsForPolicy(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
limit := c.Params.PerPage
|
||||
offset := c.Params.Page * limit
|
||||
|
||||
channels, err := c.App.GetChannelsForRetentionPolicy(policyId, offset, limit)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
channels, appErr := c.App.GetChannelsForRetentionPolicy(policyId, offset, limit)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, jsonErr := json.Marshal(channels)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getChannelsForPolicy", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(channels)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getChannelsForPolicy", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(b)
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/audit"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
func (api *API) InitElasticsearch() {
|
||||
@@ -16,7 +18,11 @@ func (api *API) InitElasticsearch() {
|
||||
}
|
||||
|
||||
func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
var cfg *model.Config
|
||||
err := json.NewDecoder(r.Body).Decode(&cfg)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error decoding config.", mlog.Err(err))
|
||||
}
|
||||
if cfg == nil {
|
||||
cfg = c.App.Config()
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func listExports(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
data, err := json.Marshal(exports)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("listImports", "app.export.marshal.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("listImports", "app.export.marshal.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
|
||||
@@ -28,7 +28,7 @@ func listImports(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
data, err := json.Marshal(imports)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("listImports", "app.import.marshal.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("listImports", "app.import.marshal.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
152
api4/insights.go
152
api4/insights.go
@@ -33,9 +33,9 @@ func getTopReactionsForTeamSince(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
team, err := c.App.GetTeam(c.Params.TeamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
team, appErr := c.App.GetTeam(c.Params.TeamId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -44,27 +44,27 @@ func getTopReactionsForTeamSince(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
user, appErr := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
startTime := model.StartOfDayForTimeRange(c.Params.TimeRange, user.GetTimezoneLocation())
|
||||
|
||||
topReactionList, err := c.App.GetTopReactionsForTeamSince(c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
|
||||
topReactionList, appErr := c.App.GetTopReactionsForTeamSince(c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
|
||||
StartUnixMilli: startTime.UnixMilli(),
|
||||
Page: c.Params.Page,
|
||||
PerPage: c.Params.PerPage,
|
||||
})
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(topReactionList)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTopReactionsForTeamSince", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(topReactionList)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTopReactionsForTeamSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -81,9 +81,9 @@ func getTopReactionsForUserSince(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
team, teamErr := c.App.GetTeam(c.Params.TeamId)
|
||||
if teamErr != nil {
|
||||
c.Err = teamErr
|
||||
team, appErr := c.App.GetTeam(c.Params.TeamId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -93,27 +93,27 @@ func getTopReactionsForUserSince(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
}
|
||||
}
|
||||
|
||||
user, err := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
user, appErr := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
startTime := model.StartOfDayForTimeRange(c.Params.TimeRange, user.GetTimezoneLocation())
|
||||
|
||||
topReactionList, err := c.App.GetTopReactionsForUserSince(c.AppContext.Session().UserId, c.Params.TeamId, &model.InsightsOpts{
|
||||
topReactionList, appErr := c.App.GetTopReactionsForUserSince(c.AppContext.Session().UserId, c.Params.TeamId, &model.InsightsOpts{
|
||||
StartUnixMilli: startTime.UnixMilli(),
|
||||
Page: c.Params.Page,
|
||||
PerPage: c.Params.PerPage,
|
||||
})
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(topReactionList)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTopReactionsForUserSince", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(topReactionList)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTopReactionsForUserSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -128,9 +128,9 @@ func getTopChannelsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
team, err := c.App.GetTeam(c.Params.TeamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
team, appErr := c.App.GetTeam(c.Params.TeamId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -139,34 +139,34 @@ func getTopChannelsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
user, appErr := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
loc := user.GetTimezoneLocation()
|
||||
startTime := model.StartOfDayForTimeRange(c.Params.TimeRange, loc)
|
||||
|
||||
topChannels, err := c.App.GetTopChannelsForTeamSince(c.AppContext, c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
|
||||
topChannels, appErr := c.App.GetTopChannelsForTeamSince(c.AppContext, c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
|
||||
StartUnixMilli: startTime.UnixMilli(),
|
||||
Page: c.Params.Page,
|
||||
PerPage: c.Params.PerPage,
|
||||
})
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
topChannels.PostCountByDuration, err = postCountByDurationViewModel(c, topChannels, startTime, c.Params.TimeRange, nil, loc)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
topChannels.PostCountByDuration, appErr = postCountByDurationViewModel(c, topChannels, startTime, c.Params.TimeRange, nil, loc)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(topChannels)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTopChannelsForTeamSince", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(topChannels)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTopChannelsForTeamSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -183,9 +183,9 @@ func getTopChannelsForUserSince(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
team, teamErr := c.App.GetTeam(c.Params.TeamId)
|
||||
if teamErr != nil {
|
||||
c.Err = teamErr
|
||||
team, appErr := c.App.GetTeam(c.Params.TeamId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -195,35 +195,34 @@ func getTopChannelsForUserSince(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
}
|
||||
|
||||
user, err := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
user, appErr := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
loc := user.GetTimezoneLocation()
|
||||
startTime := model.StartOfDayForTimeRange(c.Params.TimeRange, loc)
|
||||
|
||||
topChannels, err := c.App.GetTopChannelsForUserSince(c.AppContext, c.AppContext.Session().UserId, c.Params.TeamId, &model.InsightsOpts{
|
||||
topChannels, appErr := c.App.GetTopChannelsForUserSince(c.AppContext, c.AppContext.Session().UserId, c.Params.TeamId, &model.InsightsOpts{
|
||||
StartUnixMilli: startTime.UnixMilli(),
|
||||
Page: c.Params.Page,
|
||||
PerPage: c.Params.PerPage,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
topChannels.PostCountByDuration, err = postCountByDurationViewModel(c, topChannels, startTime, c.Params.TimeRange, &c.AppContext.Session().UserId, loc)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
topChannels.PostCountByDuration, appErr = postCountByDurationViewModel(c, topChannels, startTime, c.Params.TimeRange, &c.AppContext.Session().UserId, loc)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(topChannels)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTopChannelsForUserSince", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(topChannels)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTopChannelsForUserSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -237,9 +236,9 @@ func getTopThreadsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
team, err := c.App.GetTeam(c.Params.TeamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
team, appErr := c.App.GetTeam(c.Params.TeamId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -251,9 +250,9 @@ func getTopThreadsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
|
||||
// restrict guests and users with no access to team
|
||||
user, err := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
user, appErr := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -264,19 +263,19 @@ func getTopThreadsForTeamSince(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
|
||||
startTime := model.StartOfDayForTimeRange(c.Params.TimeRange, user.GetTimezoneLocation())
|
||||
|
||||
topThreads, err := c.App.GetTopThreadsForTeamSince(c.AppContext, c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
|
||||
topThreads, appErr := c.App.GetTopThreadsForTeamSince(c.AppContext, c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
|
||||
StartUnixMilli: startTime.UnixMilli(),
|
||||
Page: c.Params.Page,
|
||||
PerPage: c.Params.PerPage,
|
||||
})
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(topThreads)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTopThreadsForTeamSince", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(topThreads)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTopThreadsForTeamSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -287,9 +286,9 @@ func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
c.Params.TeamId = r.URL.Query().Get("team_id")
|
||||
|
||||
// restrict guests and users with no access to team
|
||||
user, err := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
user, appErr := c.App.GetUser(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
// TeamId is an optional parameter
|
||||
@@ -320,20 +319,19 @@ func getTopThreadsForUserSince(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
|
||||
startTime := model.StartOfDayForTimeRange(c.Params.TimeRange, user.GetTimezoneLocation())
|
||||
|
||||
topThreads, err := c.App.GetTopThreadsForUserSince(c.AppContext, c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
|
||||
topThreads, appErr := c.App.GetTopThreadsForUserSince(c.AppContext, c.Params.TeamId, c.AppContext.Session().UserId, &model.InsightsOpts{
|
||||
StartUnixMilli: startTime.UnixMilli(),
|
||||
Page: c.Params.Page,
|
||||
PerPage: c.Params.PerPage,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(topThreads)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTopThreadsForUserSince", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(topThreads)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTopThreadsForUserSince", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -33,14 +33,15 @@ func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var cookie *model.PostActionCookie
|
||||
if actionRequest.Cookie != "" {
|
||||
cookie = &model.PostActionCookie{}
|
||||
cookieStr, err := model.DecryptPostActionCookie(actionRequest.Cookie, c.App.PostActionCookieSecret())
|
||||
cookieStr := ""
|
||||
cookieStr, err = model.DecryptPostActionCookie(actionRequest.Cookie, c.App.PostActionCookieSecret())
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, "err="+err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal([]byte(cookieStr), &cookie)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, "err="+err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), cookie.ChannelId, model.PermissionReadChannel) {
|
||||
@@ -64,8 +65,10 @@ func doPostAction(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(resp)
|
||||
w.Write(b)
|
||||
err = json.NewEncoder(w).Encode(resp)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func openDialog(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -81,8 +84,8 @@ func openDialog(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.App.OpenInteractiveDialog(dialog); err != nil {
|
||||
c.Err = err
|
||||
if appErr := c.App.OpenInteractiveDialog(dialog); appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
25
api4/job.go
25
api4/job.go
@@ -162,15 +162,15 @@ func getJobs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jobs, err := c.App.GetJobsByTypesPage(validJobTypes, c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
jobs, appErr := c.App.GetJobsByTypesPage(validJobTypes, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(jobs)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getJobs", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(jobs)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getJobs", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
@@ -192,17 +192,18 @@ func getJobsByType(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
jobs, err := c.App.GetJobsByTypePage(c.Params.JobType, c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
jobs, appErr := c.App.GetJobsByTypePage(c.Params.JobType, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(jobs)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getJobsByType", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(jobs)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getJobsByType", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
|
||||
42
api4/ldap.go
42
api4/ldap.go
@@ -111,9 +111,9 @@ func getLdapGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
opts.IsConfigured = c.Params.IsConfigured
|
||||
}
|
||||
|
||||
groups, total, err := c.App.GetAllLdapGroupsPage(c.Params.Page, c.Params.PerPage, opts)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
groups, total, appErr := c.App.GetAllLdapGroupsPage(c.Params.Page, c.Params.PerPage, opts)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -130,12 +130,12 @@ func getLdapGroups(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
mugs = append(mugs, mug)
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(struct {
|
||||
b, err := json.Marshal(struct {
|
||||
Count int `json:"count"`
|
||||
Groups []*mixedUnlinkedGroup `json:"groups"`
|
||||
}{Count: total, Groups: mugs})
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getLdapGroups", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getLdapGroups", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -162,9 +162,9 @@ func linkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
ldapGroup, err := c.App.GetLdapGroup(c.Params.RemoteId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
ldapGroup, appErr := c.App.GetLdapGroup(c.Params.RemoteId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -175,9 +175,9 @@ func linkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
group, err := c.App.GetGroupByRemoteID(ldapGroup.GetRemoteId(), model.GroupSourceLdap)
|
||||
if err != nil && err.Id != "app.group.no_rows" {
|
||||
c.Err = err
|
||||
group, appErr := c.App.GetGroupByRemoteID(ldapGroup.GetRemoteId(), model.GroupSourceLdap)
|
||||
if appErr != nil && appErr.Id != "app.group.no_rows" {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
if group != nil {
|
||||
@@ -203,9 +203,9 @@ func linkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
group.DeleteAt = 0
|
||||
group.DisplayName = displayName
|
||||
group.RemoteId = ldapGroup.RemoteId
|
||||
newOrUpdatedGroup, err = c.App.UpdateGroup(group)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
newOrUpdatedGroup, appErr = c.App.UpdateGroup(group)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
auditRec.AddEventResultState(newOrUpdatedGroup)
|
||||
@@ -222,9 +222,9 @@ func linkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
RemoteId: ldapGroup.RemoteId,
|
||||
Source: model.GroupSourceLdap,
|
||||
}
|
||||
newOrUpdatedGroup, err = c.App.CreateGroup(newGroup)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
newOrUpdatedGroup, appErr = c.App.CreateGroup(newGroup)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
auditRec.AddEventResultState(newOrUpdatedGroup)
|
||||
@@ -232,9 +232,9 @@ func linkLdapGroup(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
status = http.StatusCreated
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(newOrUpdatedGroup)
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.linkLdapGroup", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(newOrUpdatedGroup)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.linkLdapGroup", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -132,26 +132,27 @@ func getOAuthApps(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var apps []*model.OAuthApp
|
||||
var err *model.AppError
|
||||
var appErr *model.AppError
|
||||
if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageSystemWideOAuth) {
|
||||
apps, err = c.App.GetOAuthApps(c.Params.Page, c.Params.PerPage)
|
||||
apps, appErr = c.App.GetOAuthApps(c.Params.Page, c.Params.PerPage)
|
||||
} else if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageOAuth) {
|
||||
apps, err = c.App.GetOAuthAppsByCreator(c.AppContext.Session().UserId, c.Params.Page, c.Params.PerPage)
|
||||
apps, appErr = c.App.GetOAuthAppsByCreator(c.AppContext.Session().UserId, c.Params.Page, c.Params.PerPage)
|
||||
} else {
|
||||
c.SetPermissionError(model.PermissionManageOAuth)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(apps)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getOAuthApps", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(apps)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getOAuthApps", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -295,16 +296,17 @@ func getAuthorizedOAuthApps(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
apps, err := c.App.GetAuthorizedAppsForUser(c.Params.UserId, c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
apps, appErr := c.App.GetAuthorizedAppsForUser(c.Params.UserId, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(apps)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getAuthorizedOAuthApps", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(apps)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getAuthorizedOAuthApps", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -26,8 +26,9 @@ func appendAncillaryPermissions(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
permissions := strings.Split(keys[0], ",")
|
||||
b, err := json.Marshal(model.AddAncillaryPermissions(permissions))
|
||||
if err != nil {
|
||||
c.SetJSONEncodingError()
|
||||
c.SetJSONEncodingError(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(b)
|
||||
}
|
||||
|
||||
@@ -251,9 +251,9 @@ func getWebappPlugins(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
manifests, err := c.App.GetActivePluginManifests()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
manifests, appErr := c.App.GetActivePluginManifests()
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -268,11 +268,12 @@ func getWebappPlugins(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(clientManifests)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getWebappPlugins", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(clientManifests)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getWebappPlugins", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -294,7 +295,7 @@ func getMarketplacePlugins(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
filter, err := parseMarketplacePluginFilter(r.URL)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getMarketplacePlugins", "app.plugin.marshal.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("getMarketplacePlugins", "app.plugin.marshal.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -306,7 +307,7 @@ func getMarketplacePlugins(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
json, err := json.Marshal(plugins)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getMarketplacePlugins", "app.plugin.marshal.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("getMarketplacePlugins", "app.plugin.marshal.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
13
api4/post.go
13
api4/post.go
@@ -970,9 +970,9 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
infos, err := c.App.GetFileInfosForPostWithMigration(c.Params.PostId, includeDeleted)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
infos, appErr := c.App.GetFileInfosForPostWithMigration(c.Params.PostId, includeDeleted)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -980,11 +980,12 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(infos)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getFileInfosForPost", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(infos)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getFileInfosForPost", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "max-age=2592000, private")
|
||||
w.Header().Set(model.HeaderEtagServer, model.GetEtagForFileInfos(infos))
|
||||
w.Write(js)
|
||||
|
||||
@@ -62,17 +62,18 @@ func getReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
reactions, err := c.App.GetReactionsForPost(c.Params.PostId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
reactions, appErr := c.App.GetReactionsForPost(c.Params.PostId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(reactions)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getReactions", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(reactions)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getReactions", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -125,15 +126,15 @@ func getBulkReactions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
reactions, err := c.App.GetBulkReactionsForPosts(postIds)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
reactions, appErr := c.App.GetBulkReactionsForPosts(postIds)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(reactions)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getBulkReactions", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(reactions)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getBulkReactions", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
|
||||
@@ -31,8 +31,8 @@ func remoteClusterPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var frame model.RemoteClusterFrame
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&frame); jsonErr != nil {
|
||||
c.Err = model.NewAppError("remoteClusterPing", "api.unmarshal_error", nil, "", http.StatusBadRequest).Wrap(jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&frame); err != nil {
|
||||
c.Err = model.NewAppError("remoteClusterPing", "api.unmarshal_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -47,15 +47,15 @@ func remoteClusterPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rc, err := c.App.GetRemoteCluster(frame.RemoteId)
|
||||
if err != nil {
|
||||
rc, appErr := c.App.GetRemoteCluster(frame.RemoteId)
|
||||
if appErr != nil {
|
||||
c.SetInvalidRemoteIdError(frame.RemoteId)
|
||||
return
|
||||
}
|
||||
|
||||
var ping model.RemoteClusterPing
|
||||
if jsonErr := json.Unmarshal(frame.Msg.Payload, &ping); jsonErr != nil {
|
||||
c.SetInvalidParam("msg.payload")
|
||||
if err := json.Unmarshal(frame.Msg.Payload, &ping); err != nil {
|
||||
c.SetInvalidParamWithErr("msg.payload", err)
|
||||
return
|
||||
}
|
||||
ping.RecvAt = model.GetMillis()
|
||||
@@ -64,8 +64,10 @@ func remoteClusterPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
metrics.IncrementRemoteClusterMsgReceivedCounter(rc.RemoteId)
|
||||
}
|
||||
|
||||
resp, _ := json.Marshal(&ping)
|
||||
w.Write(resp)
|
||||
err := json.NewEncoder(w).Encode(ping)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func remoteClusterAcceptMessage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -77,12 +79,13 @@ func remoteClusterAcceptMessage(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
var frame model.RemoteClusterFrame
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&frame); jsonErr != nil {
|
||||
c.Err = model.NewAppError("remoteClusterAcceptMessage", "api.unmarshal_error", nil, "", http.StatusBadRequest).Wrap(jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&frame); err != nil {
|
||||
c.Err = model.NewAppError("remoteClusterAcceptMessage", "api.unmarshal_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
if appErr := frame.IsValid(); appErr != nil {
|
||||
appErr = frame.IsValid()
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
@@ -97,8 +100,8 @@ func remoteClusterAcceptMessage(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
rc, err := c.App.GetRemoteCluster(frame.RemoteId)
|
||||
if err != nil {
|
||||
rc, appErr := c.App.GetRemoteCluster(frame.RemoteId)
|
||||
if appErr != nil {
|
||||
c.SetInvalidRemoteIdError(frame.RemoteId)
|
||||
return
|
||||
}
|
||||
@@ -107,11 +110,12 @@ func remoteClusterAcceptMessage(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
// pass message to Remote Cluster Service and write response
|
||||
resp := service.ReceiveIncomingMsg(rc, frame.Msg)
|
||||
|
||||
b, errMarshall := json.Marshal(resp)
|
||||
if errMarshall != nil {
|
||||
c.Err = model.NewAppError("remoteClusterAcceptMessage", "api.marshal_error", nil, errMarshall.Error(), http.StatusInternalServerError)
|
||||
b, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("remoteClusterAcceptMessage", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(b)
|
||||
}
|
||||
|
||||
|
||||
41
api4/role.go
41
api4/role.go
@@ -32,15 +32,15 @@ func getAllRoles(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
roles, err := c.App.GetAllRoles()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
roles, appErr := c.App.GetAllRoles()
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(roles)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getAllRoles", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(roles)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getAllRoles", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -95,17 +95,18 @@ func getRolesByNames(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
roles, err := c.App.GetRolesByNames(cleanedRoleNames)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
roles, appErr := c.App.GetRolesByNames(cleanedRoleNames)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(roles)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getRolesByNames", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(roles)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getRolesByNames", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -116,8 +117,8 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var patch model.RolePatch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&patch); jsonErr != nil {
|
||||
c.SetInvalidParamWithErr("role", jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&patch); err != nil {
|
||||
c.SetInvalidParamWithErr("role", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -125,9 +126,9 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddEventParameter("role_patch", patch)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
oldRole, err := c.App.GetRole(c.Params.RoleId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
oldRole, appErr := c.App.GetRole(c.Params.RoleId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
auditRec.AddEventPriorState(oldRole)
|
||||
@@ -203,9 +204,9 @@ func patchRole(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
role, err := c.App.PatchRole(oldRole, &patch)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
role, appErr := c.App.PatchRole(oldRole, &patch)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -93,17 +93,18 @@ func getSchemes(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
schemes, err := c.App.GetSchemesPage(c.Params.Scope, c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
schemes, appErr := c.App.GetSchemesPage(c.Params.Scope, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(schemes)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getSchemes", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(schemes)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getSchemes", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -118,9 +119,9 @@ func getTeamsForScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
scheme, err := c.App.GetScheme(c.Params.SchemeId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
scheme, appErr := c.App.GetScheme(c.Params.SchemeId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -129,17 +130,18 @@ func getTeamsForScheme(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
teams, err := c.App.GetTeamsForSchemePage(scheme, c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
teams, appErr := c.App.GetTeamsForSchemePage(scheme, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(teams)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamsForScheme", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(teams)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTeamsForScheme", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
|
||||
@@ -50,9 +50,10 @@ func getSharedChannels(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
b, err := json.Marshal(channels)
|
||||
if err != nil {
|
||||
c.SetJSONEncodingError()
|
||||
c.SetJSONEncodingError(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(b)
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ func getRemoteClusterInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
b, err := json.Marshal(remoteInfo)
|
||||
if err != nil {
|
||||
c.SetJSONEncodingError()
|
||||
c.SetJSONEncodingError(err)
|
||||
return
|
||||
}
|
||||
w.Write(b)
|
||||
|
||||
@@ -64,17 +64,18 @@ func getUserStatusesByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// No permission check required
|
||||
statuses, err := c.App.GetUserStatusesByIds(userIds)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
statuses, appErr := c.App.GetUserStatusesByIds(userIds)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(statuses)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getUserStatusesByIds", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(statuses)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getUserStatusesByIds", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
|
||||
119
api4/system.go
119
api4/system.go
@@ -195,7 +195,11 @@ func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
var cfg *model.Config
|
||||
err := json.NewDecoder(r.Body).Decode(&cfg)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error decoding the config", mlog.Err(err))
|
||||
}
|
||||
if cfg == nil {
|
||||
cfg = c.App.Config()
|
||||
}
|
||||
@@ -215,9 +219,9 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := c.App.TestEmail(c.AppContext.Session().UserId, cfg)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
appErr := c.App.TestEmail(c.AppContext.Session().UserId, cfg)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -242,9 +246,9 @@ func testSiteURL(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := c.App.TestSiteURL(siteURL)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
appErr := c.App.TestSiteURL(siteURL)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -260,9 +264,9 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
audits, err := c.App.GetAuditsPage("", c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
audits, appErr := c.App.GetAuditsPage("", c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -309,9 +313,9 @@ func invalidateCaches(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := c.App.Srv().InvalidateAllCaches()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
appErr := c.App.Srv().InvalidateAllCaches()
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -335,9 +339,9 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
lines, err := c.App.GetLogs(c.Params.Page, c.Params.LogsPerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
lines, appErr := c.App.GetLogs(c.Params.Page, c.Params.LogsPerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -361,7 +365,15 @@ func postLog(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
m := model.MapFromJSON(r.Body)
|
||||
var m map[string]string
|
||||
err := json.NewDecoder(r.Body).Decode(&m)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error decoding request.", mlog.Err(err))
|
||||
}
|
||||
if m == nil {
|
||||
m = map[string]string{}
|
||||
}
|
||||
|
||||
lvl := m["level"]
|
||||
msg := m["message"]
|
||||
|
||||
@@ -382,7 +394,10 @@ func postLog(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
m["message"] = msg
|
||||
w.Write([]byte(model.MapToJSON(m)))
|
||||
err = json.NewEncoder(w).Encode(m)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error while writing response.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -398,9 +413,9 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
rows, err := c.App.GetAnalytics(name, teamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
rows, appErr := c.App.GetAnalytics(name, teamId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -420,15 +435,15 @@ func getLatestVersion(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := c.App.GetLatestVersion("https://api.github.com/repos/mattermost/mattermost-server/releases/latest")
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
resp, appErr := c.App.GetLatestVersion("https://api.github.com/repos/mattermost/mattermost-server/releases/latest")
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, jsonErr := json.Marshal(resp)
|
||||
if jsonErr != nil {
|
||||
c.Logger.Warn("Unable to marshal JSON for latest version.", mlog.Err(jsonErr))
|
||||
b, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Unable to marshal JSON for latest version.", mlog.Err(err))
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -451,7 +466,11 @@ func getSupportedTimezones(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func testS3(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := model.ConfigFromJSON(r.Body)
|
||||
var cfg *model.Config
|
||||
err := json.NewDecoder(r.Body).Decode(&cfg)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error decoding the config", mlog.Err(err))
|
||||
}
|
||||
if cfg == nil {
|
||||
cfg = c.App.Config()
|
||||
}
|
||||
@@ -471,9 +490,9 @@ func testS3(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := c.App.CheckMandatoryS3Fields(&cfg.FileSettings)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
appErr := c.App.CheckMandatoryS3Fields(&cfg.FileSettings)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -481,7 +500,7 @@ func testS3(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg.FileSettings.AmazonS3SecretAccessKey = c.App.Config().FileSettings.AmazonS3SecretAccessKey
|
||||
}
|
||||
|
||||
appErr := c.App.TestFileStoreConnectionWithConfig(&cfg.FileSettings)
|
||||
appErr = c.App.TestFileStoreConnectionWithConfig(&cfg.FileSettings)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
@@ -776,17 +795,18 @@ func getWarnMetricsStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
status, err := c.App.GetWarnMetricsStatus()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
status, appErr := c.App.GetWarnMetricsStatus()
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(status)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getWarnMetricsStatus", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(status)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getWarnMetricsStatus", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -871,10 +891,9 @@ func getProductNotices(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
clientVersion := r.URL.Query().Get("clientVersion")
|
||||
locale := r.URL.Query().Get("locale")
|
||||
|
||||
notices, err := c.App.GetProductNotices(c.AppContext, c.AppContext.Session().UserId, c.Params.TeamId, client, clientVersion, locale)
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
notices, appErr := c.App.GetProductNotices(c.AppContext, c.AppContext.Session().UserId, c.Params.TeamId, client, clientVersion, locale)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
result, _ := notices.Marshal()
|
||||
@@ -887,9 +906,9 @@ func updateViewedProductNotices(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
c.LogAudit("attempt")
|
||||
|
||||
ids := model.ArrayFromJSON(r.Body)
|
||||
err := c.App.UpdateViewedProductNotices(c.AppContext.Session().UserId, ids)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
appErr := c.App.UpdateViewedProductNotices(c.AppContext.Session().UserId, ids)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -910,7 +929,7 @@ func getOnboarding(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
firstAdminCompleteSetupObj, err := c.App.GetOnboarding()
|
||||
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getOnboarding", "app.system.get_onboarding_request.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("getOnboarding", "app.system.get_onboarding_request.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -931,7 +950,7 @@ func completeOnboarding(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
onboardingRequest, err := model.CompleteOnboardingRequestFromReader(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("completeOnboarding", "app.system.complete_onboarding_request.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("completeOnboarding", "app.system.complete_onboarding_request.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.AddEventParameter("install_plugin", onboardingRequest.InstallPlugins)
|
||||
@@ -962,9 +981,9 @@ func getAppliedSchemaMigrations(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(migrations)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getAppliedMigrations", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(migrations)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getAppliedMigrations", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ func localCheckIntegrity(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
data, err := json.Marshal(results)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.localCheckIntegrity", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.localCheckIntegrity", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
300
api4/team.go
300
api4/team.go
@@ -485,19 +485,20 @@ func getTeamsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
teams, err := c.App.GetTeamsForUser(c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
teams, appErr := c.App.GetTeamsForUser(c.Params.UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
c.App.SanitizeTeams(*c.AppContext.Session(), teams)
|
||||
|
||||
js, jsonErr := json.Marshal(teams)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamsForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(teams)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTeamsForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -516,15 +517,15 @@ func getTeamsUnreadForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teamId := r.URL.Query().Get("exclude_team")
|
||||
includeCollapsedThreads := r.URL.Query().Get("include_collapsed_threads") == "true"
|
||||
|
||||
unreadTeamsList, err := c.App.GetTeamsUnreadForUser(teamId, c.Params.UserId, includeCollapsedThreads)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
unreadTeamsList, appErr := c.App.GetTeamsUnreadForUser(teamId, c.Params.UserId, includeCollapsedThreads)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(unreadTeamsList)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamsUnreadForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(unreadTeamsList)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTeamsUnreadForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
@@ -541,9 +542,9 @@ func getTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.AppContext.Session().UserId, c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
canSee, appErr := c.App.UserCanSeeOtherUser(c.AppContext.Session().UserId, c.Params.UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -552,9 +553,9 @@ func getTeamMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
team, err := c.App.GetTeamMember(c.Params.TeamId, c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
team, appErr := c.App.GetTeamMember(c.Params.TeamId, c.Params.UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -578,9 +579,9 @@ func getTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
restrictions, appErr := c.App.GetViewUsersRestrictions(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -590,17 +591,18 @@ func getTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
ViewRestrictions: restrictions,
|
||||
}
|
||||
|
||||
members, err := c.App.GetTeamMembers(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage, teamMembersGetOptions)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
members, appErr := c.App.GetTeamMembers(c.Params.TeamId, c.Params.Page*c.Params.PerPage, c.Params.PerPage, teamMembersGetOptions)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(members)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamMembers", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(members)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTeamMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -615,9 +617,9 @@ func getTeamMembersForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
canSee, err := c.App.UserCanSeeOtherUser(c.AppContext.Session().UserId, c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
canSee, appErr := c.App.UserCanSeeOtherUser(c.AppContext.Session().UserId, c.Params.UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -626,17 +628,18 @@ func getTeamMembersForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
members, err := c.App.GetTeamMembersForUser(c.Params.UserId, "", true)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
members, appErr := c.App.GetTeamMembersForUser(c.Params.UserId, "", true)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(members)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamMembersForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(members)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTeamMembersForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -646,10 +649,10 @@ func getTeamMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
userIds := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(userIds) == 0 {
|
||||
c.SetInvalidParam("user_ids")
|
||||
var userIDs []string
|
||||
err := json.NewDecoder(r.Body).Decode(&userIDs)
|
||||
if err != nil || len(userIDs) == 0 {
|
||||
c.SetInvalidParamWithErr("user_ids", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -658,23 +661,24 @@ func getTeamMembersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
restrictions, appErr := c.App.GetViewUsersRestrictions(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
members, err := c.App.GetTeamMembersByIds(c.Params.TeamId, userIds, restrictions)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
members, appErr := c.App.GetTeamMembersByIds(c.Params.TeamId, userIDs, restrictions)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(members)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getTeamMembersByIds", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(members)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getTeamMembersByIds", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -815,7 +819,7 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var err *model.AppError
|
||||
var appErr *model.AppError
|
||||
var members []*model.TeamMember
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&members); jsonErr != nil {
|
||||
c.SetInvalidParamWithErr("members", jsonErr)
|
||||
@@ -843,9 +847,9 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
auditRec.AddMeta("user_ids", memberIDs)
|
||||
|
||||
team, err := c.App.GetTeam(c.Params.TeamId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
team, appErr := c.App.GetTeam(c.Params.TeamId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
auditRec.AddMeta("team", team)
|
||||
@@ -856,7 +860,7 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if v, ok := err.(*model.AppError); ok {
|
||||
c.Err = v
|
||||
} else {
|
||||
c.Err = model.NewAppError("addTeamMembers", "api.team.add_members.error", nil, err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("addTeamMembers", "api.team.add_members.error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -866,7 +870,7 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
var userIds []string
|
||||
var userIDs []string
|
||||
for _, member := range members {
|
||||
if member.TeamId != c.Params.TeamId {
|
||||
c.SetInvalidParam("team_id for member with user_id=" + member.UserId)
|
||||
@@ -878,7 +882,7 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
userIds = append(userIds, member.UserId)
|
||||
userIDs = append(userIDs, member.UserId)
|
||||
}
|
||||
|
||||
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), c.Params.TeamId, model.PermissionAddUserToTeam) {
|
||||
@@ -886,9 +890,9 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
membersWithErrors, err := c.App.AddTeamMembers(c.AppContext, c.Params.TeamId, userIds, c.AppContext.Session().UserId, graceful)
|
||||
membersWithErrors, appErr := c.App.AddTeamMembers(c.AppContext, c.Params.TeamId, userIDs, c.AppContext.Session().UserId, graceful)
|
||||
|
||||
if membersWithErrors != nil {
|
||||
if len(membersWithErrors) != 0 {
|
||||
errList := make([]string, 0, len(membersWithErrors))
|
||||
for _, m := range membersWithErrors {
|
||||
if m.Error != nil {
|
||||
@@ -897,21 +901,23 @@ func addTeamMembers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
auditRec.AddMeta("errors", errList)
|
||||
}
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
var js []byte
|
||||
var jsonErr error
|
||||
var (
|
||||
js []byte
|
||||
err error
|
||||
)
|
||||
if graceful {
|
||||
// in 'graceful' mode we allow a different return value, notifying the client which users were not added
|
||||
js, jsonErr = json.Marshal(membersWithErrors)
|
||||
js, err = json.Marshal(membersWithErrors)
|
||||
} else {
|
||||
js, jsonErr = json.Marshal(model.TeamMembersWithErrorToTeamMembers(membersWithErrors))
|
||||
js, err = json.Marshal(model.TeamMembersWithErrorToTeamMembers(membersWithErrors))
|
||||
}
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("addTeamMembers", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("addTeamMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1095,7 +1101,7 @@ func updateTeamMemberSchemeRoles(c *Context, w http.ResponseWriter, r *http.Requ
|
||||
|
||||
func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teams := []*model.Team{}
|
||||
var err *model.AppError
|
||||
var appErr *model.AppError
|
||||
var teamsWithCount *model.TeamsWithCount
|
||||
|
||||
opts := &model.TeamSearch{}
|
||||
@@ -1126,26 +1132,28 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if c.Params.IncludeTotalCount {
|
||||
teamsWithCount, err = c.App.GetAllTeamsPageWithCount(offset, limit, opts)
|
||||
teamsWithCount, appErr = c.App.GetAllTeamsPageWithCount(offset, limit, opts)
|
||||
} else {
|
||||
teams, err = c.App.GetAllTeamsPage(offset, limit, opts)
|
||||
teams, appErr = c.App.GetAllTeamsPage(offset, limit, opts)
|
||||
}
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
var js []byte
|
||||
var jsonErr error
|
||||
var (
|
||||
js []byte
|
||||
err error
|
||||
)
|
||||
if c.Params.IncludeTotalCount {
|
||||
c.App.SanitizeTeams(*c.AppContext.Session(), teamsWithCount.Teams)
|
||||
js, jsonErr = json.Marshal(teamsWithCount)
|
||||
js, err = json.Marshal(teamsWithCount)
|
||||
} else {
|
||||
c.App.SanitizeTeams(*c.AppContext.Session(), teams)
|
||||
js, jsonErr = json.Marshal(teams)
|
||||
js, err = json.Marshal(teams)
|
||||
}
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getAllTeams", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getAllTeams", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1154,8 +1162,8 @@ func getAllTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func searchTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var props model.TeamSearch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
|
||||
c.SetInvalidParamWithErr("team_search", jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&props); err != nil {
|
||||
c.SetInvalidParamWithErr("team_search", err)
|
||||
return
|
||||
}
|
||||
// Only system managers may use the ExcludePolicyConstrained field
|
||||
@@ -1169,30 +1177,32 @@ func searchTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props.IncludePolicyID = model.NewBool(true)
|
||||
}
|
||||
|
||||
var teams []*model.Team
|
||||
var totalCount int64
|
||||
var err *model.AppError
|
||||
var (
|
||||
teams []*model.Team
|
||||
totalCount int64
|
||||
appErr *model.AppError
|
||||
)
|
||||
|
||||
if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionListPrivateTeams) && c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionListPublicTeams) {
|
||||
teams, totalCount, err = c.App.SearchAllTeams(&props)
|
||||
teams, totalCount, appErr = c.App.SearchAllTeams(&props)
|
||||
} else if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionListPrivateTeams) {
|
||||
if props.Page != nil || props.PerPage != nil {
|
||||
c.Err = model.NewAppError("searchTeams", "api.team.search_teams.pagination_not_implemented.private_team_search", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
teams, err = c.App.SearchPrivateTeams(&props)
|
||||
teams, appErr = c.App.SearchPrivateTeams(&props)
|
||||
} else if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionListPublicTeams) {
|
||||
if props.Page != nil || props.PerPage != nil {
|
||||
c.Err = model.NewAppError("searchTeams", "api.team.search_teams.pagination_not_implemented.public_team_search", nil, "", http.StatusNotImplemented)
|
||||
return
|
||||
}
|
||||
teams, err = c.App.SearchPublicTeams(&props)
|
||||
teams, appErr = c.App.SearchPublicTeams(&props)
|
||||
} else {
|
||||
teams = []*model.Team{}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1203,9 +1213,9 @@ func searchTeams(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
twc := map[string]any{"teams": teams, "total_count": totalCount}
|
||||
payload = model.ToJSON(twc)
|
||||
} else {
|
||||
js, jsonErr := json.Marshal(teams)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchTeams", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(teams)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("searchTeams", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
payload = js
|
||||
@@ -1357,26 +1367,26 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
bf, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeams", "api.team.invite_members_to_team_and_channels.invalid_body.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeams", "api.team.invite_members_to_team_and_channels.invalid_body.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
memberInvite := &model.MemberInvite{}
|
||||
if jsonErr := json.Unmarshal(bf, memberInvite); jsonErr != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeams", "api.team.invite_members_to_team_and_channels.invalid_body_parsing.app_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
if err := json.Unmarshal(bf, memberInvite); err != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeams", "api.team.invite_members_to_team_and_channels.invalid_body_parsing.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
emailList := memberInvite.Emails
|
||||
|
||||
for i := range emailList {
|
||||
emailList[i] = strings.ToLower(emailList[i])
|
||||
}
|
||||
|
||||
if len(emailList) == 0 {
|
||||
c.SetInvalidParam("user_email")
|
||||
return
|
||||
}
|
||||
|
||||
for i := range emailList {
|
||||
emailList[i] = strings.ToLower(emailList[i])
|
||||
}
|
||||
|
||||
auditRec := c.MakeAuditRecord("inviteUsersToTeam", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
auditRec.AddEventParameter("member_invite", memberInvite)
|
||||
@@ -1391,9 +1401,9 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if graceful {
|
||||
var invitesWithError []*model.EmailInviteWithError
|
||||
var err *model.AppError
|
||||
var appErr *model.AppError
|
||||
if emailList != nil {
|
||||
invitesWithError, err = c.App.InviteNewUsersToTeamGracefully(memberInvite, c.Params.TeamId, c.AppContext.Session().UserId, "")
|
||||
invitesWithError, appErr = c.App.InviteNewUsersToTeamGracefully(memberInvite, c.Params.TeamId, c.AppContext.Session().UserId, "")
|
||||
}
|
||||
|
||||
if invitesWithError != nil {
|
||||
@@ -1405,8 +1415,8 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
auditRec.AddMeta("errors", errList)
|
||||
}
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1424,23 +1434,24 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// we then manually schedule the job to send another invite after 48 hours
|
||||
_, e := c.App.Srv().Jobs.CreateJob(model.JobTypeResendInvitationEmail, jobData)
|
||||
if e != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeam", e.Id, nil, e.Error(), e.StatusCode)
|
||||
_, appErr = c.App.Srv().Jobs.CreateJob(model.JobTypeResendInvitationEmail, jobData)
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeam", appErr.Id, nil, appErr.Error(), appErr.StatusCode)
|
||||
return
|
||||
}
|
||||
|
||||
// in graceful mode we return both the successful ones and the failed ones
|
||||
js, jsonErr := json.Marshal(invitesWithError)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("inviteUsersToTeam", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(invitesWithError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("inviteUsersToTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
} else {
|
||||
err := c.App.InviteNewUsersToTeam(emailList, c.Params.TeamId, c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
appErr := c.App.InviteNewUsersToTeam(emailList, c.Params.TeamId, c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
ReturnStatusOK(w)
|
||||
@@ -1475,8 +1486,8 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
var guestsInvite model.GuestsInvite
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&guestsInvite); jsonErr != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteGuestsToChannels", "api.team.invite_guests_to_channels.invalid_body.app_error", nil, "", http.StatusBadRequest).Wrap(jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&guestsInvite); err != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteGuestsToChannels", "api.team.invite_guests_to_channels.invalid_body.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
auditRec.AddEventParameter("guests_invite", guestsInvite)
|
||||
@@ -1484,8 +1495,8 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
for i, email := range guestsInvite.Emails {
|
||||
guestsInvite.Emails[i] = strings.ToLower(email)
|
||||
}
|
||||
if err := guestsInvite.IsValid(); err != nil {
|
||||
c.Err = err
|
||||
if appErr := guestsInvite.IsValid(); appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
auditRec.AddMeta("email_count", len(guestsInvite.Emails))
|
||||
@@ -1495,32 +1506,33 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
|
||||
if graceful {
|
||||
var invitesWithError []*model.EmailInviteWithError
|
||||
var err *model.AppError
|
||||
var appErr *model.AppError
|
||||
|
||||
if guestsInvite.Emails != nil {
|
||||
invitesWithError, err = c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, &guestsInvite, c.AppContext.Session().UserId)
|
||||
invitesWithError, appErr = c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, &guestsInvite, c.AppContext.Session().UserId)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if appErr != nil {
|
||||
errList := make([]string, 0, len(invitesWithError))
|
||||
for _, inv := range invitesWithError {
|
||||
errList = append(errList, model.EmailInviteWithErrorToString(inv))
|
||||
}
|
||||
auditRec.AddMeta("errors", errList)
|
||||
c.Err = err
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
// in graceful mode we return both the successful ones and the failed ones
|
||||
js, jsonErr := json.Marshal(invitesWithError)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("inviteGuestsToChannel", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(invitesWithError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("inviteGuestsToChannel", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
} else {
|
||||
err := c.App.InviteGuestsToChannels(c.Params.TeamId, &guestsInvite, c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
appErr := c.App.InviteGuestsToChannels(c.Params.TeamId, &guestsInvite, c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
ReturnStatusOK(w)
|
||||
@@ -1534,9 +1546,9 @@ func getInviteInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
team, err := c.App.GetTeamByInviteId(c.Params.InviteId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
team, appErr := c.App.GetTeamByInviteId(c.Params.InviteId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1545,12 +1557,22 @@ func getInviteInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
result := map[string]string{}
|
||||
result["display_name"] = team.DisplayName
|
||||
result["description"] = team.Description
|
||||
result["name"] = team.Name
|
||||
result["id"] = team.Id
|
||||
w.Write([]byte(model.MapToJSON(result)))
|
||||
result := struct {
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
Name string `json:"name"`
|
||||
ID string `json:"id"`
|
||||
}{
|
||||
DisplayName: team.DisplayName,
|
||||
Description: team.Description,
|
||||
Name: team.Name,
|
||||
ID: team.Id,
|
||||
}
|
||||
|
||||
err := json.NewEncoder(w).Encode(result)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func invalidateAllEmailInvites(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -1781,23 +1803,23 @@ func teamMembersMinusGroupMembers(c *Context, w http.ResponseWriter, r *http.Req
|
||||
return
|
||||
}
|
||||
|
||||
users, totalCount, err := c.App.TeamMembersMinusGroupMembers(
|
||||
users, totalCount, appErr := c.App.TeamMembersMinusGroupMembers(
|
||||
c.Params.TeamId,
|
||||
groupIDs,
|
||||
c.Params.Page,
|
||||
c.Params.PerPage,
|
||||
)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, marshalErr := json.Marshal(&model.UsersWithGroupsAndCount{
|
||||
b, err := json.Marshal(&model.UsersWithGroupsAndCount{
|
||||
Users: users,
|
||||
Count: totalCount,
|
||||
})
|
||||
if marshalErr != nil {
|
||||
c.Err = model.NewAppError("Api4.teamMembersMinusGroupMembers", "api.marshal_error", nil, marshalErr.Error(), http.StatusInternalServerError)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.teamMembersMinusGroupMembers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -81,12 +81,13 @@ func localInviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
|
||||
bf, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeams", "api.team.invite_members_to_team_and_channels.invalid_body.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeams", "api.team.invite_members_to_team_and_channels.invalid_body.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
memberInvite := &model.MemberInvite{}
|
||||
if jsonErr := json.Unmarshal(bf, memberInvite); jsonErr != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeams", "api.team.invite_members_to_team_and_channels.invalid_body_parsing.app_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
err = json.Unmarshal(bf, memberInvite)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.inviteUsersToTeams", "api.team.invite_members_to_team_and_channels.invalid_body_parsing.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -117,14 +118,14 @@ func localInviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
auditRec.AddMeta("channels", memberInvite.ChannelIds)
|
||||
}
|
||||
|
||||
team, nErr := c.App.Srv().Store.Team().Get(c.Params.TeamId)
|
||||
if nErr != nil {
|
||||
team, err := c.App.Srv().Store.Team().Get(c.Params.TeamId)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(nErr, &nfErr):
|
||||
c.Err = model.NewAppError("localInviteUsersToTeam", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
case errors.As(err, &nfErr):
|
||||
c.Err = model.NewAppError("localInviteUsersToTeam", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(err)
|
||||
default:
|
||||
c.Err = model.NewAppError("localInviteUsersToTeam", "app.team.get.finding.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("localInviteUsersToTeam", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -135,7 +136,7 @@ func localInviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
if len(memberInvite.ChannelIds) > 0 {
|
||||
channels, err = c.App.Srv().Store.Channel().GetChannelsByIds(memberInvite.ChannelIds, false)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("prepareLocalInviteNewUsersToTeam", "app.channel.get_channels_by_ids.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("prepareLocalInviteNewUsersToTeam", "app.channel.get_channels_by_ids.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,33 +158,34 @@ func localInviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
auditRec.AddMeta("errors", errList)
|
||||
if len(goodEmails) > 0 {
|
||||
var eErr error
|
||||
var invitesWithErrors2 []*model.EmailInviteWithError
|
||||
if len(channels) > 0 {
|
||||
invitesWithErrors2, eErr = c.App.Srv().EmailService.SendInviteEmailsToTeamAndChannels(team, channels, "Administrator", "mmctl "+model.NewId(), nil, goodEmails, *c.App.Config().ServiceSettings.SiteURL, nil, memberInvite.Message, true)
|
||||
invitesWithErrors2, err = c.App.Srv().EmailService.SendInviteEmailsToTeamAndChannels(team, channels, "Administrator", "mmctl "+model.NewId(), nil, goodEmails, *c.App.Config().ServiceSettings.SiteURL, nil, memberInvite.Message, true)
|
||||
invitesWithErrors = append(invitesWithErrors, invitesWithErrors2...)
|
||||
} else {
|
||||
eErr = c.App.Srv().EmailService.SendInviteEmails(team, "Administrator", "mmctl "+model.NewId(), goodEmails, *c.App.Config().ServiceSettings.SiteURL, nil, false)
|
||||
err = c.App.Srv().EmailService.SendInviteEmails(team, "Administrator", "mmctl "+model.NewId(), goodEmails, *c.App.Config().ServiceSettings.SiteURL, nil, false)
|
||||
}
|
||||
|
||||
if eErr != nil {
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, email.NoRateLimiterError):
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.no_rate_limiter.app_error", nil, fmt.Sprintf("team_id=%s", team.Id), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.no_rate_limiter.app_error", nil, fmt.Sprintf("team_id=%s", team.Id), http.StatusInternalServerError).Wrap(err)
|
||||
case errors.Is(err, email.SetupRateLimiterError):
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.setup_rate_limiter.app_error", nil, fmt.Sprintf("team_id=%s, error=%v", team.Id, err), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.setup_rate_limiter.app_error", nil, fmt.Sprintf("team_id=%s, error=%v", team.Id, err), http.StatusInternalServerError).Wrap(err)
|
||||
default:
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.rate_limit_exceeded.app_error", nil, fmt.Sprintf("team_id=%s, error=%v", team.Id, err), http.StatusRequestEntityTooLarge)
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.rate_limit_exceeded.app_error", nil, fmt.Sprintf("team_id=%s, error=%v", team.Id, err), http.StatusRequestEntityTooLarge).Wrap(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// in graceful mode we return both the successful ones and the failed ones
|
||||
js, jsonErr := json.Marshal(invitesWithErrors)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("localInviteUsersToTeam", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(invitesWithErrors)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("localInviteUsersToTeam", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
} else {
|
||||
var invalidEmailList []string
|
||||
@@ -202,11 +204,11 @@ func localInviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, email.NoRateLimiterError):
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.no_rate_limiter.app_error", nil, fmt.Sprintf("team_id=%s", team.Id), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.no_rate_limiter.app_error", nil, fmt.Sprintf("team_id=%s", team.Id), http.StatusInternalServerError).Wrap(err)
|
||||
case errors.Is(err, email.SetupRateLimiterError):
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.setup_rate_limiter.app_error", nil, fmt.Sprintf("team_id=%s, error=%v", team.Id, err), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.setup_rate_limiter.app_error", nil, fmt.Sprintf("team_id=%s, error=%v", team.Id, err), http.StatusInternalServerError).Wrap(err)
|
||||
default:
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.rate_limit_exceeded.app_error", nil, fmt.Sprintf("team_id=%s, error=%v", team.Id, err), http.StatusRequestEntityTooLarge)
|
||||
c.Err = model.NewAppError("SendInviteEmails", "app.email.rate_limit_exceeded.app_error", nil, fmt.Sprintf("team_id=%s, error=%v", team.Id, err), http.StatusRequestEntityTooLarge).Wrap(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ func (api *API) InitUsage() {
|
||||
func getPostsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
count, appErr := c.App.GetPostsUsage()
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getPostsUsage", "app.post.analytics_posts_count.app_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getPostsUsage", "app.post.analytics_posts_count.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(&model.PostsUsage{Count: count})
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getPostsUsage", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getPostsUsage", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ func getPostsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func getStorageUsage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
usage, appErr := c.App.GetStorageUsage()
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getStorageUsage", "app.usage.get_storage_usage.app_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getStorageUsage", "app.usage.get_storage_usage.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
||||
return
|
||||
}
|
||||
|
||||
usage = utils.RoundOffToZeroesResolution(float64(usage), 8)
|
||||
json, err := json.Marshal(&model.StorageUsage{Bytes: usage})
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getStorageUsage", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getStorageUsage", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -58,17 +58,17 @@ func getStorageUsage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func getTeamsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teamsUsage, appErr := c.App.GetTeamsUsage()
|
||||
if appErr != nil {
|
||||
c.Err = model.NewAppError("Api4.getTeamsUsage", "app.teams.analytics_teams_count.app_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getTeamsUsage", "app.teams.analytics_teams_count.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
||||
return
|
||||
}
|
||||
|
||||
if teamsUsage == nil {
|
||||
c.Err = model.NewAppError("Api4.getTeamsUsage", "app.teams.analytics_teams_count.app_error", nil, appErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getTeamsUsage", "app.teams.analytics_teams_count.app_error", nil, "", http.StatusInternalServerError).Wrap(appErr)
|
||||
}
|
||||
|
||||
json, err := json.Marshal(teamsUsage)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getTeamsUsage", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getTeamsUsage", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func getIntegrationsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !*c.App.Config().PluginSettings.Enable {
|
||||
json, err := json.Marshal(&model.IntegrationsUsage{})
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getIntegrationsUsage", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getIntegrationsUsage", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func getIntegrationsUsage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
json, err := json.Marshal(usage)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("Api4.getIntegrationsUsage", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("Api4.getIntegrationsUsage", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
344
api4/user.go
344
api4/user.go
@@ -622,32 +622,37 @@ func getUsersByGroupChannelIds(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
usersByChannelId, err := c.App.GetUsersByGroupChannelIds(c.AppContext, channelIds, c.IsSystemAdmin())
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
usersByChannelId, appErr := c.App.GetUsersByGroupChannelIds(c.AppContext, channelIds, c.IsSystemAdmin())
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(usersByChannelId)
|
||||
w.Write(b)
|
||||
err := json.NewEncoder(w).Encode(usersByChannelId)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
inTeamId := r.URL.Query().Get("in_team")
|
||||
notInTeamId := r.URL.Query().Get("not_in_team")
|
||||
inChannelId := r.URL.Query().Get("in_channel")
|
||||
inGroupId := r.URL.Query().Get("in_group")
|
||||
notInGroupId := r.URL.Query().Get("not_in_group")
|
||||
notInChannelId := r.URL.Query().Get("not_in_channel")
|
||||
groupConstrained := r.URL.Query().Get("group_constrained")
|
||||
withoutTeam := r.URL.Query().Get("without_team")
|
||||
inactive := r.URL.Query().Get("inactive")
|
||||
active := r.URL.Query().Get("active")
|
||||
role := r.URL.Query().Get("role")
|
||||
sort := r.URL.Query().Get("sort")
|
||||
rolesString := r.URL.Query().Get("roles")
|
||||
channelRolesString := r.URL.Query().Get("channel_roles")
|
||||
teamRolesString := r.URL.Query().Get("team_roles")
|
||||
var (
|
||||
query = r.URL.Query()
|
||||
inTeamId = query.Get("in_team")
|
||||
notInTeamId = query.Get("not_in_team")
|
||||
inChannelId = query.Get("in_channel")
|
||||
inGroupId = query.Get("in_group")
|
||||
notInGroupId = query.Get("not_in_group")
|
||||
notInChannelId = query.Get("not_in_channel")
|
||||
groupConstrained = query.Get("group_constrained")
|
||||
withoutTeam = query.Get("without_team")
|
||||
inactive = query.Get("inactive")
|
||||
active = query.Get("active")
|
||||
role = query.Get("role")
|
||||
sort = query.Get("sort")
|
||||
rolesString = query.Get("roles")
|
||||
channelRolesString = query.Get("channel_roles")
|
||||
teamRolesString = query.Get("team_roles")
|
||||
)
|
||||
|
||||
if notInChannelId != "" && inTeamId == "" {
|
||||
c.SetInvalidURLParam("team_id")
|
||||
@@ -674,10 +679,12 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
withoutTeamBool, _ := strconv.ParseBool(withoutTeam)
|
||||
groupConstrainedBool, _ := strconv.ParseBool(groupConstrained)
|
||||
inactiveBool, _ := strconv.ParseBool(inactive)
|
||||
activeBool, _ := strconv.ParseBool(active)
|
||||
var (
|
||||
withoutTeamBool, _ = strconv.ParseBool(withoutTeam)
|
||||
groupConstrainedBool, _ = strconv.ParseBool(groupConstrained)
|
||||
inactiveBool, _ = strconv.ParseBool(inactive)
|
||||
activeBool, _ = strconv.ParseBool(active)
|
||||
)
|
||||
|
||||
if inactiveBool && activeBool {
|
||||
c.SetInvalidURLParam("inactive")
|
||||
@@ -709,9 +716,9 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
restrictions, appErr := c.App.GetViewUsersRestrictions(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -736,14 +743,16 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
ViewRestrictions: restrictions,
|
||||
}
|
||||
|
||||
var profiles []*model.User
|
||||
etag := ""
|
||||
var (
|
||||
profiles []*model.User
|
||||
etag string
|
||||
)
|
||||
|
||||
if inChannelId != "" {
|
||||
if !*c.App.Config().TeamSettings.ExperimentalViewArchivedChannels {
|
||||
channel, appErr := c.App.GetChannel(c.AppContext, inChannelId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
channel, cErr := c.App.GetChannel(c.AppContext, inChannelId)
|
||||
if cErr != nil {
|
||||
c.Err = cErr
|
||||
return
|
||||
}
|
||||
if channel.DeleteAt != 0 {
|
||||
@@ -760,14 +769,14 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err = c.App.GetUsersWithoutTeamPage(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersWithoutTeamPage(userGetOptions, c.IsSystemAdmin())
|
||||
} else if notInChannelId != "" {
|
||||
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), notInChannelId, model.PermissionReadChannel) {
|
||||
c.SetPermissionError(model.PermissionReadChannel)
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err = c.App.GetUsersNotInChannelPage(inTeamId, notInChannelId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
|
||||
profiles, appErr = c.App.GetUsersNotInChannelPage(inTeamId, notInChannelId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
|
||||
} else if notInTeamId != "" {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), notInTeamId, model.PermissionViewTeam) {
|
||||
c.SetPermissionError(model.PermissionViewTeam)
|
||||
@@ -779,7 +788,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err = c.App.GetUsersNotInTeamPage(notInTeamId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
|
||||
profiles, appErr = c.App.GetUsersNotInTeamPage(notInTeamId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
|
||||
} else if inTeamId != "" {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), inTeamId, model.PermissionViewTeam) {
|
||||
c.SetPermissionError(model.PermissionViewTeam)
|
||||
@@ -787,15 +796,15 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if sort == "last_activity_at" {
|
||||
profiles, err = c.App.GetRecentlyActiveUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
|
||||
profiles, appErr = c.App.GetRecentlyActiveUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
|
||||
} else if sort == "create_at" {
|
||||
profiles, err = c.App.GetNewUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
|
||||
profiles, appErr = c.App.GetNewUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
|
||||
} else {
|
||||
etag = c.App.GetUsersInTeamEtag(inTeamId, restrictions.Hash())
|
||||
if c.HandleEtag(etag, "Get Users in Team", w, r) {
|
||||
return
|
||||
}
|
||||
profiles, err = c.App.GetUsersInTeamPage(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersInTeamPage(userGetOptions, c.IsSystemAdmin())
|
||||
}
|
||||
} else if inChannelId != "" {
|
||||
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), inChannelId, model.PermissionReadChannel) {
|
||||
@@ -804,11 +813,11 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if sort == "status" {
|
||||
profiles, err = c.App.GetUsersInChannelPageByStatus(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersInChannelPageByStatus(userGetOptions, c.IsSystemAdmin())
|
||||
} else if sort == "admin" {
|
||||
profiles, err = c.App.GetUsersInChannelPageByAdmin(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersInChannelPageByAdmin(userGetOptions, c.IsSystemAdmin())
|
||||
} else {
|
||||
profiles, err = c.App.GetUsersInChannelPage(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersInChannelPage(userGetOptions, c.IsSystemAdmin())
|
||||
}
|
||||
} else if inGroupId != "" {
|
||||
if gErr := requireGroupAccess(c, inGroupId); gErr != nil {
|
||||
@@ -817,34 +826,35 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
profiles, _, err = c.App.GetGroupMemberUsersPage(inGroupId, c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
profiles, _, appErr = c.App.GetGroupMemberUsersPage(inGroupId, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
} else if notInGroupId != "" {
|
||||
if gErr := requireGroupAccess(c, notInGroupId); gErr != nil {
|
||||
gErr.Where = "Api.getUsers"
|
||||
c.Err = gErr
|
||||
appErr = requireGroupAccess(c, notInGroupId)
|
||||
if appErr != nil {
|
||||
appErr.Where = "Api.getUsers"
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err = c.App.GetUsersNotInGroupPage(notInGroupId, c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
profiles, appErr = c.App.GetUsersNotInGroupPage(notInGroupId, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
} else {
|
||||
userGetOptions, err = c.App.RestrictUsersGetByPermissions(c.AppContext.Session().UserId, userGetOptions)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
userGetOptions, appErr = c.App.RestrictUsersGetByPermissions(c.AppContext.Session().UserId, userGetOptions)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
profiles, err = c.App.GetUsersPage(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersPage(userGetOptions, c.IsSystemAdmin())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -853,9 +863,9 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
c.App.UpdateLastActivityAtIfNeeded(*c.AppContext.Session())
|
||||
|
||||
js, jsonErr := json.Marshal(profiles)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getUsers", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(profiles)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getUsers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -882,10 +892,10 @@ func requireGroupAccess(c *web.Context, groupID string) *model.AppError {
|
||||
}
|
||||
|
||||
func getUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userIds := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(userIds) == 0 {
|
||||
c.SetInvalidParam("user_ids")
|
||||
var userIDs []string
|
||||
err := json.NewDecoder(r.Body).Decode(&userIDs)
|
||||
if err != nil || len(userIDs) == 0 {
|
||||
c.SetInvalidParamWithErr("user_ids", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -896,30 +906,30 @@ func getUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if sinceString != "" {
|
||||
since, parseError := strconv.ParseInt(sinceString, 10, 64)
|
||||
if parseError != nil {
|
||||
c.SetInvalidParam("since")
|
||||
since, sErr := strconv.ParseInt(sinceString, 10, 64)
|
||||
if sErr != nil {
|
||||
c.SetInvalidParamWithErr("since", sErr)
|
||||
return
|
||||
}
|
||||
options.Since = since
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
restrictions, appErr := c.App.GetViewUsersRestrictions(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
options.ViewRestrictions = restrictions
|
||||
|
||||
users, err := c.App.GetUsersByIds(userIds, options)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
users, appErr := c.App.GetUsersByIds(userIDs, options)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(users)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getUsersByIds", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(users)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getUsersByIds", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -927,28 +937,28 @@ func getUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getUsersByNames(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
usernames := model.ArrayFromJSON(r.Body)
|
||||
|
||||
if len(usernames) == 0 {
|
||||
c.SetInvalidParam("usernames")
|
||||
var usernames []string
|
||||
err := json.NewDecoder(r.Body).Decode(&usernames)
|
||||
if err != nil || len(usernames) == 0 {
|
||||
c.SetInvalidParamWithErr("usernames", err)
|
||||
return
|
||||
}
|
||||
|
||||
restrictions, err := c.App.GetViewUsersRestrictions(c.AppContext.Session().UserId)
|
||||
restrictions, appErr := c.App.GetViewUsersRestrictions(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
users, appErr := c.App.GetUsersByUsernames(usernames, c.IsSystemAdmin(), restrictions)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, err := json.Marshal(users)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
users, err := c.App.GetUsersByUsernames(usernames, c.IsSystemAdmin(), restrictions)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(users)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getUsersByNames", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
c.Err = model.NewAppError("getUsersByNames", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -956,21 +966,22 @@ func getUsersByNames(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getKnownUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
userIds, err := c.App.GetKnownUsers(c.AppContext.Session().UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
userIDs, appErr := c.App.GetKnownUsers(c.AppContext.Session().UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(userIds)
|
||||
|
||||
w.Write(data)
|
||||
err := json.NewEncoder(w).Encode(userIDs)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var props model.UserSearch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
|
||||
c.SetInvalidParamWithErr("props", jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&props); err != nil {
|
||||
c.SetInvalidParamWithErr("props", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -989,17 +1000,17 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if props.InGroupId != "" {
|
||||
if gErr := requireGroupAccess(c, props.InGroupId); gErr != nil {
|
||||
gErr.Where = "Api.searchUsers"
|
||||
c.Err = gErr
|
||||
if appErr := requireGroupAccess(c, props.InGroupId); appErr != nil {
|
||||
appErr.Where = "Api.searchUsers"
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if props.NotInGroupId != "" {
|
||||
if gErr := requireGroupAccess(c, props.NotInGroupId); gErr != nil {
|
||||
gErr.Where = "Api.searchUsers"
|
||||
c.Err = gErr
|
||||
if appErr := requireGroupAccess(c, props.NotInGroupId); appErr != nil {
|
||||
appErr.Where = "Api.searchUsers"
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -1048,21 +1059,21 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
options.AllowFullNames = *c.App.Config().PrivacySettings.ShowFullName
|
||||
}
|
||||
|
||||
options, err := c.App.RestrictUsersSearchByPermissions(c.AppContext.Session().UserId, options)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
options, appErr := c.App.RestrictUsersSearchByPermissions(c.AppContext.Session().UserId, options)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err := c.App.SearchUsers(&props, options)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
profiles, appErr := c.App.SearchUsers(&props, options)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(profiles)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchUsers", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(profiles)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("searchUsers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1973,9 +1984,9 @@ func getSessions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sessions, err := c.App.GetSessions(c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
sessions, appErr := c.App.GetSessions(c.Params.UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1983,11 +1994,12 @@ func getSessions(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
session.Sanitize()
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(sessions)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getSessions", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(sessions)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getSessions", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -2343,8 +2355,8 @@ func searchUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
var props model.UserAccessTokenSearch
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&props); jsonErr != nil {
|
||||
c.SetInvalidParamWithErr("user_access_token_search", jsonErr)
|
||||
if err := json.NewDecoder(r.Body).Decode(&props); err != nil {
|
||||
c.SetInvalidParamWithErr("user_access_token_search", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2353,15 +2365,15 @@ func searchUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
accessTokens, err := c.App.SearchUserAccessTokens(props.Term)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
accessTokens, appErr := c.App.SearchUserAccessTokens(props.Term)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(accessTokens)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchUserAccessTokens", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(accessTokens)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("searchUserAccessTokens", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2374,15 +2386,15 @@ func getUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
accessTokens, err := c.App.GetUserAccessTokens(c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
accessTokens, appErr := c.App.GetUserAccessTokens(c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(accessTokens)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchUserAccessTokens", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(accessTokens)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("searchUserAccessTokens", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2405,15 +2417,15 @@ func getUserAccessTokensForUser(c *Context, w http.ResponseWriter, r *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
accessTokens, err := c.App.GetUserAccessTokensForUser(c.Params.UserId, c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
accessTokens, appErr := c.App.GetUserAccessTokensForUser(c.Params.UserId, c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(accessTokens)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("searchUserAccessTokens", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(accessTokens)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("searchUserAccessTokens", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2431,9 +2443,9 @@ func getUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
accessToken, err := c.App.GetUserAccessToken(c.Params.TokenId, true)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
accessToken, appErr := c.App.GetUserAccessToken(c.Params.TokenId, true)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2791,9 +2803,9 @@ func convertUserToBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.App.GetUser(c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
user, appErr := c.App.GetUser(c.Params.UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2807,9 +2819,9 @@ func convertUserToBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
bot, err := c.App.ConvertUserToBot(user)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
bot, appErr := c.App.ConvertUserToBot(user)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2817,9 +2829,9 @@ func convertUserToBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddEventResultState(bot)
|
||||
auditRec.AddEventObjectType("bot")
|
||||
|
||||
js, jsonErr := json.Marshal(bot)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("convertUserToBot", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(bot)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("convertUserToBot", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -2839,15 +2851,15 @@ func getUploadsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
uss, err := c.App.GetUploadSessionsForUser(c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
uss, appErr := c.App.GetUploadSessionsForUser(c.Params.UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(uss)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getUploadsForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(uss)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getUploadsForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
@@ -3252,14 +3264,16 @@ func getUsersWithInvalidEmails(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
users, err := c.App.GetUsersWithInvalidEmails(c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
users, appErr := c.App.GetUsersWithInvalidEmails(c.Params.Page, c.Params.PerPage)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(users)
|
||||
w.Write(b)
|
||||
err := json.NewEncoder(w).Encode(users)
|
||||
if err != nil {
|
||||
c.Logger.Warn("Error writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func getRecentSearches(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -100,45 +100,47 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
ViewRestrictions: nil,
|
||||
}
|
||||
|
||||
var err *model.AppError
|
||||
var profiles []*model.User
|
||||
etag := ""
|
||||
var (
|
||||
appErr *model.AppError
|
||||
profiles []*model.User
|
||||
etag string
|
||||
)
|
||||
|
||||
if withoutTeamBool, _ := strconv.ParseBool(withoutTeam); withoutTeamBool {
|
||||
profiles, err = c.App.GetUsersWithoutTeamPage(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersWithoutTeamPage(userGetOptions, c.IsSystemAdmin())
|
||||
} else if notInChannelId != "" {
|
||||
profiles, err = c.App.GetUsersNotInChannelPage(inTeamId, notInChannelId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
|
||||
profiles, appErr = c.App.GetUsersNotInChannelPage(inTeamId, notInChannelId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
|
||||
} else if notInTeamId != "" {
|
||||
etag = c.App.GetUsersNotInTeamEtag(inTeamId, "")
|
||||
if c.HandleEtag(etag, "Get Users Not in Team", w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
profiles, err = c.App.GetUsersNotInTeamPage(notInTeamId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
|
||||
profiles, appErr = c.App.GetUsersNotInTeamPage(notInTeamId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
|
||||
} else if inTeamId != "" {
|
||||
if sort == "last_activity_at" {
|
||||
profiles, err = c.App.GetRecentlyActiveUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
|
||||
profiles, appErr = c.App.GetRecentlyActiveUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
|
||||
} else if sort == "create_at" {
|
||||
profiles, err = c.App.GetNewUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
|
||||
profiles, appErr = c.App.GetNewUsersForTeamPage(inTeamId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), nil)
|
||||
} else {
|
||||
etag = c.App.GetUsersInTeamEtag(inTeamId, "")
|
||||
if c.HandleEtag(etag, "Get Users in Team", w, r) {
|
||||
return
|
||||
}
|
||||
profiles, err = c.App.GetUsersInTeamPage(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersInTeamPage(userGetOptions, c.IsSystemAdmin())
|
||||
}
|
||||
} else if inChannelId != "" {
|
||||
if sort == "status" {
|
||||
profiles, err = c.App.GetUsersInChannelPageByStatus(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersInChannelPageByStatus(userGetOptions, c.IsSystemAdmin())
|
||||
} else {
|
||||
profiles, err = c.App.GetUsersInChannelPage(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersInChannelPage(userGetOptions, c.IsSystemAdmin())
|
||||
}
|
||||
} else {
|
||||
profiles, err = c.App.GetUsersPage(userGetOptions, c.IsSystemAdmin())
|
||||
profiles, appErr = c.App.GetUsersPage(userGetOptions, c.IsSystemAdmin())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -146,9 +148,9 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set(model.HeaderEtagServer, etag)
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(profiles)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("localGetUsers", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(profiles)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("localGetUsers", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -170,23 +172,23 @@ func localGetUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
options.Since = since
|
||||
}
|
||||
|
||||
users, err := c.App.GetUsersByIds(userIds, options)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
users, appErr := c.App.GetUsersByIds(userIds, options)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(users)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("localGetUsersByIds", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(users)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("localGetUsersByIds", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -344,16 +346,17 @@ func localGetUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func localGetUploadsForUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
uss, err := c.App.GetUploadSessionsForUser(c.Params.UserId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
uss, appErr := c.App.GetUploadSessionsForUser(c.Params.UserId)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(uss)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("localGetUploadsForUser", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
js, err := json.Marshal(uss)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("localGetUploadsForUser", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -178,24 +178,26 @@ func updateIncomingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
teamId := r.URL.Query().Get("team_id")
|
||||
userId := c.AppContext.Session().UserId
|
||||
var (
|
||||
teamID = r.URL.Query().Get("team_id")
|
||||
userID = c.AppContext.Session().UserId
|
||||
|
||||
var hooks []*model.IncomingWebhook
|
||||
var err *model.AppError
|
||||
hooks []*model.IncomingWebhook
|
||||
appErr *model.AppError
|
||||
)
|
||||
|
||||
if teamId != "" {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), teamId, model.PermissionManageIncomingWebhooks) {
|
||||
if teamID != "" {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), teamID, model.PermissionManageIncomingWebhooks) {
|
||||
c.SetPermissionError(model.PermissionManageIncomingWebhooks)
|
||||
return
|
||||
}
|
||||
|
||||
// Remove userId as a filter if they have permission to manage others.
|
||||
if c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), teamId, model.PermissionManageOthersIncomingWebhooks) {
|
||||
userId = ""
|
||||
if c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), teamID, model.PermissionManageOthersIncomingWebhooks) {
|
||||
userID = ""
|
||||
}
|
||||
|
||||
hooks, err = c.App.GetIncomingWebhooksForTeamPageByUser(teamId, userId, c.Params.Page, c.Params.PerPage)
|
||||
hooks, appErr = c.App.GetIncomingWebhooksForTeamPageByUser(teamID, userID, c.Params.Page, c.Params.PerPage)
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageIncomingWebhooks) {
|
||||
c.SetPermissionError(model.PermissionManageIncomingWebhooks)
|
||||
@@ -204,22 +206,23 @@ func getIncomingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Remove userId as a filter if they have permission to manage others.
|
||||
if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageOthersIncomingWebhooks) {
|
||||
userId = ""
|
||||
userID = ""
|
||||
}
|
||||
|
||||
hooks, err = c.App.GetIncomingWebhooksPageByUser(userId, c.Params.Page, c.Params.PerPage)
|
||||
hooks, appErr = c.App.GetIncomingWebhooksPageByUser(userID, c.Params.Page, c.Params.PerPage)
|
||||
}
|
||||
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, err := json.Marshal(hooks)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
c.Err = model.NewAppError("getIncomingHooks", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(hooks)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getIncomingHooks", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
@@ -451,37 +454,40 @@ func createOutgoingHook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
channelId := r.URL.Query().Get("channel_id")
|
||||
teamId := r.URL.Query().Get("team_id")
|
||||
userId := c.AppContext.Session().UserId
|
||||
var (
|
||||
query = r.URL.Query()
|
||||
channelID = query.Get("channel_id")
|
||||
teamID = query.Get("team_id")
|
||||
userID = c.AppContext.Session().UserId
|
||||
|
||||
var hooks []*model.OutgoingWebhook
|
||||
var err *model.AppError
|
||||
hooks []*model.OutgoingWebhook
|
||||
appErr *model.AppError
|
||||
)
|
||||
|
||||
if channelId != "" {
|
||||
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelId, model.PermissionManageOutgoingWebhooks) {
|
||||
if channelID != "" {
|
||||
if !c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelID, model.PermissionManageOutgoingWebhooks) {
|
||||
c.SetPermissionError(model.PermissionManageOutgoingWebhooks)
|
||||
return
|
||||
}
|
||||
|
||||
// Remove userId as a filter if they have permission to manage others.
|
||||
if c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelId, model.PermissionManageOthersOutgoingWebhooks) {
|
||||
userId = ""
|
||||
if c.App.SessionHasPermissionToChannel(c.AppContext, *c.AppContext.Session(), channelID, model.PermissionManageOthersOutgoingWebhooks) {
|
||||
userID = ""
|
||||
}
|
||||
|
||||
hooks, err = c.App.GetOutgoingWebhooksForChannelPageByUser(channelId, userId, c.Params.Page, c.Params.PerPage)
|
||||
} else if teamId != "" {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), teamId, model.PermissionManageOutgoingWebhooks) {
|
||||
hooks, appErr = c.App.GetOutgoingWebhooksForChannelPageByUser(channelID, userID, c.Params.Page, c.Params.PerPage)
|
||||
} else if teamID != "" {
|
||||
if !c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), teamID, model.PermissionManageOutgoingWebhooks) {
|
||||
c.SetPermissionError(model.PermissionManageOutgoingWebhooks)
|
||||
return
|
||||
}
|
||||
|
||||
// Remove userId as a filter if they have permission to manage others.
|
||||
if c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), teamId, model.PermissionManageOthersOutgoingWebhooks) {
|
||||
userId = ""
|
||||
if c.App.SessionHasPermissionToTeam(*c.AppContext.Session(), teamID, model.PermissionManageOthersOutgoingWebhooks) {
|
||||
userID = ""
|
||||
}
|
||||
|
||||
hooks, err = c.App.GetOutgoingWebhooksForTeamPageByUser(teamId, userId, c.Params.Page, c.Params.PerPage)
|
||||
hooks, appErr = c.App.GetOutgoingWebhooksForTeamPageByUser(teamID, userID, c.Params.Page, c.Params.PerPage)
|
||||
} else {
|
||||
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageOutgoingWebhooks) {
|
||||
c.SetPermissionError(model.PermissionManageOutgoingWebhooks)
|
||||
@@ -490,22 +496,23 @@ func getOutgoingHooks(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Remove userId as a filter if they have permission to manage others.
|
||||
if c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionManageOthersOutgoingWebhooks) {
|
||||
userId = ""
|
||||
userID = ""
|
||||
}
|
||||
|
||||
hooks, err = c.App.GetOutgoingWebhooksPageByUser(userId, c.Params.Page, c.Params.PerPage)
|
||||
hooks, appErr = c.App.GetOutgoingWebhooksPageByUser(userID, c.Params.Page, c.Params.PerPage)
|
||||
}
|
||||
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
js, err := json.Marshal(hooks)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
c.Err = model.NewAppError("getOutgoingHooks", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
js, jsonErr := json.Marshal(hooks)
|
||||
if jsonErr != nil {
|
||||
c.Err = model.NewAppError("getOutgoingHooks", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Write(js)
|
||||
}
|
||||
|
||||
|
||||
116
app/channel.go
116
app/channel.go
@@ -641,11 +641,11 @@ func (a *App) UpdateChannel(c request.CTX, channel *model.Channel) (*model.Chann
|
||||
var invErr *store.ErrInvalidInput
|
||||
switch {
|
||||
case errors.As(err, &invErr):
|
||||
return nil, model.NewAppError("UpdateChannel", "app.channel.update.bad_id", nil, invErr.Error(), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("UpdateChannel", "app.channel.update.bad_id", nil, "", http.StatusBadRequest).Wrap(invErr)
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
default:
|
||||
return nil, model.NewAppError("UpdateChannel", "app.channel.update_channel.internal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("UpdateChannel", "app.channel.update_channel.internal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1267,9 +1267,9 @@ func (a *App) UpdateChannelMemberNotifyProps(c request.CTX, data map[string]stri
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("updateMemberNotifyProps", MissingChannelMemberError, nil, nfErr.Error(), http.StatusNotFound)
|
||||
return nil, model.NewAppError("updateMemberNotifyProps", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(nfErr)
|
||||
default:
|
||||
return nil, model.NewAppError("updateMemberNotifyProps", "app.channel.get_member.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("updateMemberNotifyProps", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1289,17 +1289,17 @@ func (a *App) UpdateChannelMemberNotifyProps(c request.CTX, data map[string]stri
|
||||
}
|
||||
|
||||
func (a *App) updateChannelMember(c request.CTX, member *model.ChannelMember) (*model.ChannelMember, *model.AppError) {
|
||||
member, nErr := a.Srv().Store.Channel().UpdateMember(member)
|
||||
if nErr != nil {
|
||||
member, err := a.Srv().Store.Channel().UpdateMember(member)
|
||||
if err != nil {
|
||||
var appErr *model.AppError
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
case errors.As(nErr, &nfErr):
|
||||
return nil, model.NewAppError("updateChannelMember", MissingChannelMemberError, nil, nfErr.Error(), http.StatusNotFound)
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("updateChannelMember", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(nfErr)
|
||||
default:
|
||||
return nil, model.NewAppError("updateChannelMember", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("updateChannelMember", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2604,14 +2604,14 @@ func (a *App) MarkChannelAsUnreadFromPost(c request.CTX, postID string, userID s
|
||||
}
|
||||
|
||||
func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID string, userID string) (*model.ChannelUnreadAt, *model.AppError) {
|
||||
post, err := a.GetSinglePost(postID, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
post, appErr := a.GetSinglePost(postID, false)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
user, err := a.GetUser(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
user, appErr := a.GetUser(userID)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
threadId := post.RootId
|
||||
@@ -2619,18 +2619,18 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID st
|
||||
threadId = post.Id
|
||||
}
|
||||
|
||||
unreadMentions, unreadMentionsRoot, err := a.countMentionsFromPost(c, user, post)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
unreadMentions, unreadMentionsRoot, appErr := a.countMentionsFromPost(c, user, post)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
// if root post,
|
||||
// In CRT Supported Client: badge on channel only sums mentions in root posts including and below the post that was marked.
|
||||
// In CRT Unsupported Client: badge on channel sums mentions in all posts (root & replies) including and below the post that was marked unread.
|
||||
if post.RootId == "" {
|
||||
channelUnread, nErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, unreadMentionsRoot, true)
|
||||
if nErr != nil {
|
||||
return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
channelUnread, err := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, unreadMentionsRoot, true)
|
||||
if err != nil {
|
||||
return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
a.sendWebSocketPostUnreadEvent(c, channelUnread, postID, true)
|
||||
@@ -2643,21 +2643,21 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID st
|
||||
// If there are replies with mentions below the marked reply in the thread, then sum the mentions for the threads mention badge.
|
||||
// In CRT Unsupported Client: Channel is marked as unread and new messages line inserted above the marked post.
|
||||
// Badge on channel sums mentions in all posts (root & replies) including and below the post that was marked unread.
|
||||
rootPost, err := a.GetSinglePost(post.RootId, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
rootPost, appErr := a.GetSinglePost(post.RootId, false)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
channel, nErr := a.Srv().Store.Channel().Get(post.ChannelId, true)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
channel, err := a.Srv().Store.Channel().Get(post.ChannelId, true)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.ThreadAutoFollow {
|
||||
threadMembership, sErr := a.Srv().Store.Thread().GetMembershipForUser(user.Id, threadId)
|
||||
threadMembership, mErr := a.Srv().Store.Thread().GetMembershipForUser(user.Id, threadId)
|
||||
var errNotFound *store.ErrNotFound
|
||||
if sErr != nil && !errors.As(sErr, &errNotFound) {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, sErr.Error(), http.StatusInternalServerError)
|
||||
if mErr != nil && !errors.As(mErr, &errNotFound) {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(mErr)
|
||||
}
|
||||
// Follow thread if we're not already following it
|
||||
if threadMembership == nil {
|
||||
@@ -2668,25 +2668,25 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID st
|
||||
UpdateViewedTimestamp: false,
|
||||
UpdateParticipants: false,
|
||||
}
|
||||
threadMembership, sErr = a.Srv().Store.Thread().MaintainMembership(user.Id, threadId, opts)
|
||||
if sErr != nil {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, sErr.Error(), http.StatusInternalServerError)
|
||||
threadMembership, mErr = a.Srv().Store.Thread().MaintainMembership(user.Id, threadId, opts)
|
||||
if mErr != nil {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(mErr)
|
||||
}
|
||||
}
|
||||
// If threadmembership already exists but user had previously unfollowed the thread, then follow the thread again.
|
||||
threadMembership.Following = true
|
||||
threadMembership.LastViewed = post.CreateAt - 1
|
||||
threadMembership.UnreadMentions, err = a.countThreadMentions(c, user, rootPost, channel.TeamId, post.CreateAt-1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
threadMembership.UnreadMentions, appErr = a.countThreadMentions(c, user, rootPost, channel.TeamId, post.CreateAt-1)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
threadMembership, sErr = a.Srv().Store.Thread().UpdateMembership(threadMembership)
|
||||
if sErr != nil {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, sErr.Error(), http.StatusInternalServerError)
|
||||
threadMembership, mErr = a.Srv().Store.Thread().UpdateMembership(threadMembership)
|
||||
if mErr != nil {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(mErr)
|
||||
}
|
||||
thread, sErr := a.Srv().Store.Thread().GetThreadForUser(channel.TeamId, threadMembership, true)
|
||||
if sErr != nil {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, sErr.Error(), http.StatusInternalServerError)
|
||||
thread, mErr := a.Srv().Store.Thread().GetThreadForUser(channel.TeamId, threadMembership, true)
|
||||
if mErr != nil {
|
||||
return nil, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(mErr)
|
||||
}
|
||||
a.sanitizeProfiles(thread.Participants, false)
|
||||
thread.Post.SanitizeProps()
|
||||
@@ -2702,9 +2702,9 @@ func (a *App) markChannelAsUnreadFromPostCRTUnsupported(c request.CTX, postID st
|
||||
}
|
||||
}
|
||||
|
||||
channelUnread, nErr := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, 0, false)
|
||||
if nErr != nil {
|
||||
return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
channelUnread, err := a.Srv().Store.Channel().UpdateLastViewedAtPost(post, userID, unreadMentions, 0, false)
|
||||
if err != nil {
|
||||
return channelUnread, model.NewAppError("MarkChannelAsUnreadFromPost", "app.channel.update_last_viewed_at_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
a.sendWebSocketPostUnreadEvent(c, channelUnread, postID, false)
|
||||
a.UpdateMobileAppBadge(userID)
|
||||
@@ -3213,14 +3213,14 @@ func (a *App) ToggleMuteChannel(c request.CTX, channelID, userID string) (*model
|
||||
}
|
||||
|
||||
func (a *App) setChannelsMuted(c request.CTX, channelIDs []string, userID string, muted bool) ([]*model.ChannelMember, *model.AppError) {
|
||||
members, nErr := a.Srv().Store.Channel().GetMembersByChannelIds(channelIDs, userID)
|
||||
if nErr != nil {
|
||||
members, err := a.Srv().Store.Channel().GetMembersByChannelIds(channelIDs, userID)
|
||||
if err != nil {
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
default:
|
||||
return nil, model.NewAppError("setChannelsMuted", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("setChannelsMuted", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3240,17 +3240,17 @@ func (a *App) setChannelsMuted(c request.CTX, channelIDs []string, userID string
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
updated, nErr := a.Srv().Store.Channel().UpdateMultipleMembers(membersToUpdate)
|
||||
if nErr != nil {
|
||||
updated, err := a.Srv().Store.Channel().UpdateMultipleMembers(membersToUpdate)
|
||||
if err != nil {
|
||||
var appErr *model.AppError
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
case errors.As(nErr, &nfErr):
|
||||
return nil, model.NewAppError("setChannelsMuted", MissingChannelMemberError, nil, nfErr.Error(), http.StatusNotFound)
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("setChannelsMuted", MissingChannelMemberError, nil, "", http.StatusNotFound).Wrap(nfErr)
|
||||
default:
|
||||
return nil, model.NewAppError("setChannelsMuted", "app.channel.get_member.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("setChannelsMuted", "app.channel.get_member.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3375,7 +3375,7 @@ func (a *App) ClearChannelMembersCache(c request.CTX, channelID string) error {
|
||||
return nil
|
||||
}
|
||||
if err := a.forEachChannelMember(c, channelID, clearSessionCache); err != nil {
|
||||
return fmt.Errorf("error clearing cache for channel members: channel_id: %s, error: %v", channelID, err)
|
||||
return fmt.Errorf("error clearing cache for channel members: channel_id: %s, error: %w", channelID, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -3383,7 +3383,7 @@ func (a *App) ClearChannelMembersCache(c request.CTX, channelID string) error {
|
||||
func (a *App) GetMemberCountsByGroup(ctx context.Context, channelID string, includeTimezones bool) ([]*model.ChannelMemberCountByGroup, *model.AppError) {
|
||||
channelMemberCounts, err := a.Srv().Store.Channel().GetMemberCountsByGroup(ctx, channelID, includeTimezones)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetMemberCountsByGroup", "app.channel.get_member_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("GetMemberCountsByGroup", "app.channel.get_member_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
return channelMemberCounts, nil
|
||||
|
||||
@@ -144,7 +144,7 @@ func (a *App) UpdateSidebarCategoryOrder(c request.CTX, userID, teamID string, c
|
||||
func (a *App) UpdateSidebarCategories(c request.CTX, userID, teamID string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
updatedCategories, originalCategories, err := a.Srv().Store.Channel().UpdateSidebarCategories(userID, teamID, categories)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("UpdateSidebarCategories", "app.channel.sidebar_categories.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("UpdateSidebarCategories", "app.channel.sidebar_categories.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventSidebarCategoryUpdated, teamID, "", userID, nil)
|
||||
|
||||
@@ -280,7 +280,7 @@ func (a *App) getDynamicListArgument(c *request.Context, commandArgs *model.Comm
|
||||
|
||||
var listItems []model.AutocompleteListItem
|
||||
if jsonErr := json.NewDecoder(resp.Body).Decode(&listItems); jsonErr != nil {
|
||||
mlog.Warn("Failed to decode from JSON", mlog.Err(jsonErr))
|
||||
c.Logger().Warn("Failed to decode from JSON", mlog.Err(jsonErr))
|
||||
}
|
||||
|
||||
return parseListItems(listItems, parsed, toBeParsed)
|
||||
|
||||
15
app/emoji.go
15
app/emoji.go
@@ -52,8 +52,8 @@ func (a *App) CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartIma
|
||||
// do our best to validate the emoji before committing anything to the DB so that we don't have to clean up
|
||||
// orphaned files left over when validation fails later on
|
||||
emoji.PreSave()
|
||||
if err := emoji.IsValid(); err != nil {
|
||||
return nil, err
|
||||
if appErr := emoji.IsValid(); appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
if emoji.CreatorId != sessionUserId {
|
||||
@@ -61,22 +61,21 @@ func (a *App) CreateEmoji(sessionUserId string, emoji *model.Emoji, multiPartIma
|
||||
}
|
||||
|
||||
if existingEmoji, err := a.Srv().Store.Emoji().GetByName(context.Background(), emoji.Name, true); err == nil && existingEmoji != nil {
|
||||
return nil, model.NewAppError("createEmoji", "api.emoji.create.duplicate.app_error", nil, "", http.StatusBadRequest)
|
||||
return nil, model.NewAppError("createEmoji", "api.emoji.create.duplicate.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
imageData := multiPartImageData.File["image"]
|
||||
if len(imageData) == 0 {
|
||||
err := model.NewAppError("Context", "api.context.invalid_body_param.app_error", map[string]any{"Name": "createEmoji"}, "", http.StatusBadRequest)
|
||||
return nil, err
|
||||
return nil, model.NewAppError("Context", "api.context.invalid_body_param.app_error", map[string]any{"Name": "createEmoji"}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if err := a.UploadEmojiImage(emoji.Id, imageData[0]); err != nil {
|
||||
return nil, err
|
||||
if appErr := a.UploadEmojiImage(emoji.Id, imageData[0]); appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
emoji, err := a.Srv().Store.Emoji().Save(emoji)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("CreateEmoji", "app.emoji.create.internal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("CreateEmoji", "app.emoji.create.internal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventEmojiAdded, "", "", "", nil)
|
||||
|
||||
@@ -141,14 +141,14 @@ func (a *App) BulkExport(ctx request.CTX, writer io.Writer, outPath string, opts
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) exportWriteLine(writer io.Writer, line *LineImportData) *model.AppError {
|
||||
func (a *App) exportWriteLine(w io.Writer, line *LineImportData) *model.AppError {
|
||||
b, err := json.Marshal(line)
|
||||
if err != nil {
|
||||
return model.NewAppError("BulkExport", "app.export.export_write_line.json_marshall.error", nil, "err="+err.Error(), http.StatusBadRequest)
|
||||
return model.NewAppError("BulkExport", "app.export.export_write_line.json_marshall.error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
if _, err := writer.Write(append(b, '\n')); err != nil {
|
||||
return model.NewAppError("BulkExport", "app.export.export_write_line.io_writer.error", nil, "err="+err.Error(), http.StatusBadRequest)
|
||||
if _, err := w.Write(append(b, '\n')); err != nil {
|
||||
return model.NewAppError("BulkExport", "app.export.export_write_line.io_writer.error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
61
app/group.go
61
app/group.go
@@ -122,9 +122,9 @@ func (a *App) isUniqueToUsernames(val string) *model.AppError {
|
||||
}
|
||||
|
||||
func (a *App) CreateGroupWithUserIds(group *model.GroupWithUserIds) (*model.Group, *model.AppError) {
|
||||
if err := a.isUniqueToUsernames(group.GetName()); err != nil {
|
||||
err.Where = "CreateGroupWithUserIds"
|
||||
return nil, err
|
||||
if appErr := a.isUniqueToUsernames(group.GetName()); appErr != nil {
|
||||
appErr.Where = "CreateGroupWithUserIds"
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
newGroup, err := a.Srv().Store.Group().CreateWithUserIds(group)
|
||||
@@ -136,18 +136,18 @@ func (a *App) CreateGroupWithUserIds(group *model.GroupWithUserIds) (*model.Grou
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
case errors.As(err, &invErr):
|
||||
return nil, model.NewAppError("CreateGroupWithUserIds", "app.group.id.app_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("CreateGroupWithUserIds", "app.group.id.app_error", nil, "", http.StatusBadRequest).Wrap(invErr)
|
||||
case errors.As(err, &dupKey):
|
||||
return nil, model.NewAppError("CreateGroupWithUserIds", "app.custom_group.unique_name", nil, dupKey.Error(), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("CreateGroupWithUserIds", "app.custom_group.unique_name", nil, "", http.StatusBadRequest).Wrap(dupKey)
|
||||
default:
|
||||
return nil, model.NewAppError("CreateGroupWithUserIds", "app.insert_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("CreateGroupWithUserIds", "app.insert_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
messageWs := model.NewWebSocketEvent(model.WebsocketEventReceivedGroup, "", "", "", nil)
|
||||
count, err := a.Srv().Store.Group().GetMemberCount(newGroup.Id)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("CreateGroupWithUserIds", "app.group.id.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("CreateGroupWithUserIds", "app.group.id.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
group.MemberCount = model.NewInt(int(count))
|
||||
groupJSON, jsonErr := json.Marshal(newGroup)
|
||||
@@ -161,28 +161,12 @@ func (a *App) CreateGroupWithUserIds(group *model.GroupWithUserIds) (*model.Grou
|
||||
}
|
||||
|
||||
func (a *App) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
||||
if err := a.isUniqueToUsernames(group.GetName()); err != nil {
|
||||
err.Where = "UpdateGroup"
|
||||
return nil, err
|
||||
if appErr := a.isUniqueToUsernames(group.GetName()); appErr != nil {
|
||||
appErr.Where = "UpdateGroup"
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
updatedGroup, err := a.Srv().Store.Group().Update(group)
|
||||
|
||||
if err == nil {
|
||||
count, countErr := a.Srv().Store.Group().GetMemberCount(updatedGroup.Id)
|
||||
if countErr != nil {
|
||||
return nil, model.NewAppError("UpdateGroup", "app.group.id.app_error", nil, countErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
updatedGroup.MemberCount = model.NewInt(int(count))
|
||||
messageWs := model.NewWebSocketEvent(model.WebsocketEventReceivedGroup, "", "", "", nil)
|
||||
groupJSON, jsonErr := json.Marshal(updatedGroup)
|
||||
if jsonErr != nil {
|
||||
return nil, model.NewAppError("UpdateGroup", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
|
||||
}
|
||||
messageWs.Add("group", string(groupJSON))
|
||||
a.Publish(messageWs)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
var appErr *model.AppError
|
||||
@@ -191,14 +175,29 @@ func (a *App) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("UpdateGroup", "app.group.no_rows", nil, nfErr.Error(), http.StatusNotFound)
|
||||
return nil, model.NewAppError("UpdateGroup", "app.group.no_rows", nil, "", http.StatusNotFound).Wrap(nfErr)
|
||||
case errors.As(err, &dupKey):
|
||||
return nil, model.NewAppError("CreateGroup", "app.custom_group.unique_name", nil, dupKey.Error(), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("CreateGroup", "app.custom_group.unique_name", nil, "", http.StatusBadRequest).Wrap(dupKey)
|
||||
default:
|
||||
return nil, model.NewAppError("UpdateGroup", "app.select_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("UpdateGroup", "app.select_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
count, err := a.Srv().Store.Group().GetMemberCount(updatedGroup.Id)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("UpdateGroup", "app.group.id.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
updatedGroup.MemberCount = model.NewInt(int(count))
|
||||
messageWs := model.NewWebSocketEvent(model.WebsocketEventReceivedGroup, "", "", "", nil)
|
||||
|
||||
groupJSON, err := json.Marshal(updatedGroup)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("UpdateGroup", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
messageWs.Add("group", string(groupJSON))
|
||||
a.Publish(messageWs)
|
||||
|
||||
return updatedGroup, nil
|
||||
}
|
||||
|
||||
@@ -763,9 +762,9 @@ func (a *App) DeleteGroupMembers(groupID string, userIDs []string) ([]*model.Gro
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
case errors.As(err, &invErr):
|
||||
return nil, model.NewAppError("DeleteGroupMember", "app.group.uniqueness_error", nil, invErr.Error(), http.StatusBadRequest)
|
||||
return nil, model.NewAppError("DeleteGroupMember", "app.group.uniqueness_error", nil, "", http.StatusBadRequest).Wrap(invErr)
|
||||
default:
|
||||
return nil, model.NewAppError("DeleteGroupMember", "app.update_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("DeleteGroupMember", "app.update_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -332,10 +332,10 @@ func validateUserTeamsImportData(data *[]UserTeamImportData) *model.AppError {
|
||||
}
|
||||
}
|
||||
|
||||
if tdata.Theme != nil && 0 < len(strings.Trim(*tdata.Theme, " \t\r")) {
|
||||
if tdata.Theme != nil && strings.Trim(*tdata.Theme, " \t\r") != "" {
|
||||
var unused map[string]string
|
||||
if err := json.NewDecoder(strings.NewReader(*tdata.Theme)).Decode(&unused); err != nil {
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_teams_import_data.invalid_team_theme.error", nil, err.Error(), http.StatusBadRequest)
|
||||
return model.NewAppError("BulkImport", "app.import.validate_user_teams_import_data.invalid_team_theme.error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,9 +98,9 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(result.NErr, &nfErr):
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.post.get.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.post.get.app_error", nil, "", http.StatusNotFound).Wrap(nfErr)
|
||||
default:
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.post.get.app_error", nil, result.NErr.Error(), http.StatusInternalServerError)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.post.get.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr)
|
||||
}
|
||||
}
|
||||
if cookie.Integration == nil {
|
||||
@@ -116,9 +116,9 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get.existing.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get.existing.app_error", nil, "", http.StatusNotFound).Wrap(nfErr)
|
||||
default:
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get.find.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get.find.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI
|
||||
post := result.Data.(*model.Post)
|
||||
result = <-cchan
|
||||
if result.NErr != nil {
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get_for_post.app_error", nil, result.NErr.Error(), http.StatusInternalServerError)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.channel.get_for_post.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr)
|
||||
}
|
||||
channel := result.Data.(*model.Channel)
|
||||
|
||||
@@ -195,9 +195,9 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(ur.NErr, &nfErr):
|
||||
return "", model.NewAppError("DoPostActionWithCookie", MissingAccountError, nil, nfErr.Error(), http.StatusNotFound)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", MissingAccountError, nil, "", http.StatusNotFound).Wrap(nfErr)
|
||||
default:
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.user.get.app_error", nil, ur.NErr.Error(), http.StatusInternalServerError)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(ur.NErr)
|
||||
}
|
||||
}
|
||||
user := ur.Data.(*model.User)
|
||||
@@ -209,9 +209,9 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(tr.NErr, &nfErr):
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.team.get.find.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.team.get.find.app_error", nil, "", http.StatusNotFound).Wrap(nfErr)
|
||||
default:
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.team.get.finding.app_error", nil, tr.NErr.Error(), http.StatusInternalServerError)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "app.team.get.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(tr.NErr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +234,6 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI
|
||||
return "", appErr
|
||||
}
|
||||
|
||||
var resp *http.Response
|
||||
if strings.HasPrefix(upstreamURL, "/warn_metrics/") {
|
||||
appErr = a.doLocalWarnMetricsRequest(c, upstreamURL, upstreamRequest)
|
||||
if appErr != nil {
|
||||
@@ -242,11 +241,12 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
requestJSON, jsonErr := json.Marshal(upstreamRequest)
|
||||
if jsonErr != nil {
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "api.marshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
|
||||
requestJSON, err := json.Marshal(upstreamRequest)
|
||||
if err != nil {
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
resp, appErr = a.DoActionRequest(c, upstreamURL, requestJSON)
|
||||
resp, appErr := a.DoActionRequest(c, upstreamURL, requestJSON)
|
||||
if appErr != nil {
|
||||
return "", appErr
|
||||
}
|
||||
@@ -255,12 +255,12 @@ func (a *App) DoPostActionWithCookie(c *request.Context, postID, actionId, userI
|
||||
var response model.PostActionIntegrationResponse
|
||||
respBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "api.post.do_action.action_integration.app_error", nil, "err="+err.Error(), http.StatusBadRequest)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "api.post.do_action.action_integration.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
if len(respBytes) > 0 {
|
||||
if err = json.Unmarshal(respBytes, &response); err != nil {
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "api.post.do_action.action_integration.app_error", nil, "err="+err.Error(), http.StatusBadRequest)
|
||||
return "", model.NewAppError("DoPostActionWithCookie", "api.post.do_action.action_integration.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,14 +585,17 @@ func (a *App) DoLocalRequest(c *request.Context, rawURL string, body []byte) (*h
|
||||
}
|
||||
|
||||
func (a *App) OpenInteractiveDialog(request model.OpenDialogRequest) *model.AppError {
|
||||
clientTriggerId, userID, err := request.DecodeAndVerifyTriggerId(a.AsymmetricSigningKey())
|
||||
if err != nil {
|
||||
return err
|
||||
clientTriggerId, userID, appErr := request.DecodeAndVerifyTriggerId(a.AsymmetricSigningKey())
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
request.TriggerId = clientTriggerId
|
||||
|
||||
jsonRequest, _ := json.Marshal(request)
|
||||
jsonRequest, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
a.ch.srv.GetLogger().Warn("Error encoding request", mlog.Err(err))
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventOpenDialog, "", "", userID, nil)
|
||||
message.Add("dialog", string(jsonRequest))
|
||||
@@ -606,23 +609,19 @@ func (a *App) SubmitInteractiveDialog(c *request.Context, request model.SubmitDi
|
||||
request.URL = ""
|
||||
request.Type = "dialog_submission"
|
||||
|
||||
b, jsonErr := json.Marshal(request)
|
||||
if jsonErr != nil {
|
||||
return nil, model.NewAppError("SubmitInteractiveDialog", "app.submit_interactive_dialog.json_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
resp, err := a.DoActionRequest(c, url, b)
|
||||
b, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, model.NewAppError("SubmitInteractiveDialog", "app.submit_interactive_dialog.json_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
resp, appErr := a.DoActionRequest(c, url, b)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var response model.SubmitDialogResponse
|
||||
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
||||
// Don't fail, an empty response is acceptable
|
||||
return &response, nil
|
||||
}
|
||||
json.NewDecoder(resp.Body).Decode(&response) // Don't fail, an empty response is acceptable
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
@@ -342,14 +342,14 @@ func (s *Server) GetSanitizedClientLicense() map[string]string {
|
||||
|
||||
// RequestTrialLicense request a trial license from the mattermost official license server
|
||||
func (s *Server) RequestTrialLicense(trialRequest *model.TrialLicenseRequest) *model.AppError {
|
||||
trialRequestJSON, jsonErr := json.Marshal(trialRequest)
|
||||
if jsonErr != nil {
|
||||
return model.NewAppError("RequestTrialLicense", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
trialRequestJSON, err := json.Marshal(trialRequest)
|
||||
if err != nil {
|
||||
return model.NewAppError("RequestTrialLicense", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
resp, err := http.Post(RequestTrialURL, "application/json", bytes.NewBuffer(trialRequestJSON))
|
||||
if err != nil {
|
||||
return model.NewAppError("RequestTrialLicense", "api.license.request_trial_license.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
return model.NewAppError("RequestTrialLicense", "api.license.request_trial_license.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
@@ -363,7 +363,11 @@ func (s *Server) RequestTrialLicense(trialRequest *model.TrialLicenseRequest) *m
|
||||
fmt.Sprintf("Unexpected HTTP status code %q returned by server", resp.Status), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
licenseResponse := model.MapFromJSON(resp.Body)
|
||||
var licenseResponse map[string]string
|
||||
err = json.NewDecoder(resp.Body).Decode(&licenseResponse)
|
||||
if err != nil {
|
||||
s.GetLogger().Warn("Error decoding license response", mlog.Err(err))
|
||||
}
|
||||
|
||||
if _, ok := licenseResponse["license"]; !ok {
|
||||
return model.NewAppError("RequestTrialLicense", "api.license.request_trial_license.app_error", nil, licenseResponse["message"], http.StatusBadRequest)
|
||||
|
||||
@@ -6,14 +6,14 @@ package app
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/app/request"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/i18n"
|
||||
@@ -382,9 +382,9 @@ func (s *Server) StopPushNotificationsHubWorkers() {
|
||||
}
|
||||
|
||||
func (a *App) rawSendToPushProxy(msg *model.PushNotification) (model.PushResponse, error) {
|
||||
msgJSON, jsonErr := json.Marshal(msg)
|
||||
if jsonErr != nil {
|
||||
return nil, errors.Wrap(jsonErr, "failed to encode to JSON")
|
||||
msgJSON, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to encode to JSON: %w", err)
|
||||
}
|
||||
|
||||
url := strings.TrimRight(*a.Config().EmailSettings.PushNotificationServer, "/") + model.APIURLSuffixV1 + "/send_push"
|
||||
@@ -400,8 +400,8 @@ func (a *App) rawSendToPushProxy(msg *model.PushNotification) (model.PushRespons
|
||||
defer resp.Body.Close()
|
||||
|
||||
var pushResponse model.PushResponse
|
||||
if jsonErr := json.NewDecoder(resp.Body).Decode(&pushResponse); jsonErr != nil {
|
||||
return nil, errors.Wrap(jsonErr, "failed to decode from JSON")
|
||||
if err := json.NewDecoder(resp.Body).Decode(&pushResponse); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode from JSON: %w", err)
|
||||
}
|
||||
|
||||
return pushResponse, nil
|
||||
@@ -427,7 +427,7 @@ func (a *App) sendToPushProxy(msg *model.PushNotification, session *model.Sessio
|
||||
case model.PushStatusRemove:
|
||||
a.AttachDeviceId(session.Id, "", session.ExpiresAt)
|
||||
a.ClearSessionCacheForUser(session.UserId)
|
||||
return errors.New("Device was reported as removed")
|
||||
return errors.New("device was reported as removed")
|
||||
case model.PushStatusFail:
|
||||
return errors.New(pushResponse[model.PushStatusErrorMsg])
|
||||
}
|
||||
@@ -447,9 +447,9 @@ func (a *App) SendAckToPushProxy(ack *model.PushNotificationAck) error {
|
||||
mlog.String("status", model.PushReceived),
|
||||
)
|
||||
|
||||
ackJSON, jsonErr := json.Marshal(ack)
|
||||
if jsonErr != nil {
|
||||
return errors.Wrap(jsonErr, "failed to encode to JSON")
|
||||
ackJSON, err := json.Marshal(ack)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encode to JSON: %w", err)
|
||||
}
|
||||
|
||||
request, err := http.NewRequest(
|
||||
@@ -457,7 +457,6 @@ func (a *App) SendAckToPushProxy(ack *model.PushNotificationAck) error {
|
||||
strings.TrimRight(*a.Config().EmailSettings.PushNotificationServer, "/")+model.APIURLSuffixV1+"/ack",
|
||||
bytes.NewReader(ackJSON),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -467,19 +466,16 @@ func (a *App) SendAckToPushProxy(ack *model.PushNotificationAck) error {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Reading the body to completion.
|
||||
_, err = io.Copy(io.Discard, resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *App) getMobileAppSessions(userID string) ([]*model.Session, *model.AppError) {
|
||||
sessions, err := a.Srv().Store.Session().GetSessionsWithActiveDeviceIds(userID)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("getMobileAppSessions", "app.session.get_sessions.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("getMobileAppSessions", "app.session.get_sessions.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
return sessions, nil
|
||||
@@ -572,7 +568,7 @@ func (a *App) BuildPushNotificationMessage(c request.CTX, contentsConfig string,
|
||||
|
||||
unreadCount, err := a.Srv().Store.User().GetUnreadCount(user.Id)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("BuildPushNotificationMessage", "app.user.get_unread_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("BuildPushNotificationMessage", "app.user.get_unread_count.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
msg.Badge = int(unreadCount)
|
||||
|
||||
|
||||
@@ -852,7 +852,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
|
||||
var ar *model.AccessResponse
|
||||
err = json.NewDecoder(tee).Decode(&ar)
|
||||
if err != nil || resp.StatusCode != http.StatusOK {
|
||||
return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.bad_response.app_error", nil, fmt.Sprintf("response_body=%s, status_code=%d, error=%v", buf.String(), resp.StatusCode, err), http.StatusInternalServerError)
|
||||
return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.bad_response.app_error", nil, fmt.Sprintf("response_body=%s, status_code=%d, error=%v", buf.String(), resp.StatusCode, err), http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
if strings.ToLower(ar.TokenType) != model.AccessTokenType {
|
||||
|
||||
71
app/post.go
71
app/post.go
@@ -251,7 +251,7 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
|
||||
post.AddProp("attachments", attachmentsInterface)
|
||||
}
|
||||
if err != nil {
|
||||
mlog.Warn("Could not convert post attachments to map interface.", mlog.Err(err))
|
||||
c.Logger().Warn("Could not convert post attachments to map interface.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
|
||||
|
||||
if len(post.FileIds) > 0 {
|
||||
if err = a.attachFilesToPost(post); err != nil {
|
||||
mlog.Warn("Encountered error attaching files to post", mlog.String("post_id", post.Id), mlog.Any("file_ids", post.FileIds), mlog.Err(err))
|
||||
c.Logger().Warn("Encountered error attaching files to post", mlog.String("post_id", post.Id), mlog.Any("file_ids", post.FileIds), mlog.Err(err))
|
||||
}
|
||||
|
||||
if a.Metrics() != nil {
|
||||
@@ -348,12 +348,12 @@ func (a *App) CreatePost(c request.CTX, post *model.Post, channel *model.Channel
|
||||
UpdateFollowing: true,
|
||||
})
|
||||
if err != nil {
|
||||
mlog.Warn("Failed to update thread membership", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to update thread membership", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.handlePostEvents(c, rpost, user, channel, triggerWebhooks, parentPostList, setOnline); err != nil {
|
||||
mlog.Warn("Failed to handle post events", mlog.Err(err))
|
||||
c.Logger().Warn("Failed to handle post events", mlog.Err(err))
|
||||
}
|
||||
|
||||
// Send any ephemeral posts after the post is created to ensure it shows up after the latest post created
|
||||
@@ -1224,34 +1224,35 @@ func (a *App) GetPostsForChannelAroundLastUnread(c request.CTX, channelID, userI
|
||||
}
|
||||
|
||||
func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post, *model.AppError) {
|
||||
post, nErr := a.Srv().Store.Post().GetSingle(postID, false)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("DeletePost", "app.post.get.app_error", nil, nErr.Error(), http.StatusBadRequest)
|
||||
post, err := a.Srv().Store.Post().GetSingle(postID, false)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("DeletePost", "app.post.get.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
}
|
||||
|
||||
channel, err := a.GetChannel(c, post.ChannelId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
channel, appErr := a.GetChannel(c, post.ChannelId)
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
if channel.DeleteAt != 0 {
|
||||
err := model.NewAppError("DeletePost", "api.post.delete_post.can_not_delete_post_in_deleted.error", nil, "", http.StatusBadRequest)
|
||||
return nil, err
|
||||
appErr := model.NewAppError("DeletePost", "api.post.delete_post.can_not_delete_post_in_deleted.error", nil, "", http.StatusBadRequest)
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Post().Delete(postID, model.GetMillis(), deleteByID); err != nil {
|
||||
err = a.Srv().Store.Post().Delete(postID, model.GetMillis(), deleteByID)
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
switch {
|
||||
case errors.As(err, &nfErr):
|
||||
return nil, model.NewAppError("DeletePost", "app.post.delete.app_error", nil, nfErr.Error(), http.StatusNotFound)
|
||||
return nil, model.NewAppError("DeletePost", "app.post.delete.app_error", nil, "", http.StatusNotFound).Wrap(nfErr)
|
||||
default:
|
||||
return nil, model.NewAppError("DeletePost", "app.post.delete.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("DeletePost", "app.post.delete.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
postJSON, jsonErr := json.Marshal(post)
|
||||
if jsonErr != nil {
|
||||
return nil, model.NewAppError("DeletePost", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
|
||||
postJSON, err := json.Marshal(post)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("DeletePost", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
userMessage := model.NewWebSocketEvent(model.WebsocketEventPostDeleted, "", post.ChannelId, "", nil)
|
||||
@@ -1283,14 +1284,14 @@ func (a *App) DeletePost(c request.CTX, postID, deleteByID string) (*model.Post,
|
||||
|
||||
func (a *App) deleteFlaggedPosts(postID string) {
|
||||
if err := a.Srv().Store.Preference().DeleteCategoryAndName(model.PreferenceCategoryFlaggedPost, postID); err != nil {
|
||||
mlog.Warn("Unable to delete flagged post preference when deleting post.", mlog.Err(err))
|
||||
a.Log().Warn("Unable to delete flagged post preference when deleting post.", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) deletePostFiles(postID string) {
|
||||
if _, err := a.Srv().Store.FileInfo().DeleteForPost(postID); err != nil {
|
||||
mlog.Warn("Encountered error when deleting files for post", mlog.String("post_id", postID), mlog.Err(err))
|
||||
a.Log().Warn("Encountered error when deleting files for post", mlog.String("post_id", postID), mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1358,7 +1359,7 @@ func (a *App) searchPostsInTeam(teamID string, userID string, paramsList []*mode
|
||||
|
||||
for result := range pchan {
|
||||
if result.NErr != nil {
|
||||
return nil, model.NewAppError("searchPostsInTeam", "app.post.search.app_error", nil, result.NErr.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("searchPostsInTeam", "app.post.search.app_error", nil, "", http.StatusInternalServerError).Wrap(result.NErr)
|
||||
}
|
||||
data := result.Data.(*model.PostList)
|
||||
posts.Extend(data)
|
||||
@@ -1375,7 +1376,7 @@ func (a *App) convertChannelNamesToChannelIds(c *request.Context, channels []str
|
||||
for idx, channelName := range channels {
|
||||
channel, err := a.parseAndFetchChannelIdByNameFromInFilter(c, channelName, userID, teamID, includeDeletedChannels)
|
||||
if err != nil {
|
||||
mlog.Warn("error getting channel id by name from in filter", mlog.Err(err))
|
||||
a.Log().Warn("error getting channel id by name from in filter", mlog.Err(err))
|
||||
continue
|
||||
}
|
||||
channels[idx] = channel.Id
|
||||
@@ -1387,7 +1388,7 @@ func (a *App) convertUserNameToUserIds(usernames []string) []string {
|
||||
for idx, username := range usernames {
|
||||
user, err := a.GetUserByUsername(username)
|
||||
if err != nil {
|
||||
mlog.Warn("error getting user by username", mlog.String("user_name", username), mlog.Err(err))
|
||||
a.Log().Warn("error getting user by username", mlog.String("user_name", username), mlog.Err(err))
|
||||
continue
|
||||
}
|
||||
usernames[idx] = user.Id
|
||||
@@ -1410,13 +1411,13 @@ func (a *App) GetLastAccessiblePostTime() (int64, *model.AppError) {
|
||||
// All posts are accessible
|
||||
return 0, nil
|
||||
default:
|
||||
return 0, model.NewAppError("GetLastAccessiblePostTime", "app.system.get_by_name.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return 0, model.NewAppError("GetLastAccessiblePostTime", "app.system.get_by_name.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
lastAccessiblePostTime, err := strconv.ParseInt(system.Value, 10, 64)
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("GetLastAccessiblePostTime", "common.parse_error_int64", map[string]interface{}{"Value": system.Value}, err.Error(), http.StatusInternalServerError)
|
||||
return 0, model.NewAppError("GetLastAccessiblePostTime", "common.parse_error_int64", map[string]interface{}{"Value": system.Value}, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
return lastAccessiblePostTime, nil
|
||||
@@ -1434,7 +1435,7 @@ func (a *App) ComputeLastAccessiblePostTime() error {
|
||||
if err != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
if !errors.As(err, &nfErr) {
|
||||
return model.NewAppError("ComputeLastAccessiblePostTime", "app.last_accessible_post.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return model.NewAppError("ComputeLastAccessiblePostTime", "app.last_accessible_post.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1444,7 +1445,7 @@ func (a *App) ComputeLastAccessiblePostTime() error {
|
||||
Value: strconv.FormatInt(createdAt, 10),
|
||||
})
|
||||
if err != nil {
|
||||
return model.NewAppError("ComputeLastAccessiblePostTime", "app.system.save.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return model.NewAppError("ComputeLastAccessiblePostTime", "app.system.save.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -1458,7 +1459,7 @@ func (a *App) getCloudMessagesHistoryLimit() (int64, *model.AppError) {
|
||||
|
||||
limits, err := a.Cloud().GetCloudLimits("")
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("getCloudMessagesHistoryLimit", "api.cloud.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return 0, model.NewAppError("getCloudMessagesHistoryLimit", "api.cloud.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
if limits == nil || limits.Messages == nil || limits.Messages.History == nil {
|
||||
@@ -1516,14 +1517,14 @@ func (a *App) SearchPostsForUser(c *request.Context, terms string, userID string
|
||||
return model.MakePostSearchResults(model.NewPostList(), nil), nil
|
||||
}
|
||||
|
||||
postSearchResults, nErr := a.Srv().Store.Post().SearchPostsForUser(finalParamsList, userID, teamID, page, perPage)
|
||||
if nErr != nil {
|
||||
postSearchResults, err := a.Srv().Store.Post().SearchPostsForUser(finalParamsList, userID, teamID, page, perPage)
|
||||
if err != nil {
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(nErr, &appErr):
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
default:
|
||||
return nil, model.NewAppError("SearchPostsForUser", "app.post.search.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("SearchPostsForUser", "app.post.search.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1535,9 +1536,9 @@ func (a *App) SearchPostsForUser(c *request.Context, terms string, userID string
|
||||
}
|
||||
|
||||
func (a *App) GetRecentSearchesForUser(userID string) ([]*model.SearchParams, *model.AppError) {
|
||||
searchParams, nErr := a.Srv().Store.Post().GetRecentSearchesForUser(userID)
|
||||
if nErr != nil {
|
||||
return nil, model.NewAppError("GetRecentSearchesForUser", "app.recent_searches.app_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
searchParams, err := a.Srv().Store.Post().GetRecentSearchesForUser(userID)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("GetRecentSearchesForUser", "app.recent_searches.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
return searchParams, nil
|
||||
|
||||
@@ -53,12 +53,12 @@ func (a *App) UpdatePreferences(userID string, preferences model.Preferences) *m
|
||||
case errors.As(err, &appErr):
|
||||
return appErr
|
||||
default:
|
||||
return model.NewAppError("UpdatePreferences", "app.preference.save.updating.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
return model.NewAppError("UpdatePreferences", "app.preference.save.updating.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Channel().UpdateSidebarChannelsByPreferences(preferences); err != nil {
|
||||
return model.NewAppError("UpdatePreferences", "api.preference.update_preferences.update_sidebar.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return model.NewAppError("UpdatePreferences", "api.preference.update_preferences.update_sidebar.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventSidebarCategoryUpdated, "", "", userID, nil)
|
||||
@@ -87,12 +87,12 @@ func (a *App) DeletePreferences(userID string, preferences model.Preferences) *m
|
||||
|
||||
for _, preference := range preferences {
|
||||
if err := a.Srv().Store.Preference().Delete(userID, preference.Category, preference.Name); err != nil {
|
||||
return model.NewAppError("DeletePreferences", "app.preference.delete.app_error", nil, err.Error(), http.StatusBadRequest)
|
||||
return model.NewAppError("DeletePreferences", "app.preference.delete.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.Srv().Store.Channel().DeleteSidebarChannelsByPreferences(preferences); err != nil {
|
||||
return model.NewAppError("DeletePreferences", "api.preference.delete_preferences.update_sidebar.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return model.NewAppError("DeletePreferences", "api.preference.delete_preferences.update_sidebar.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventSidebarCategoryUpdated, "", "", userID, nil)
|
||||
|
||||
@@ -162,9 +162,9 @@ func (a *App) DeleteReactionForPost(c *request.Context, reaction *model.Reaction
|
||||
func (a *App) sendReactionEvent(event string, reaction *model.Reaction, post *model.Post) {
|
||||
// send out that a reaction has been added/removed
|
||||
message := model.NewWebSocketEvent(event, "", post.ChannelId, "", nil)
|
||||
reactionJSON, jsonErr := json.Marshal(reaction)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode reaction to JSON")
|
||||
reactionJSON, err := json.Marshal(reaction)
|
||||
if err != nil {
|
||||
a.Log().Warn("Failed to encode reaction to JSON", mlog.Err(err))
|
||||
}
|
||||
message.Add("reaction", string(reactionJSON))
|
||||
a.Publish(message)
|
||||
|
||||
@@ -91,7 +91,7 @@ func (s *Server) DoSecurityUpdateCheck() {
|
||||
|
||||
var bulletins model.SecurityBulletins
|
||||
if jsonErr := json.NewDecoder(res.Body).Decode(&bulletins); jsonErr != nil {
|
||||
mlog.Error("Failed to decode JSON", mlog.Err(jsonErr))
|
||||
s.Log.Error("Failed to decode JSON", mlog.Err(jsonErr))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -77,9 +77,9 @@ func setCollapsePreference(a *app.App, args *model.CommandArgs, isCollapse bool)
|
||||
|
||||
socketMessage := model.NewWebSocketEvent(model.WebsocketEventPreferenceChanged, "", "", args.UserId, nil)
|
||||
|
||||
prefJSON, jsonErr := json.Marshal(pref)
|
||||
if jsonErr != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.marshal_error") + jsonErr.Error(), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
prefJSON, err := json.Marshal(pref)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: args.T("api.marshal_error") + err.Error(), ResponseType: model.CommandResponseTypeEphemeral}
|
||||
}
|
||||
socketMessage.Add("preference", string(prefJSON))
|
||||
a.Publish(socketMessage)
|
||||
|
||||
@@ -570,7 +570,7 @@ func (*LoadTestProvider) JsonCommand(a *app.App, c request.CTX, args *model.Comm
|
||||
|
||||
var post model.Post
|
||||
if jsonErr := json.NewDecoder(r.Body).Decode(&post); jsonErr != nil {
|
||||
return &model.CommandResponse{Text: "Unable to decode post", ResponseType: model.CommandResponseTypeEphemeral}, errors.Errorf("could not decode post from json")
|
||||
return &model.CommandResponse{Text: "Unable to decode post", ResponseType: model.CommandResponseTypeEphemeral}, errors.Wrapf(jsonErr, "could not decode post from json")
|
||||
}
|
||||
post.ChannelId = args.ChannelId
|
||||
post.UserId = args.UserId
|
||||
|
||||
@@ -22,9 +22,9 @@ func (a *App) AddStatusCache(status *model.Status) {
|
||||
a.AddStatusCacheSkipClusterSend(status)
|
||||
|
||||
if a.Cluster() != nil {
|
||||
statusJSON, jsonErr := json.Marshal(status)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode status to JSON")
|
||||
statusJSON, err := json.Marshal(status)
|
||||
if err != nil {
|
||||
a.Log().Warn("Failed to encode status to JSON", mlog.Err(err))
|
||||
}
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.ClusterEventUpdateStatus,
|
||||
@@ -456,20 +456,20 @@ func (a *App) GetCustomStatus(userID string) (*model.CustomStatus, *model.AppErr
|
||||
func (a *App) addRecentCustomStatus(userID string, status *model.CustomStatus) *model.AppError {
|
||||
var newRCS model.RecentCustomStatuses
|
||||
|
||||
pref, err := a.GetPreferenceByCategoryAndNameForUser(userID, model.PreferenceCategoryCustomStatus, model.PreferenceNameRecentCustomStatuses)
|
||||
if err != nil || pref.Value == "" {
|
||||
pref, appErr := a.GetPreferenceByCategoryAndNameForUser(userID, model.PreferenceCategoryCustomStatus, model.PreferenceNameRecentCustomStatuses)
|
||||
if appErr != nil || pref.Value == "" {
|
||||
newRCS = model.RecentCustomStatuses{*status}
|
||||
} else {
|
||||
var existingRCS model.RecentCustomStatuses
|
||||
if jsonErr := json.Unmarshal([]byte(pref.Value), &existingRCS); jsonErr != nil {
|
||||
return model.NewAppError("addRecentCustomStatus", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
if err := json.Unmarshal([]byte(pref.Value), &existingRCS); err != nil {
|
||||
return model.NewAppError("addRecentCustomStatus", "api.unmarshal_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
newRCS = existingRCS.Add(status)
|
||||
}
|
||||
|
||||
newRCSJSON, jsonErr := json.Marshal(newRCS)
|
||||
if jsonErr != nil {
|
||||
return model.NewAppError("addRecentCustomStatus", "api.marshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
newRCSJSON, err := json.Marshal(newRCS)
|
||||
if err != nil {
|
||||
return model.NewAppError("addRecentCustomStatus", "api.marshal_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
pref = &model.Preference{
|
||||
UserId: userID,
|
||||
@@ -477,17 +477,17 @@ func (a *App) addRecentCustomStatus(userID string, status *model.CustomStatus) *
|
||||
Name: model.PreferenceNameRecentCustomStatuses,
|
||||
Value: string(newRCSJSON),
|
||||
}
|
||||
if err := a.UpdatePreferences(userID, model.Preferences{*pref}); err != nil {
|
||||
return err
|
||||
if appErr := a.UpdatePreferences(userID, model.Preferences{*pref}); appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) RemoveRecentCustomStatus(userID string, status *model.CustomStatus) *model.AppError {
|
||||
pref, err := a.GetPreferenceByCategoryAndNameForUser(userID, model.PreferenceCategoryCustomStatus, model.PreferenceNameRecentCustomStatuses)
|
||||
if err != nil {
|
||||
return err
|
||||
pref, appErr := a.GetPreferenceByCategoryAndNameForUser(userID, model.PreferenceCategoryCustomStatus, model.PreferenceNameRecentCustomStatuses)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
if pref.Value == "" {
|
||||
@@ -495,26 +495,26 @@ func (a *App) RemoveRecentCustomStatus(userID string, status *model.CustomStatus
|
||||
}
|
||||
|
||||
var existingRCS model.RecentCustomStatuses
|
||||
if jsonErr := json.Unmarshal([]byte(pref.Value), &existingRCS); jsonErr != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
if err := json.Unmarshal([]byte(pref.Value), &existingRCS); err != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.unmarshal_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
if ok, err := existingRCS.Contains(status); !ok || err != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.custom_status.recent_custom_statuses.delete.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
newRCS, removeErr := existingRCS.Remove(status)
|
||||
if removeErr != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.custom_status.recent_custom_statuses.delete.app_error", nil, removeErr.Error(), http.StatusBadRequest)
|
||||
newRCS, err := existingRCS.Remove(status)
|
||||
if err != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.custom_status.recent_custom_statuses.delete.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
|
||||
newRCSJSON, jsonErr := json.Marshal(newRCS)
|
||||
if jsonErr != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.marshal_error", nil, jsonErr.Error(), http.StatusBadRequest)
|
||||
newRCSJSON, err := json.Marshal(newRCS)
|
||||
if err != nil {
|
||||
return model.NewAppError("RemoveRecentCustomStatus", "api.marshal_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
pref.Value = string(newRCSJSON)
|
||||
if err := a.UpdatePreferences(userID, model.Preferences{*pref}); err != nil {
|
||||
return err
|
||||
if appErr := a.UpdatePreferences(userID, model.Preferences{*pref}); appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
16
app/user.go
16
app/user.go
@@ -1241,7 +1241,7 @@ func (a *App) updateUserNotifyProps(userID string, props map[string]string) *mod
|
||||
case errors.As(err, &appErr):
|
||||
return appErr
|
||||
default:
|
||||
return model.NewAppError("UpdateUser", "app.user.update.finding.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return model.NewAppError("UpdateUser", "app.user.update.finding.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1417,7 +1417,7 @@ func (a *App) CreatePasswordRecoveryToken(userID, email string) (*model.Token, *
|
||||
}
|
||||
jsonData, err := json.Marshal(tokenExtra)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("CreatePasswordRecoveryToken", "api.user.create_password_token.error", nil, "", http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("CreatePasswordRecoveryToken", "api.user.create_password_token.error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
token := model.NewToken(TokenTypePasswordRecovery, string(jsonData))
|
||||
@@ -2184,9 +2184,9 @@ func (a *App) PromoteGuestToUser(c *request.Context, user *model.User, requestor
|
||||
for _, member := range teamMembers {
|
||||
a.sendUpdatedMemberRoleEvent(user.Id, member)
|
||||
|
||||
channelMembers, err := a.GetChannelMembersForUser(c, member.TeamId, user.Id)
|
||||
if err != nil {
|
||||
c.Logger().Warn("Failed to get channel members for user on promote guest to user", mlog.Err(err))
|
||||
channelMembers, appErr := a.GetChannelMembersForUser(c, member.TeamId, user.Id)
|
||||
if appErr != nil {
|
||||
c.Logger().Warn("Failed to get channel members for user on promote guest to user", mlog.Err(appErr))
|
||||
}
|
||||
|
||||
for _, member := range channelMembers {
|
||||
@@ -2228,9 +2228,9 @@ func (a *App) DemoteUserToGuest(c request.CTX, user *model.User) *model.AppError
|
||||
for _, member := range teamMembers {
|
||||
a.sendUpdatedMemberRoleEvent(user.Id, member)
|
||||
|
||||
channelMembers, err := a.GetChannelMembersForUser(c, member.TeamId, user.Id)
|
||||
if err != nil {
|
||||
c.Logger().Warn("Failed to get channel members for users on demote user to guest", mlog.Err(err))
|
||||
channelMembers, appErr := a.GetChannelMembersForUser(c, member.TeamId, user.Id)
|
||||
if appErr != nil {
|
||||
c.Logger().Warn("Failed to get channel members for users on demote user to guest", mlog.Err(appErr))
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -98,9 +98,9 @@ func (a *App) TriggerWebhook(c request.CTX, payload *model.OutgoingWebhookPayloa
|
||||
var body io.Reader
|
||||
var contentType string
|
||||
if hook.ContentType == "application/json" {
|
||||
js, jsonErr := json.Marshal(payload)
|
||||
if jsonErr != nil {
|
||||
mlog.Warn("Failed to encode to JSON", mlog.Err(jsonErr))
|
||||
js, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
c.Logger().Warn("Failed to encode to JSON", mlog.Err(err))
|
||||
}
|
||||
body = bytes.NewReader(js)
|
||||
contentType = "application/json"
|
||||
@@ -116,7 +116,7 @@ func (a *App) TriggerWebhook(c request.CTX, payload *model.OutgoingWebhookPayloa
|
||||
a.Srv().Go(func() {
|
||||
webhookResp, err := a.doOutgoingWebhookRequest(url, body, contentType)
|
||||
if err != nil {
|
||||
mlog.Error("Event POST failed.", mlog.Err(err))
|
||||
c.Logger().Error("Event POST failed.", mlog.Err(err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ func (a *App) TriggerWebhook(c request.CTX, payload *model.OutgoingWebhookPayloa
|
||||
webhookResp.IconURL = hook.IconURL
|
||||
}
|
||||
if _, err := a.CreateWebhookPost(c, hook.CreatorId, channel, text, webhookResp.Username, webhookResp.IconURL, "", webhookResp.Props, webhookResp.Type, postRootId); err != nil {
|
||||
mlog.Error("Failed to create response post.", mlog.Err(err))
|
||||
c.Logger().Error("Failed to create response post.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -175,7 +175,7 @@ func (a *App) doOutgoingWebhookRequest(url string, body io.Reader, contentType s
|
||||
if jsonErr == io.EOF {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, model.NewAppError("doOutgoingWebhookRequest", "api.unmarshal_error", nil, jsonErr.Error(), http.StatusInternalServerError)
|
||||
return nil, model.NewAppError("doOutgoingWebhookRequest", "api.unmarshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
|
||||
}
|
||||
|
||||
return &hookResp, nil
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
type AdvancedPermissionsPhase2Progress struct {
|
||||
@@ -26,7 +27,10 @@ func (p *AdvancedPermissionsPhase2Progress) ToJSON() string {
|
||||
|
||||
func AdvancedPermissionsPhase2ProgressFromJSON(data io.Reader) *AdvancedPermissionsPhase2Progress {
|
||||
var o *AdvancedPermissionsPhase2Progress
|
||||
json.NewDecoder(data).Decode(&o)
|
||||
err := json.NewDecoder(data).Decode(&o)
|
||||
if err != nil {
|
||||
mlog.Warn("Error decoding advanced permissions phase 2 progress", mlog.Err(err))
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
@@ -57,13 +61,17 @@ func (worker *Worker) runAdvancedPermissionsPhase2Migration(lastDone string) (bo
|
||||
var progress *AdvancedPermissionsPhase2Progress
|
||||
if lastDone == "" {
|
||||
// Haven't started the migration yet.
|
||||
progress = new(AdvancedPermissionsPhase2Progress)
|
||||
progress.CurrentTable = "TeamMembers"
|
||||
progress.LastChannelId = strings.Repeat("0", 26)
|
||||
progress.LastTeamId = strings.Repeat("0", 26)
|
||||
progress.LastUserId = strings.Repeat("0", 26)
|
||||
progress = &AdvancedPermissionsPhase2Progress{
|
||||
CurrentTable: "TeamMembers",
|
||||
LastChannelId: strings.Repeat("0", 26),
|
||||
LastTeamId: strings.Repeat("0", 26),
|
||||
LastUserId: strings.Repeat("0", 26),
|
||||
}
|
||||
} else {
|
||||
progress = AdvancedPermissionsPhase2ProgressFromJSON(strings.NewReader(lastDone))
|
||||
err := json.NewDecoder(strings.NewReader(lastDone)).Decode(&progress)
|
||||
if err != nil {
|
||||
return false, "", model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "migrations.worker.run_advanced_permissions_phase_2_migration.invalid_progress", map[string]any{"lastDone": lastDone}, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
if !progress.IsValid() {
|
||||
return false, "", model.NewAppError("MigrationsWorker.runAdvancedPermissionsPhase2Migration", "migrations.worker.run_advanced_permissions_phase_2_migration.invalid_progress", map[string]any{"progress": progress.ToJSON()}, "", http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
@@ -156,7 +156,6 @@ type ChannelModeratedRolesPatch struct {
|
||||
// Paginate whether to paginate the results.
|
||||
// Page page requested, if results are paginated.
|
||||
// PerPage number of results per page, if paginated.
|
||||
//
|
||||
type ChannelSearchOpts struct {
|
||||
NotAssociatedToGroup string
|
||||
ExcludeDefaultChannels bool
|
||||
|
||||
1130
model/client4.go
1130
model/client4.go
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -91,23 +91,21 @@ func (o *Preference) IsValid() *AppError {
|
||||
if o.Category == PreferenceCategoryTheme {
|
||||
var unused map[string]string
|
||||
if err := json.NewDecoder(strings.NewReader(o.Value)).Decode(&unused); err != nil {
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.theme.app_error", nil, "value="+o.Value, http.StatusBadRequest)
|
||||
return NewAppError("Preference.IsValid", "model.preference.is_valid.theme.app_error", nil, "value="+o.Value, http.StatusBadRequest).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var preUpdateColorPattern = regexp.MustCompile(`^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$`)
|
||||
|
||||
func (o *Preference) PreUpdate() {
|
||||
if o.Category == PreferenceCategoryTheme {
|
||||
// decode the value of theme (a map of strings to string) and eliminate any invalid values
|
||||
var props map[string]string
|
||||
if err := json.NewDecoder(strings.NewReader(o.Value)).Decode(&props); err != nil {
|
||||
// just continue, the invalid preference value should get caught by IsValid before saving
|
||||
return
|
||||
}
|
||||
|
||||
colorPattern := regexp.MustCompile(`^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$`)
|
||||
// just continue, the invalid preference value should get caught by IsValid before saving
|
||||
json.NewDecoder(strings.NewReader(o.Value)).Decode(&props)
|
||||
|
||||
// blank out any invalid theme values
|
||||
for name, value := range props {
|
||||
@@ -115,7 +113,7 @@ func (o *Preference) PreUpdate() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !colorPattern.MatchString(value) {
|
||||
if !preUpdateColorPattern.MatchString(value) {
|
||||
props[name] = "#ffffff"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ func AppErrorFromJSON(data io.Reader) *AppError {
|
||||
var er AppError
|
||||
err := decoder.Decode(&er)
|
||||
if err != nil {
|
||||
return NewAppError("AppErrorFromJSON", "model.utils.decode_json.app_error", nil, "body: "+str, http.StatusInternalServerError)
|
||||
return NewAppError("AppErrorFromJSON", "model.utils.decode_json.app_error", nil, "body: "+str, http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
return &er
|
||||
}
|
||||
@@ -401,23 +401,25 @@ func MapBoolToJSON(objmap map[string]bool) string {
|
||||
|
||||
// MapFromJSON will decode the key/value pair map
|
||||
func MapFromJSON(data io.Reader) map[string]string {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap map[string]string
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
|
||||
json.NewDecoder(data).Decode(&objmap)
|
||||
if objmap == nil {
|
||||
return make(map[string]string)
|
||||
}
|
||||
|
||||
return objmap
|
||||
}
|
||||
|
||||
// MapFromJSON will decode the key/value pair map
|
||||
func MapBoolFromJSON(data io.Reader) map[string]bool {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap map[string]bool
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
|
||||
json.NewDecoder(data).Decode(&objmap)
|
||||
if objmap == nil {
|
||||
return make(map[string]bool)
|
||||
}
|
||||
|
||||
return objmap
|
||||
}
|
||||
|
||||
@@ -427,12 +429,13 @@ func ArrayToJSON(objmap []string) string {
|
||||
}
|
||||
|
||||
func ArrayFromJSON(data io.Reader) []string {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap []string
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
|
||||
json.NewDecoder(data).Decode(&objmap)
|
||||
if objmap == nil {
|
||||
return make([]string, 0)
|
||||
}
|
||||
|
||||
return objmap
|
||||
}
|
||||
|
||||
@@ -459,12 +462,13 @@ func StringInterfaceToJSON(objmap map[string]any) string {
|
||||
}
|
||||
|
||||
func StringInterfaceFromJSON(data io.Reader) map[string]any {
|
||||
decoder := json.NewDecoder(data)
|
||||
|
||||
var objmap map[string]any
|
||||
if err := decoder.Decode(&objmap); err != nil {
|
||||
|
||||
json.NewDecoder(data).Decode(&objmap)
|
||||
if objmap == nil {
|
||||
return make(map[string]any)
|
||||
}
|
||||
|
||||
return objmap
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ func slackParseChannels(data io.Reader, channelType model.ChannelType) ([]slackC
|
||||
|
||||
var channels []slackChannel
|
||||
if err := decoder.Decode(&channels); err != nil {
|
||||
mlog.Warn("Slack Import: Error occurred when parsing some Slack channels. Import may work anyway.")
|
||||
mlog.Warn("Slack Import: Error occurred when parsing some Slack channels. Import may work anyway.", mlog.Err(err))
|
||||
return channels, err
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func slackParsePosts(data io.Reader) ([]slackPost, error) {
|
||||
|
||||
var posts []slackPost
|
||||
if err := decoder.Decode(&posts); err != nil {
|
||||
mlog.Warn("Slack Import: Error occurred when parsing some Slack posts. Import may work anyway.")
|
||||
mlog.Warn("Slack Import: Error occurred when parsing some Slack posts. Import may work anyway.", mlog.Err(err))
|
||||
return posts, err
|
||||
}
|
||||
return posts, nil
|
||||
|
||||
@@ -500,15 +500,16 @@ func (s *FileBackendTestSuite) TestFileModTime() {
|
||||
|
||||
func BenchmarkS3WriteFile(b *testing.B) {
|
||||
settings := FileBackendSettings{
|
||||
DriverName: driverS3,
|
||||
AmazonS3AccessKeyId: "minioaccesskey",
|
||||
AmazonS3SecretAccessKey: "miniosecretkey",
|
||||
AmazonS3Bucket: "mattermost-test",
|
||||
AmazonS3Region: "",
|
||||
AmazonS3Endpoint: "localhost:9000",
|
||||
AmazonS3PathPrefix: "",
|
||||
AmazonS3SSL: false,
|
||||
AmazonS3SSE: false,
|
||||
DriverName: driverS3,
|
||||
AmazonS3AccessKeyId: "minioaccesskey",
|
||||
AmazonS3SecretAccessKey: "miniosecretkey",
|
||||
AmazonS3Bucket: "mattermost-test",
|
||||
AmazonS3Region: "",
|
||||
AmazonS3Endpoint: "localhost:9000",
|
||||
AmazonS3PathPrefix: "",
|
||||
AmazonS3SSL: false,
|
||||
AmazonS3SSE: false,
|
||||
AmazonS3RequestTimeoutMilliseconds: 20000,
|
||||
}
|
||||
|
||||
backend, err := NewFileBackend(settings)
|
||||
|
||||
@@ -58,7 +58,6 @@ type mailData struct {
|
||||
}
|
||||
|
||||
// smtpClient is implemented by an smtp.Client. See https://golang.org/pkg/net/smtp/#Client.
|
||||
//
|
||||
type smtpClient interface {
|
||||
Mail(string) error
|
||||
Rcpt(string) error
|
||||
|
||||
@@ -241,8 +241,8 @@ func (c *Context) SetInvalidRemoteClusterTokenError() {
|
||||
c.Err = NewInvalidRemoteClusterTokenError()
|
||||
}
|
||||
|
||||
func (c *Context) SetJSONEncodingError() {
|
||||
c.Err = NewJSONEncodingError()
|
||||
func (c *Context) SetJSONEncodingError(err error) {
|
||||
c.Err = NewJSONEncodingError(err)
|
||||
}
|
||||
|
||||
func (c *Context) SetCommandNotFoundError() {
|
||||
@@ -294,9 +294,9 @@ func NewInvalidRemoteClusterTokenError() *model.AppError {
|
||||
return err
|
||||
}
|
||||
|
||||
func NewJSONEncodingError() *model.AppError {
|
||||
err := model.NewAppError("Context", "api.context.json_encoding.app_error", nil, "", http.StatusInternalServerError)
|
||||
return err
|
||||
func NewJSONEncodingError(err error) *model.AppError {
|
||||
appErr := model.NewAppError("Context", "api.context.json_encoding.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
return appErr
|
||||
}
|
||||
|
||||
func (c *Context) SetPermissionError(permissions ...*model.Permission) {
|
||||
|
||||
@@ -48,7 +48,7 @@ func authorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var authRequest *model.AuthorizeRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&authRequest)
|
||||
if err != nil || authRequest == nil {
|
||||
c.SetInvalidParam("authorize_request")
|
||||
c.SetInvalidParamWithErr("authorize_request", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ func getAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.LogAudit("success")
|
||||
|
||||
if err := json.NewEncoder(w).Encode(accessRsp); err != nil {
|
||||
mlog.Warn("Error writing response", mlog.Err(err))
|
||||
c.Logger.Warn("Error writing response", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,15 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
if *c.App.Config().LogSettings.EnableWebhookDebugging {
|
||||
if c.Err != nil {
|
||||
payload, _ := json.Marshal(incomingWebhookPayload)
|
||||
mlog.Debug("Incoming webhook received", mlog.String("webhook_id", id), mlog.String("request_id", c.AppContext.RequestId()), mlog.String("payload", string(payload)))
|
||||
fields := []mlog.Field{mlog.String("webhook_id", id), mlog.String("request_id", c.AppContext.RequestId())}
|
||||
payload, err := json.Marshal(incomingWebhookPayload)
|
||||
if err != nil {
|
||||
fields = append(fields, mlog.NamedErr("encoding_err", err))
|
||||
} else {
|
||||
fields = append(fields, mlog.String("payload", string(payload)))
|
||||
}
|
||||
|
||||
mlog.Debug("Incoming webhook received", fields...)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
Ссылка в новой задаче
Block a user