MM-40818: Pass filestore to channels (#19677)

We move away from referencing server struct
but pass the filestore service to Channels
explicitly.

https://mattermost.atlassian.net/browse/MM-40818

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2022-03-10 19:49:05 +05:30
коммит произвёл GitHub
родитель c8eafebecf
Коммит 7664c9d709
5 изменённых файлов: 32 добавлений и 10 удалений

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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 {

Просмотреть файл

@@ -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)

Просмотреть файл

@@ -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

Просмотреть файл

@@ -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.