[GH-15744] Remove direct token store access in api4/user module (#18411)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
b6f0afb919
Коммит
d0fad86246
13
api4/user.go
13
api4/user.go
@@ -123,16 +123,9 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
var ruser *model.User
|
var ruser *model.User
|
||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
if tokenId != "" {
|
if tokenId != "" {
|
||||||
token, nErr := c.App.Srv().Store.Token().GetByToken(tokenId)
|
token, appErr := c.App.GetTokenById(tokenId)
|
||||||
if nErr != nil {
|
if appErr != nil {
|
||||||
var status int
|
c.Err = appErr
|
||||||
switch nErr.(type) {
|
|
||||||
case *store.ErrNotFound:
|
|
||||||
status = http.StatusNotFound
|
|
||||||
default:
|
|
||||||
status = http.StatusInternalServerError
|
|
||||||
}
|
|
||||||
c.Err = model.NewAppError("CreateUserWithToken", "api.user.create_user.signup_link_invalid.app_error", nil, nErr.Error(), status)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
auditRec.AddMeta("token_type", token.Type)
|
auditRec.AddMeta("token_type", token.Type)
|
||||||
|
|||||||
@@ -757,6 +757,7 @@ type AppIface interface {
|
|||||||
GetThreadMembershipForUser(userId, threadId string) (*model.ThreadMembership, *model.AppError)
|
GetThreadMembershipForUser(userId, threadId string) (*model.ThreadMembership, *model.AppError)
|
||||||
GetThreadMembershipsForUser(userID, teamID string) ([]*model.ThreadMembership, error)
|
GetThreadMembershipsForUser(userID, teamID string) ([]*model.ThreadMembership, error)
|
||||||
GetThreadsForUser(userID, teamID string, options model.GetUserThreadsOpts) (*model.Threads, *model.AppError)
|
GetThreadsForUser(userID, teamID string, options model.GetUserThreadsOpts) (*model.Threads, *model.AppError)
|
||||||
|
GetTokenById(token string) (*model.Token, *model.AppError)
|
||||||
GetUploadSession(uploadId string) (*model.UploadSession, *model.AppError)
|
GetUploadSession(uploadId string) (*model.UploadSession, *model.AppError)
|
||||||
GetUploadSessionsForUser(userID string) ([]*model.UploadSession, *model.AppError)
|
GetUploadSessionsForUser(userID string) ([]*model.UploadSession, *model.AppError)
|
||||||
GetUser(userID string) (*model.User, *model.AppError)
|
GetUser(userID string) (*model.User, *model.AppError)
|
||||||
|
|||||||
@@ -9330,6 +9330,28 @@ func (a *OpenTracingAppLayer) GetThreadsForUser(userID string, teamID string, op
|
|||||||
return resultVar0, resultVar1
|
return resultVar0, resultVar1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *OpenTracingAppLayer) GetTokenById(token string) (*model.Token, *model.AppError) {
|
||||||
|
origCtx := a.ctx
|
||||||
|
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetTokenById")
|
||||||
|
|
||||||
|
a.ctx = newCtx
|
||||||
|
a.app.Srv().Store.SetContext(newCtx)
|
||||||
|
defer func() {
|
||||||
|
a.app.Srv().Store.SetContext(origCtx)
|
||||||
|
a.ctx = origCtx
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer span.Finish()
|
||||||
|
resultVar0, resultVar1 := a.app.GetTokenById(token)
|
||||||
|
|
||||||
|
if resultVar1 != nil {
|
||||||
|
span.LogFields(spanlog.Error(resultVar1))
|
||||||
|
ext.Error.Set(span, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultVar0, resultVar1
|
||||||
|
}
|
||||||
|
|
||||||
func (a *OpenTracingAppLayer) GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions) (*model.UsersStats, *model.AppError) {
|
func (a *OpenTracingAppLayer) GetTotalUsersStats(viewRestrictions *model.ViewUsersRestrictions) (*model.UsersStats, *model.AppError) {
|
||||||
origCtx := a.ctx
|
origCtx := a.ctx
|
||||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetTotalUsersStats")
|
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetTotalUsersStats")
|
||||||
|
|||||||
19
app/user.go
19
app/user.go
@@ -1353,6 +1353,25 @@ func (a *App) GetPasswordRecoveryToken(token string) (*model.Token, *model.AppEr
|
|||||||
return rtoken, nil
|
return rtoken, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) GetTokenById(token string) (*model.Token, *model.AppError) {
|
||||||
|
rtoken, err := a.Srv().Store.Token().GetByToken(token)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
var status int
|
||||||
|
|
||||||
|
switch err.(type) {
|
||||||
|
case *store.ErrNotFound:
|
||||||
|
status = http.StatusNotFound
|
||||||
|
default:
|
||||||
|
status = http.StatusInternalServerError
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, model.NewAppError("GetTokenById", "api.user.create_user.signup_link_invalid.app_error", nil, err.Error(), status)
|
||||||
|
}
|
||||||
|
|
||||||
|
return rtoken, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) DeleteToken(token *model.Token) *model.AppError {
|
func (a *App) DeleteToken(token *model.Token) *model.AppError {
|
||||||
err := a.Srv().Store.Token().Delete(token.Token)
|
err := a.Srv().Store.Token().Delete(token.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user