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>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c8eafebecf
Коммит
7664c9d709
@@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
"github.com/mattermost/mattermost-server/v6/plugin"
|
"github.com/mattermost/mattermost-server/v6/plugin"
|
||||||
"github.com/mattermost/mattermost-server/v6/services/imageproxy"
|
"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/mattermost/mattermost-server/v6/shared/mlog"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@@ -48,6 +49,7 @@ type namer interface {
|
|||||||
type Channels struct {
|
type Channels struct {
|
||||||
srv *Server
|
srv *Server
|
||||||
cfgSvc configSvc
|
cfgSvc configSvc
|
||||||
|
filestore filestore.FileBackend
|
||||||
licenseSvc licenseSvc
|
licenseSvc licenseSvc
|
||||||
|
|
||||||
postActionCookieSecret []byte
|
postActionCookieSecret []byte
|
||||||
@@ -115,6 +117,7 @@ func NewChannels(s *Server, services map[ServiceKey]interface{}) (*Channels, err
|
|||||||
requiredServices := []ServiceKey{
|
requiredServices := []ServiceKey{
|
||||||
ConfigKey,
|
ConfigKey,
|
||||||
LicenseKey,
|
LicenseKey,
|
||||||
|
FilestoreKey,
|
||||||
}
|
}
|
||||||
for _, svcKey := range requiredServices {
|
for _, svcKey := range requiredServices {
|
||||||
svc, ok := services[svcKey]
|
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")
|
return nil, errors.New("Config service does not contain Name method")
|
||||||
}
|
}
|
||||||
ch.cfgSvc = cfgSvc
|
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:
|
case LicenseKey:
|
||||||
svc, ok := svc.(licenseSvc)
|
svc, ok := svc.(licenseSvc)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (a *App) FileBackend() filestore.FileBackend {
|
func (a *App) FileBackend() filestore.FileBackend {
|
||||||
return a.Srv().FileBackend()
|
return a.ch.filestore
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CheckMandatoryS3Fields(settings *model.FileSettings) *model.AppError {
|
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/config"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"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/shared/i18n"
|
||||||
"github.com/mattermost/mattermost-server/v6/store/storetest/mocks"
|
"github.com/mattermost/mattermost-server/v6/store/storetest/mocks"
|
||||||
"github.com/mattermost/mattermost-server/v6/testlib"
|
"github.com/mattermost/mattermost-server/v6/testlib"
|
||||||
@@ -1428,14 +1429,16 @@ func TestPushNotificationRace(t *testing.T) {
|
|||||||
Return(&model.Preference{Value: "test"}, nil)
|
Return(&model.Preference{Value: "test"}, nil)
|
||||||
mockStore.On("Preference").Return(&mockPreferenceStore)
|
mockStore.On("Preference").Return(&mockPreferenceStore)
|
||||||
s := &Server{
|
s := &Server{
|
||||||
Store: mockStore,
|
Store: mockStore,
|
||||||
products: make(map[string]Product),
|
products: make(map[string]Product),
|
||||||
Router: mux.NewRouter(),
|
Router: mux.NewRouter(),
|
||||||
|
filestore: &fmocks.FileBackend{},
|
||||||
}
|
}
|
||||||
s.configStore = &configWrapper{srv: s, Store: memoryStore}
|
s.configStore = &configWrapper{srv: s, Store: memoryStore}
|
||||||
serviceMap := map[ServiceKey]interface{}{
|
serviceMap := map[ServiceKey]interface{}{
|
||||||
ConfigKey: s.configStore,
|
ConfigKey: s.configStore,
|
||||||
LicenseKey: &licenseWrapper{s},
|
LicenseKey: &licenseWrapper{s},
|
||||||
|
FilestoreKey: s.filestore,
|
||||||
}
|
}
|
||||||
ch, err := NewChannels(s, serviceMap)
|
ch, err := NewChannels(s, serviceMap)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v6/config"
|
"github.com/mattermost/mattermost-server/v6/config"
|
||||||
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
"github.com/mattermost/mattermost-server/v6/einterfaces"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"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/shared/mlog"
|
||||||
"github.com/mattermost/mattermost-server/v6/store"
|
"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 {
|
func RunEssentialJobs(s *Server) error {
|
||||||
s.runEssentialJobs = true
|
s.runEssentialJobs = true
|
||||||
|
|
||||||
|
|||||||
@@ -89,8 +89,9 @@ var SentryDSN = "placeholder_sentry_dsn"
|
|||||||
type ServiceKey string
|
type ServiceKey string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ConfigKey ServiceKey = "config"
|
ConfigKey ServiceKey = "config"
|
||||||
LicenseKey ServiceKey = "license"
|
LicenseKey ServiceKey = "license"
|
||||||
|
FilestoreKey ServiceKey = "filestore"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
@@ -362,8 +363,9 @@ func NewServer(options ...Option) (*Server, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serviceMap := map[ServiceKey]interface{}{
|
serviceMap := map[ServiceKey]interface{}{
|
||||||
ConfigKey: s.configStore,
|
ConfigKey: s.configStore,
|
||||||
LicenseKey: s.licenseWrapper,
|
LicenseKey: s.licenseWrapper,
|
||||||
|
FilestoreKey: s.filestore,
|
||||||
}
|
}
|
||||||
// Step 8: Initialize products.
|
// Step 8: Initialize products.
|
||||||
// Depends on s.httpService.
|
// Depends on s.httpService.
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user