MM-21898 - Part 1: Generate and use an interface instead of *A… (#13840)
* Generate and use an interface instead of *App
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
66fc096768
Коммит
17523fa5d9
@@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
App *app.App
|
||||
App app.AppIface
|
||||
Log *mlog.Logger
|
||||
Params *Params
|
||||
Err *model.AppError
|
||||
@@ -24,20 +24,20 @@ type Context struct {
|
||||
}
|
||||
|
||||
func (c *Context) LogAudit(extraInfo string) {
|
||||
audit := &model.Audit{UserId: c.App.Session.UserId, IpAddress: c.App.IpAddress, Action: c.App.Path, ExtraInfo: extraInfo, SessionId: c.App.Session.Id}
|
||||
if err := c.App.Srv.Store.Audit().Save(audit); err != nil {
|
||||
audit := &model.Audit{UserId: c.App.Session().UserId, IpAddress: c.App.IpAddress(), Action: c.App.Path(), ExtraInfo: extraInfo, SessionId: c.App.Session().Id}
|
||||
if err := c.App.Srv().Store.Audit().Save(audit); err != nil {
|
||||
c.LogError(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Context) LogAuditWithUserId(userId, extraInfo string) {
|
||||
|
||||
if len(c.App.Session.UserId) > 0 {
|
||||
extraInfo = strings.TrimSpace(extraInfo + " session_user=" + c.App.Session.UserId)
|
||||
if len(c.App.Session().UserId) > 0 {
|
||||
extraInfo = strings.TrimSpace(extraInfo + " session_user=" + c.App.Session().UserId)
|
||||
}
|
||||
|
||||
audit := &model.Audit{UserId: userId, IpAddress: c.App.IpAddress, Action: c.App.Path, ExtraInfo: extraInfo, SessionId: c.App.Session.Id}
|
||||
if err := c.App.Srv.Store.Audit().Save(audit); err != nil {
|
||||
audit := &model.Audit{UserId: userId, IpAddress: c.App.IpAddress(), Action: c.App.Path(), ExtraInfo: extraInfo, SessionId: c.App.Session().Id}
|
||||
if err := c.App.Srv().Store.Audit().Save(audit); err != nil {
|
||||
c.LogError(err)
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func (c *Context) LogAuditWithUserId(userId, extraInfo string) {
|
||||
func (c *Context) LogError(err *model.AppError) {
|
||||
// Filter out 404s, endless reconnects and browser compatibility errors
|
||||
if err.StatusCode == http.StatusNotFound ||
|
||||
(c.App.Path == "/api/v3/users/websocket" && err.StatusCode == http.StatusUnauthorized) ||
|
||||
(c.App.Path() == "/api/v3/users/websocket" && err.StatusCode == http.StatusUnauthorized) ||
|
||||
err.Id == "web.check_browser_compatibility.app_error" {
|
||||
c.LogDebug(err)
|
||||
} else {
|
||||
@@ -82,19 +82,19 @@ func (c *Context) LogDebug(err *model.AppError) {
|
||||
}
|
||||
|
||||
func (c *Context) IsSystemAdmin() bool {
|
||||
return c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM)
|
||||
return c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM)
|
||||
}
|
||||
|
||||
func (c *Context) SessionRequired() {
|
||||
if !*c.App.Config().ServiceSettings.EnableUserAccessTokens &&
|
||||
c.App.Session.Props[model.SESSION_PROP_TYPE] == model.SESSION_TYPE_USER_ACCESS_TOKEN &&
|
||||
c.App.Session.Props[model.SESSION_PROP_IS_BOT] != model.SESSION_PROP_IS_BOT_VALUE {
|
||||
c.App.Session().Props[model.SESSION_PROP_TYPE] == model.SESSION_TYPE_USER_ACCESS_TOKEN &&
|
||||
c.App.Session().Props[model.SESSION_PROP_IS_BOT] != model.SESSION_PROP_IS_BOT_VALUE {
|
||||
|
||||
c.Err = model.NewAppError("", "api.context.session_expired.app_error", nil, "UserAccessToken", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if len(c.App.Session.UserId) == 0 {
|
||||
if len(c.App.Session().UserId) == 0 {
|
||||
c.Err = model.NewAppError("", "api.context.session_expired.app_error", nil, "UserRequired", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
@@ -107,11 +107,11 @@ func (c *Context) MfaRequired() {
|
||||
}
|
||||
|
||||
// OAuth integrations are excepted
|
||||
if c.App.Session.IsOAuth {
|
||||
if c.App.Session().IsOAuth {
|
||||
return
|
||||
}
|
||||
|
||||
if user, err := c.App.GetUser(c.App.Session.UserId); err != nil {
|
||||
if user, err := c.App.GetUser(c.App.Session().UserId); err != nil {
|
||||
c.Err = model.NewAppError("", "api.context.session_expired.app_error", nil, "MfaRequired", http.StatusUnauthorized)
|
||||
return
|
||||
} else {
|
||||
@@ -127,7 +127,7 @@ func (c *Context) MfaRequired() {
|
||||
|
||||
// Special case to let user get themself
|
||||
subpath, _ := utils.GetSubpathFromConfig(c.App.Config())
|
||||
if c.App.Path == path.Join(subpath, "/api/v4/users/me") {
|
||||
if c.App.Path() == path.Join(subpath, "/api/v4/users/me") {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ func (c *Context) SetCommandNotFoundError() {
|
||||
}
|
||||
|
||||
func (c *Context) HandleEtag(etag string, routeName string, w http.ResponseWriter, r *http.Request) bool {
|
||||
metrics := c.App.Metrics
|
||||
metrics := c.App.Metrics()
|
||||
if et := r.Header.Get(model.HEADER_ETAG_CLIENT); len(etag) > 0 {
|
||||
if et == etag {
|
||||
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
|
||||
@@ -224,7 +224,7 @@ func (c *Context) RequireUserId() *Context {
|
||||
}
|
||||
|
||||
if c.Params.UserId == model.ME {
|
||||
c.Params.UserId = c.App.Session.UserId
|
||||
c.Params.UserId = c.App.Session().UserId
|
||||
}
|
||||
|
||||
if len(c.Params.UserId) != 26 {
|
||||
|
||||
Ссылка в новой задаче
Block a user