diff --git a/server/app/app.go b/server/app/app.go index bc7aaa7a4..14363935a 100644 --- a/server/app/app.go +++ b/server/app/app.go @@ -1,6 +1,7 @@ package app import ( + "github.com/mattermost/focalboard/server/auth" "github.com/mattermost/focalboard/server/services/config" "github.com/mattermost/focalboard/server/services/store" "github.com/mattermost/focalboard/server/services/webhook" @@ -11,11 +12,26 @@ import ( type App struct { config *config.Configuration store store.Store + auth *auth.Auth wsServer *ws.Server filesBackend filesstore.FileBackend webhook *webhook.Client } -func New(config *config.Configuration, store store.Store, wsServer *ws.Server, filesBackend filesstore.FileBackend, webhook *webhook.Client) *App { - return &App{config: config, store: store, wsServer: wsServer, filesBackend: filesBackend, webhook: webhook} +func New( + config *config.Configuration, + store store.Store, + auth *auth.Auth, + wsServer *ws.Server, + filesBackend filesstore.FileBackend, + webhook *webhook.Client, +) *App { + return &App{ + config: config, + store: store, + auth: auth, + wsServer: wsServer, + filesBackend: filesBackend, + webhook: webhook, + } } diff --git a/server/app/auth.go b/server/app/auth.go index 51f923ab2..6e6760c6a 100644 --- a/server/app/auth.go +++ b/server/app/auth.go @@ -2,7 +2,6 @@ package app import ( "log" - "time" "github.com/google/uuid" "github.com/mattermost/focalboard/server/model" @@ -13,18 +12,7 @@ import ( // GetSession Get a user active session and refresh the session if is needed func (a *App) GetSession(token string) (*model.Session, error) { - if len(token) < 1 { - return nil, errors.New("no session token") - } - - session, err := a.store.GetSession(token, a.config.SessionExpireTime) - if err != nil { - return nil, errors.Wrap(err, "unable to get the session for the token") - } - if session.UpdateAt < (time.Now().Unix() - a.config.SessionRefreshTime) { - a.store.RefreshSession(session) - } - return session, nil + return a.auth.GetSession(token) } // GetRegisteredUserCount returns the number of registered users diff --git a/server/app/blocks_test.go b/server/app/blocks_test.go index b26338df3..7ebcc1d5e 100644 --- a/server/app/blocks_test.go +++ b/server/app/blocks_test.go @@ -26,7 +26,7 @@ func TestGetParentID(t *testing.T) { auth := auth.New(&cfg, store) wsserver := ws.NewServer(auth, true) webhook := webhook.NewClient(&cfg) - app := New(&cfg, store, wsserver, &mocks.FileBackend{}, webhook) + app := New(&cfg, store, auth, wsserver, &mocks.FileBackend{}, webhook) t.Run("success query", func(t *testing.T) { store.EXPECT().GetParentID(gomock.Eq("test-id")).Return("test-parent-id", nil) diff --git a/server/server/server.go b/server/server/server.go index 682d29a44..4a683a76b 100644 --- a/server/server/server.go +++ b/server/server/server.go @@ -77,7 +77,7 @@ func New(cfg *config.Configuration, singleUser bool) (*Server, error) { webhookClient := webhook.NewClient(cfg) - appBuilder := func() *app.App { return app.New(cfg, store, wsServer, filesBackend, webhookClient) } + appBuilder := func() *app.App { return app.New(cfg, store, auth, wsServer, filesBackend, webhookClient) } api := api.NewAPI(appBuilder, singleUser) // Local router for admin APIs