[MM-56061] Only render where field in model.AppError when it's present (#25648)
* Only render where field in model.AppError when it's present * Remove trailing comma from permission error
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a54f927e3d
Коммит
5b6b425cfc
@@ -911,7 +911,6 @@ type AppIface interface {
|
||||
ListTeamCommands(teamID string) ([]*model.Command, *model.AppError)
|
||||
Log() *mlog.Logger
|
||||
LoginByOAuth(c request.CTX, service string, userData io.Reader, teamID string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||
MakePermissionError(s *model.Session, permissions []*model.Permission) *model.AppError
|
||||
MarkChannelsAsViewed(c request.CTX, channelIDs []string, userID string, currentSessionId string, collapsedThreadsSupported, isCRTEnabled bool) (map[string]int64, *model.AppError)
|
||||
MaxPostSize() int
|
||||
MessageExport() einterfaces.MessageExportInterface
|
||||
|
||||
@@ -14,15 +14,6 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
func (a *App) MakePermissionError(s *model.Session, permissions []*model.Permission) *model.AppError {
|
||||
permissionsStr := "permission="
|
||||
for _, permission := range permissions {
|
||||
permissionsStr += permission.Id
|
||||
permissionsStr += ","
|
||||
}
|
||||
return model.NewAppError("Permissions", "api.context.permissions.app_error", nil, "userId="+s.UserId+", "+permissionsStr, http.StatusForbidden)
|
||||
}
|
||||
|
||||
func (a *App) SessionHasPermissionTo(session model.Session, permission *model.Permission) bool {
|
||||
if session.IsUnrestricted() {
|
||||
return true
|
||||
@@ -360,7 +351,7 @@ func (a *App) SessionHasPermissionToManageBot(session model.Session, botUserId s
|
||||
// the bot doesn't exist at all.
|
||||
return model.MakeBotNotFoundError("permissions", botUserId)
|
||||
}
|
||||
return a.MakePermissionError(&session, []*model.Permission{model.PermissionManageBots})
|
||||
return model.MakePermissionError(&session, []*model.Permission{model.PermissionManageBots})
|
||||
}
|
||||
} else {
|
||||
if !a.SessionHasPermissionTo(session, model.PermissionManageOthersBots) {
|
||||
@@ -369,7 +360,7 @@ func (a *App) SessionHasPermissionToManageBot(session model.Session, botUserId s
|
||||
// pretend as if the bot doesn't exist at all.
|
||||
return model.MakeBotNotFoundError("permissions", botUserId)
|
||||
}
|
||||
return a.MakePermissionError(&session, []*model.Permission{model.PermissionManageOthersBots})
|
||||
return model.MakePermissionError(&session, []*model.Permission{model.PermissionManageOthersBots})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12464,28 +12464,6 @@ func (a *OpenTracingAppLayer) MakeAuditRecord(rctx request.CTX, event string, in
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) MakePermissionError(s *model.Session, permissions []*model.Permission) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.MakePermissionError")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store().SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store().SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.MakePermissionError(s, permissions)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) MarkChannelAsUnreadFromPost(c request.CTX, postID string, userID string, collapsedThreadsSupported bool) (*model.ChannelUnreadAt, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.MarkChannelAsUnreadFromPost")
|
||||
|
||||
@@ -2055,10 +2055,10 @@ func (a *App) GetPostIfAuthorized(c request.CTX, postID string, session *model.S
|
||||
if !a.SessionHasPermissionToChannel(c, *session, channel.Id, model.PermissionReadChannelContent) {
|
||||
if channel.Type == model.ChannelTypeOpen && !*a.Config().ComplianceSettings.Enable {
|
||||
if !a.SessionHasPermissionToTeam(*session, channel.TeamId, model.PermissionReadPublicChannel) {
|
||||
return nil, a.MakePermissionError(session, []*model.Permission{model.PermissionReadPublicChannel})
|
||||
return nil, model.MakePermissionError(session, []*model.Permission{model.PermissionReadPublicChannel})
|
||||
}
|
||||
} else {
|
||||
return nil, a.MakePermissionError(session, []*model.Permission{model.PermissionReadChannelContent})
|
||||
return nil, model.MakePermissionError(session, []*model.Permission{model.PermissionReadChannelContent})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user