Migrate to stateless app.App (#17542)
* add request context * move initialialization to server * use app interface instead of global app functions * remove app context from webconn * cleanup * remove duplicated services * move context to separate package * remove finalize init method and move content to NewServer function * restart workers and schedulers after adding license for tests * reflect review comments Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c09369f14a
Коммит
5ea06e51d0
30
web/oauth.go
30
web/oauth.go
@@ -54,7 +54,7 @@ func authorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if c.App.Session().IsOAuth {
|
||||
if c.AppContext.Session().IsOAuth {
|
||||
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
|
||||
c.Err.DetailedError += ", attempted access by oauth app"
|
||||
return
|
||||
@@ -64,7 +64,7 @@ func authorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
defer c.LogAuditRec(auditRec)
|
||||
c.LogAudit("attempt")
|
||||
|
||||
redirectUrl, err := c.App.AllowOAuthAppAccessToUser(c.App.Session().UserId, authRequest)
|
||||
redirectUrl, err := c.App.AllowOAuthAppAccessToUser(c.AppContext.Session().UserId, authRequest)
|
||||
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
@@ -89,7 +89,7 @@ func deauthorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
auditRec := c.MakeAuditRecord("deauthorizeOAuthApp", audit.Fail)
|
||||
defer c.LogAuditRec(auditRec)
|
||||
|
||||
err := c.App.DeauthorizeOAuthAppForUser(c.App.Session().UserId, clientId)
|
||||
err := c.App.DeauthorizeOAuthAppForUser(c.AppContext.Session().UserId, clientId)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -134,7 +134,7 @@ func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// here we should check if the user is logged in
|
||||
if c.App.Session().UserId == "" {
|
||||
if c.AppContext.Session().UserId == "" {
|
||||
if loginHint == model.USER_AUTH_SERVICE_SAML {
|
||||
http.Redirect(w, r, c.GetSiteURLHeader()+"/login/sso/saml?redirect_to="+url.QueryEscape(r.RequestURI), http.StatusFound)
|
||||
} else {
|
||||
@@ -155,14 +155,14 @@ func authorizeOAuthPage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
isAuthorized := false
|
||||
|
||||
if _, err := c.App.GetPreferenceByCategoryAndNameForUser(c.App.Session().UserId, model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, authRequest.ClientId); err == nil {
|
||||
if _, err := c.App.GetPreferenceByCategoryAndNameForUser(c.AppContext.Session().UserId, model.PREFERENCE_CATEGORY_AUTHORIZED_OAUTH_APP, authRequest.ClientId); err == nil {
|
||||
// when we support scopes we should check if the scopes match
|
||||
isAuthorized = true
|
||||
}
|
||||
|
||||
// Automatically allow if the app is trusted
|
||||
if oauthApp.IsTrusted || isAuthorized {
|
||||
redirectUrl, err := c.App.AllowOAuthAppAccessToUser(c.App.Session().UserId, authRequest)
|
||||
redirectUrl, err := c.App.AllowOAuthAppAccessToUser(c.AppContext.Session().UserId, authRequest)
|
||||
|
||||
if err != nil {
|
||||
utils.RenderWebAppError(c.App.Config(), w, r, err, c.App.AsymmetricSigningKey())
|
||||
@@ -295,15 +295,15 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
err.Translate(c.App.T)
|
||||
err.Translate(c.AppContext.T)
|
||||
c.LogErrorByCode(err)
|
||||
renderError(err)
|
||||
return
|
||||
}
|
||||
|
||||
user, err := c.App.CompleteOAuth(service, body, teamId, props, tokenUser)
|
||||
user, err := c.App.CompleteOAuth(c.AppContext, service, body, teamId, props, tokenUser)
|
||||
if err != nil {
|
||||
err.Translate(c.App.T)
|
||||
err.Translate(c.AppContext.T)
|
||||
c.LogErrorByCode(err)
|
||||
renderError(err)
|
||||
return
|
||||
@@ -314,9 +314,9 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
} else if action == model.OAUTH_ACTION_SSO_TO_EMAIL {
|
||||
redirectURL = app.GetProtocol(r) + "://" + r.Host + "/claim?email=" + url.QueryEscape(props["email"])
|
||||
} else {
|
||||
err = c.App.DoLogin(w, r, user, "", isMobile, false, false)
|
||||
err = c.App.DoLogin(c.AppContext, w, r, user, "", isMobile, false, false)
|
||||
if err != nil {
|
||||
err.Translate(c.App.T)
|
||||
err.Translate(c.AppContext.T)
|
||||
mlog.Error(err.Error())
|
||||
renderError(err)
|
||||
return
|
||||
@@ -324,19 +324,19 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Old mobile version
|
||||
if isMobile && !hasRedirectURL {
|
||||
c.App.AttachSessionCookies(w, r)
|
||||
c.App.AttachSessionCookies(c.AppContext, w, r)
|
||||
return
|
||||
} else
|
||||
// New mobile version
|
||||
if isMobile && hasRedirectURL {
|
||||
redirectURL = utils.AppendQueryParamsToURL(redirectURL, map[string]string{
|
||||
model.SESSION_COOKIE_TOKEN: c.App.Session().Token,
|
||||
model.SESSION_COOKIE_CSRF: c.App.Session().GetCSRF(),
|
||||
model.SESSION_COOKIE_TOKEN: c.AppContext.Session().Token,
|
||||
model.SESSION_COOKIE_CSRF: c.AppContext.Session().GetCSRF(),
|
||||
})
|
||||
utils.RenderMobileAuthComplete(w, redirectURL)
|
||||
return
|
||||
} else { // For web
|
||||
c.App.AttachSessionCookies(w, r)
|
||||
c.App.AttachSessionCookies(c.AppContext, w, r)
|
||||
|
||||
// If no redirect url is passed, get the default one
|
||||
if !hasRedirectURL {
|
||||
|
||||
Ссылка в новой задаче
Block a user