Migrate store methods to use request.Context instead of context.Context (#24836)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
0d5a8b8841
Коммит
13c05a571f
@@ -146,8 +146,8 @@ func (a *App) GetOAuthAppsByCreator(userID string, page, perPage int) ([]*model.
|
||||
return oauthApps, nil
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthImplicitRedirect(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
session, err := a.GetOAuthAccessTokenForImplicitFlow(userID, authRequest)
|
||||
func (a *App) GetOAuthImplicitRedirect(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
session, err := a.GetOAuthAccessTokenForImplicitFlow(c, userID, authRequest)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func (a *App) GetOAuthCodeRedirect(userID string, authRequest *model.AuthorizeRe
|
||||
return uri.String(), nil
|
||||
}
|
||||
|
||||
func (a *App) AllowOAuthAppAccessToUser(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
func (a *App) AllowOAuthAppAccessToUser(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError) {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return "", model.NewAppError("AllowOAuthAppAccessToUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -214,7 +214,7 @@ func (a *App) AllowOAuthAppAccessToUser(userID string, authRequest *model.Author
|
||||
case model.AuthCodeResponseType:
|
||||
redirectURI, err = a.GetOAuthCodeRedirect(userID, authRequest)
|
||||
case model.ImplicitResponseType:
|
||||
redirectURI, err = a.GetOAuthImplicitRedirect(userID, authRequest)
|
||||
redirectURI, err = a.GetOAuthImplicitRedirect(c, userID, authRequest)
|
||||
default:
|
||||
return authRequest.RedirectURI + "?error=unsupported_response_type&state=" + authRequest.State, nil
|
||||
}
|
||||
@@ -240,7 +240,7 @@ func (a *App) AllowOAuthAppAccessToUser(userID string, authRequest *model.Author
|
||||
return redirectURI, nil
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError) {
|
||||
func (a *App) GetOAuthAccessTokenForImplicitFlow(c *request.Context, userID string, authRequest *model.AuthorizeRequest) (*model.Session, *model.AppError) {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -255,7 +255,7 @@ func (a *App) GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *mod
|
||||
return nil, err
|
||||
}
|
||||
|
||||
session, err := a.newSession(oauthApp, user)
|
||||
session, err := a.newSession(c, oauthApp, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -269,7 +269,7 @@ func (a *App) GetOAuthAccessTokenForImplicitFlow(userID string, authRequest *mod
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError) {
|
||||
func (a *App) GetOAuthAccessTokenForCodeFlow(c *request.Context, clientId, grantType, redirectURI, code, secret, refreshToken string) (*model.AccessResponse, *model.AppError) {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
|
||||
if accessData != nil {
|
||||
if accessData.IsExpired() {
|
||||
var access *model.AccessResponse
|
||||
access, err := a.newSessionUpdateToken(oauthApp, accessData, user)
|
||||
access, err := a.newSessionUpdateToken(c, oauthApp, accessData, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -338,7 +338,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
|
||||
} else {
|
||||
var session *model.Session
|
||||
// Create a new session and return new access token
|
||||
session, err := a.newSession(oauthApp, user)
|
||||
session, err := a.newSession(c, oauthApp, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -372,7 +372,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
|
||||
return nil, model.NewAppError("GetOAuthAccessToken", "api.oauth.get_access_token.internal_user.app_error", nil, "", http.StatusNotFound)
|
||||
}
|
||||
|
||||
access, err := a.newSessionUpdateToken(oauthApp, accessData, user)
|
||||
access, err := a.newSessionUpdateToken(c, oauthApp, accessData, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -382,7 +382,7 @@ func (a *App) GetOAuthAccessTokenForCodeFlow(clientId, grantType, redirectURI, c
|
||||
return accessRsp, nil
|
||||
}
|
||||
|
||||
func (a *App) newSession(app *model.OAuthApp, user *model.User) (*model.Session, *model.AppError) {
|
||||
func (a *App) newSession(c *request.Context, app *model.OAuthApp, user *model.User) (*model.Session, *model.AppError) {
|
||||
// Set new token an session
|
||||
session := &model.Session{UserId: user.Id, Roles: user.Roles, IsOAuth: true}
|
||||
session.GenerateCSRF()
|
||||
@@ -393,7 +393,7 @@ func (a *App) newSession(app *model.OAuthApp, user *model.User) (*model.Session,
|
||||
session.AddProp(model.SessionPropOs, "OAuth2")
|
||||
session.AddProp(model.SessionPropBrowser, "OAuth2")
|
||||
|
||||
session, err := a.Srv().Store().Session().Save(session)
|
||||
session, err := a.Srv().Store().Session().Save(c, session)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("newSession", "api.oauth.get_access_token.internal_session.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
@@ -403,13 +403,13 @@ func (a *App) newSession(app *model.OAuthApp, user *model.User) (*model.Session,
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (a *App) newSessionUpdateToken(app *model.OAuthApp, accessData *model.AccessData, user *model.User) (*model.AccessResponse, *model.AppError) {
|
||||
func (a *App) newSessionUpdateToken(c *request.Context, app *model.OAuthApp, accessData *model.AccessData, user *model.User) (*model.AccessResponse, *model.AppError) {
|
||||
// Remove the previous session
|
||||
if err := a.Srv().Store().Session().Remove(accessData.Token); err != nil {
|
||||
mlog.Warn("error removing access data token from session", mlog.Err(err))
|
||||
}
|
||||
|
||||
session, err := a.newSession(app, user)
|
||||
session, err := a.newSession(c, app, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -493,7 +493,7 @@ func (a *App) GetAuthorizedAppsForUser(userID string, page, perPage int) ([]*mod
|
||||
return apps, nil
|
||||
}
|
||||
|
||||
func (a *App) DeauthorizeOAuthAppForUser(userID, appID string) *model.AppError {
|
||||
func (a *App) DeauthorizeOAuthAppForUser(c *request.Context, userID, appID string) *model.AppError {
|
||||
if !*a.Config().ServiceSettings.EnableOAuthServiceProvider {
|
||||
return model.NewAppError("DeauthorizeOAuthAppForUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -505,7 +505,7 @@ func (a *App) DeauthorizeOAuthAppForUser(userID, appID string) *model.AppError {
|
||||
}
|
||||
|
||||
for _, ad := range accessData {
|
||||
if err := a.RevokeAccessToken(ad.Token); err != nil {
|
||||
if err := a.RevokeAccessToken(c, ad.Token); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -548,8 +548,8 @@ func (a *App) RegenerateOAuthAppSecret(app *model.OAuthApp) (*model.OAuthApp, *m
|
||||
return app, nil
|
||||
}
|
||||
|
||||
func (a *App) RevokeAccessToken(token string) *model.AppError {
|
||||
if err := a.ch.srv.platform.RevokeAccessToken(token); err != nil {
|
||||
func (a *App) RevokeAccessToken(c *request.Context, token string) *model.AppError {
|
||||
if err := a.ch.srv.platform.RevokeAccessToken(c, token); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, platform.GetTokenError):
|
||||
return model.NewAppError("RevokeAccessToken", "api.oauth.revoke_access_token.get.app_error", nil, "", http.StatusBadRequest).Wrap(err)
|
||||
@@ -678,7 +678,7 @@ func (a *App) CompleteSwitchWithOAuth(c *request.Context, service string, userDa
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", MissingAccountError, nil, "", http.StatusInternalServerError).Wrap(nErr)
|
||||
}
|
||||
|
||||
if err := a.RevokeAllSessions(user.Id); err != nil {
|
||||
if err := a.RevokeAllSessions(c, user.Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -969,7 +969,7 @@ func (a *App) SwitchEmailToOAuth(c *request.Context, w http.ResponseWriter, r *h
|
||||
return authURL, nil
|
||||
}
|
||||
|
||||
func (a *App) SwitchOAuthToEmail(email, password, requesterId string) (string, *model.AppError) {
|
||||
func (a *App) SwitchOAuthToEmail(c *request.Context, email, password, requesterId string) (string, *model.AppError) {
|
||||
if a.Srv().License() != nil && !*a.Config().ServiceSettings.ExperimentalEnableAuthenticationTransfer {
|
||||
return "", model.NewAppError("oauthToEmail", "api.user.oauth_to_email.not_available.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
@@ -991,11 +991,11 @@ func (a *App) SwitchOAuthToEmail(email, password, requesterId string) (string, *
|
||||
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Srv().EmailService.SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error("error sending signin change email", mlog.Err(err))
|
||||
c.Logger().Error("error sending signin change email", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
||||
if err := a.RevokeAllSessions(requesterId); err != nil {
|
||||
if err := a.RevokeAllSessions(c, requesterId); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user