2020-10-16 19:12:53 +02:00
|
|
|
package app
|
2020-10-16 16:21:42 +02:00
|
|
|
|
2020-10-16 16:36:08 +02:00
|
|
|
import (
|
2022-07-18 19:21:57 +02:00
|
|
|
"io"
|
2022-06-15 12:17:44 +02:00
|
|
|
"sync"
|
2022-03-22 16:24:34 +02:00
|
|
|
"time"
|
|
|
|
|
2021-02-02 22:11:21 +02:00
|
|
|
"github.com/mattermost/focalboard/server/auth"
|
2021-01-27 00:13:46 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/config"
|
2021-06-04 16:38:49 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/metrics"
|
2021-09-13 21:36:36 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/notify"
|
2022-03-22 16:24:34 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/permissions"
|
2021-01-27 00:13:46 +02:00
|
|
|
"github.com/mattermost/focalboard/server/services/store"
|
|
|
|
"github.com/mattermost/focalboard/server/services/webhook"
|
2022-03-22 16:24:34 +02:00
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
2021-08-27 10:59:14 +02:00
|
|
|
"github.com/mattermost/focalboard/server/ws"
|
2021-05-29 08:23:10 +02:00
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
mm_model "github.com/mattermost/mattermost-server/v6/model"
|
2021-08-24 12:13:58 +02:00
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/filestore"
|
2022-06-15 12:17:44 +02:00
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
2020-10-16 16:36:08 +02:00
|
|
|
)
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
const (
|
2022-04-22 19:14:12 +02:00
|
|
|
blockChangeNotifierQueueSize = 1000
|
2022-03-22 16:24:34 +02:00
|
|
|
blockChangeNotifierPoolSize = 10
|
|
|
|
blockChangeNotifierShutdownTimeout = time.Second * 10
|
|
|
|
)
|
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
type servicesAPI interface {
|
|
|
|
GetUsersFromProfiles(options *mm_model.UserGetOptions) ([]*mm_model.User, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReadCloseSeeker = filestore.ReadCloseSeeker
|
|
|
|
|
|
|
|
type fileBackend interface {
|
|
|
|
Reader(path string) (ReadCloseSeeker, error)
|
|
|
|
FileExists(path string) (bool, error)
|
|
|
|
CopyFile(oldPath, newPath string) error
|
|
|
|
MoveFile(oldPath, newPath string) error
|
|
|
|
WriteFile(fr io.Reader, path string) (int64, error)
|
|
|
|
RemoveFile(path string) error
|
2022-06-15 12:17:44 +02:00
|
|
|
}
|
|
|
|
|
2021-06-11 14:24:51 +02:00
|
|
|
type Services struct {
|
2022-02-02 20:25:06 +02:00
|
|
|
Auth *auth.Auth
|
|
|
|
Store store.Store
|
2022-07-18 19:21:57 +02:00
|
|
|
FilesBackend fileBackend
|
2022-02-02 20:25:06 +02:00
|
|
|
Webhook *webhook.Client
|
|
|
|
Metrics *metrics.Metrics
|
|
|
|
Notifications *notify.Service
|
2022-07-18 19:21:57 +02:00
|
|
|
Logger mlog.LoggerIFace
|
2022-03-22 16:24:34 +02:00
|
|
|
Permissions permissions.PermissionsService
|
2022-02-02 20:25:06 +02:00
|
|
|
SkipTemplateInit bool
|
2022-07-18 19:21:57 +02:00
|
|
|
ServicesAPI servicesAPI
|
2021-06-04 16:38:49 +02:00
|
|
|
}
|
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
type App struct {
|
2022-03-22 16:24:34 +02:00
|
|
|
config *config.Configuration
|
|
|
|
store store.Store
|
|
|
|
auth *auth.Auth
|
|
|
|
wsAdapter ws.Adapter
|
2022-07-18 19:21:57 +02:00
|
|
|
filesBackend fileBackend
|
2022-03-22 16:24:34 +02:00
|
|
|
webhook *webhook.Client
|
|
|
|
metrics *metrics.Metrics
|
|
|
|
notifications *notify.Service
|
2022-07-18 19:21:57 +02:00
|
|
|
logger mlog.LoggerIFace
|
2022-12-23 17:47:51 +02:00
|
|
|
permissions permissions.PermissionsService
|
2022-03-22 16:24:34 +02:00
|
|
|
blockChangeNotifier *utils.CallbackQueue
|
2022-07-18 19:21:57 +02:00
|
|
|
servicesAPI servicesAPI
|
2022-06-15 12:17:44 +02:00
|
|
|
|
|
|
|
cardLimitMux sync.RWMutex
|
|
|
|
cardLimit int
|
2020-10-16 19:12:53 +02:00
|
|
|
}
|
|
|
|
|
2021-09-16 21:31:02 +02:00
|
|
|
func (a *App) SetConfig(config *config.Configuration) {
|
|
|
|
a.config = config
|
|
|
|
}
|
|
|
|
|
2022-03-29 13:09:39 +02:00
|
|
|
func (a *App) GetConfig() *config.Configuration {
|
|
|
|
return a.config
|
|
|
|
}
|
|
|
|
|
2021-08-27 10:59:14 +02:00
|
|
|
func New(config *config.Configuration, wsAdapter ws.Adapter, services Services) *App {
|
2022-02-02 20:25:06 +02:00
|
|
|
app := &App{
|
2022-03-22 16:24:34 +02:00
|
|
|
config: config,
|
|
|
|
store: services.Store,
|
|
|
|
auth: services.Auth,
|
|
|
|
wsAdapter: wsAdapter,
|
|
|
|
filesBackend: services.FilesBackend,
|
|
|
|
webhook: services.Webhook,
|
|
|
|
metrics: services.Metrics,
|
|
|
|
notifications: services.Notifications,
|
|
|
|
logger: services.Logger,
|
2022-12-23 17:47:51 +02:00
|
|
|
permissions: services.Permissions,
|
2022-03-22 16:24:34 +02:00
|
|
|
blockChangeNotifier: utils.NewCallbackQueue("blockChangeNotifier", blockChangeNotifierQueueSize, blockChangeNotifierPoolSize, services.Logger),
|
2022-07-18 19:21:57 +02:00
|
|
|
servicesAPI: services.ServicesAPI,
|
2021-02-02 22:11:21 +02:00
|
|
|
}
|
2022-02-02 20:25:06 +02:00
|
|
|
app.initialize(services.SkipTemplateInit)
|
|
|
|
return app
|
2020-10-16 16:21:42 +02:00
|
|
|
}
|
2022-06-15 12:17:44 +02:00
|
|
|
|
|
|
|
func (a *App) CardLimit() int {
|
|
|
|
a.cardLimitMux.RLock()
|
|
|
|
defer a.cardLimitMux.RUnlock()
|
|
|
|
return a.cardLimit
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) SetCardLimit(cardLimit int) {
|
|
|
|
a.cardLimitMux.Lock()
|
|
|
|
defer a.cardLimitMux.Unlock()
|
|
|
|
a.cardLimit = cardLimit
|
|
|
|
}
|
2022-11-30 23:49:16 +02:00
|
|
|
|
|
|
|
func (a *App) GetLicense() *mm_model.License {
|
|
|
|
return a.store.GetLicense()
|
|
|
|
}
|