diff --git a/app/channels.go b/app/channels.go index 1e630ba5b9..b8ae9a5450 100644 --- a/app/channels.go +++ b/app/channels.go @@ -17,6 +17,7 @@ import ( "github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/plugin" "github.com/mattermost/mattermost-server/v6/services/imageproxy" + "github.com/mattermost/mattermost-server/v6/shared/filestore" "github.com/mattermost/mattermost-server/v6/shared/mlog" "github.com/pkg/errors" ) @@ -48,6 +49,7 @@ type namer interface { type Channels struct { srv *Server cfgSvc configSvc + filestore filestore.FileBackend licenseSvc licenseSvc postActionCookieSecret []byte @@ -115,6 +117,7 @@ func NewChannels(s *Server, services map[ServiceKey]interface{}) (*Channels, err requiredServices := []ServiceKey{ ConfigKey, LicenseKey, + FilestoreKey, } for _, svcKey := range requiredServices { svc, ok := services[svcKey] @@ -133,6 +136,12 @@ func NewChannels(s *Server, services map[ServiceKey]interface{}) (*Channels, err return nil, errors.New("Config service does not contain Name method") } ch.cfgSvc = cfgSvc + case FilestoreKey: + filestore, ok := svc.(filestore.FileBackend) + if !ok { + return nil, errors.New("Filestore service did not satisfy FileBackend interface") + } + ch.filestore = filestore case LicenseKey: svc, ok := svc.(licenseSvc) if !ok { diff --git a/app/file.go b/app/file.go index 7ff5f8ca53..15bcd5e4ad 100644 --- a/app/file.go +++ b/app/file.go @@ -48,7 +48,7 @@ const ( ) func (a *App) FileBackend() filestore.FileBackend { - return a.Srv().FileBackend() + return a.ch.filestore } func (a *App) CheckMandatoryS3Fields(settings *model.FileSettings) *model.AppError { diff --git a/app/notification_push_test.go b/app/notification_push_test.go index 867e2ef136..5173e38fcc 100644 --- a/app/notification_push_test.go +++ b/app/notification_push_test.go @@ -19,6 +19,7 @@ import ( "github.com/mattermost/mattermost-server/v6/config" "github.com/mattermost/mattermost-server/v6/model" + fmocks "github.com/mattermost/mattermost-server/v6/shared/filestore/mocks" "github.com/mattermost/mattermost-server/v6/shared/i18n" "github.com/mattermost/mattermost-server/v6/store/storetest/mocks" "github.com/mattermost/mattermost-server/v6/testlib" @@ -1428,14 +1429,16 @@ func TestPushNotificationRace(t *testing.T) { Return(&model.Preference{Value: "test"}, nil) mockStore.On("Preference").Return(&mockPreferenceStore) s := &Server{ - Store: mockStore, - products: make(map[string]Product), - Router: mux.NewRouter(), + Store: mockStore, + products: make(map[string]Product), + Router: mux.NewRouter(), + filestore: &fmocks.FileBackend{}, } s.configStore = &configWrapper{srv: s, Store: memoryStore} serviceMap := map[ServiceKey]interface{}{ - ConfigKey: s.configStore, - LicenseKey: &licenseWrapper{s}, + ConfigKey: s.configStore, + LicenseKey: &licenseWrapper{s}, + FilestoreKey: s.filestore, } ch, err := NewChannels(s, serviceMap) require.NoError(t, err) diff --git a/app/options.go b/app/options.go index 5da342136e..d4ff13e9d5 100644 --- a/app/options.go +++ b/app/options.go @@ -9,6 +9,7 @@ import ( "github.com/mattermost/mattermost-server/v6/config" "github.com/mattermost/mattermost-server/v6/einterfaces" "github.com/mattermost/mattermost-server/v6/model" + "github.com/mattermost/mattermost-server/v6/shared/filestore" "github.com/mattermost/mattermost-server/v6/shared/mlog" "github.com/mattermost/mattermost-server/v6/store" ) @@ -65,6 +66,13 @@ func ConfigStore(configStore *config.Store) Option { } } +func SetFileStore(filestore filestore.FileBackend) Option { + return func(s *Server) error { + s.filestore = filestore + return nil + } +} + func RunEssentialJobs(s *Server) error { s.runEssentialJobs = true diff --git a/app/server.go b/app/server.go index 018168b4f6..44a979f460 100644 --- a/app/server.go +++ b/app/server.go @@ -89,8 +89,9 @@ var SentryDSN = "placeholder_sentry_dsn" type ServiceKey string const ( - ConfigKey ServiceKey = "config" - LicenseKey ServiceKey = "license" + ConfigKey ServiceKey = "config" + LicenseKey ServiceKey = "license" + FilestoreKey ServiceKey = "filestore" ) type Server struct { @@ -362,8 +363,9 @@ func NewServer(options ...Option) (*Server, error) { } serviceMap := map[ServiceKey]interface{}{ - ConfigKey: s.configStore, - LicenseKey: s.licenseWrapper, + ConfigKey: s.configStore, + LicenseKey: s.licenseWrapper, + FilestoreKey: s.filestore, } // Step 8: Initialize products. // Depends on s.httpService.