mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-05 14:50:29 +02:00
Refactor App lifecycle (#590)
* remove Server dep from App * remove appbuilder
This commit is contained in:
parent
ddfae3266a
commit
edc3eb7e8f
@ -41,7 +41,7 @@ func (a *API) handleAdminSetPassword(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = a.app().UpdateUserPassword(username, requestData.Password)
|
err = a.app.UpdateUserPassword(username, requestData.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
|
@ -35,7 +35,7 @@ const (
|
|||||||
// REST APIs
|
// REST APIs
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
appBuilder func() *app.App
|
app *app.App
|
||||||
authService string
|
authService string
|
||||||
singleUserToken string
|
singleUserToken string
|
||||||
MattermostAuth bool
|
MattermostAuth bool
|
||||||
@ -43,9 +43,9 @@ type API struct {
|
|||||||
audit *audit.Audit
|
audit *audit.Audit
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAPI(appBuilder func() *app.App, singleUserToken string, authService string, logger *mlog.Logger, audit *audit.Audit) *API {
|
func NewAPI(app *app.App, singleUserToken string, authService string, logger *mlog.Logger, audit *audit.Audit) *API {
|
||||||
return &API{
|
return &API{
|
||||||
appBuilder: appBuilder,
|
app: app,
|
||||||
singleUserToken: singleUserToken,
|
singleUserToken: singleUserToken,
|
||||||
authService: authService,
|
authService: authService,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
@ -53,10 +53,6 @@ func NewAPI(appBuilder func() *app.App, singleUserToken string, authService stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) app() *app.App {
|
|
||||||
return a.appBuilder()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *API) RegisterRoutes(r *mux.Router) {
|
func (a *API) RegisterRoutes(r *mux.Router) {
|
||||||
apiv1 := r.PathPrefix("/api/v1").Subrouter()
|
apiv1 := r.PathPrefix("/api/v1").Subrouter()
|
||||||
apiv1.Use(a.requireCSRFToken)
|
apiv1.Use(a.requireCSRFToken)
|
||||||
@ -126,7 +122,7 @@ func (a *API) hasValidReadTokenForBlock(r *http.Request, container store.Contain
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
isValid, err := a.app().IsValidReadToken(container, blockID, readToken)
|
isValid, err := a.app.IsValidReadToken(container, blockID, readToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.logger.Error("IsValidReadToken ERROR", mlog.Err(err))
|
a.logger.Error("IsValidReadToken ERROR", mlog.Err(err))
|
||||||
return false
|
return false
|
||||||
@ -153,7 +149,7 @@ func (a *API) getContainerAllowingReadTokenForBlock(r *http.Request, blockID str
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Has session and access to workspace
|
// Has session and access to workspace
|
||||||
if session != nil && a.app().DoesUserHaveWorkspaceAccess(session.UserID, container.WorkspaceID) {
|
if session != nil && a.app.DoesUserHaveWorkspaceAccess(session.UserID, container.WorkspaceID) {
|
||||||
return &container, nil
|
return &container, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +235,7 @@ func (a *API) handleGetBlocks(w http.ResponseWriter, r *http.Request) {
|
|||||||
auditRec.AddMeta("parentID", parentID)
|
auditRec.AddMeta("parentID", parentID)
|
||||||
auditRec.AddMeta("blockType", blockType)
|
auditRec.AddMeta("blockType", blockType)
|
||||||
|
|
||||||
blocks, err := a.app().GetBlocks(*container, parentID, blockType)
|
blocks, err := a.app.GetBlocks(*container, parentID, blockType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -358,7 +354,7 @@ func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
stampModifiedByUser(r, blocks, auditRec)
|
stampModifiedByUser(r, blocks, auditRec)
|
||||||
|
|
||||||
err = a.app().InsertBlocks(*container, blocks)
|
err = a.app.InsertBlocks(*container, blocks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -404,7 +400,7 @@ func (a *API) handleGetUser(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||||
auditRec.AddMeta("userID", userID)
|
auditRec.AddMeta("userID", userID)
|
||||||
|
|
||||||
user, err := a.app().GetUser(userID)
|
user, err := a.app.GetUser(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -458,7 +454,7 @@ func (a *API) handleGetMe(w http.ResponseWriter, r *http.Request) {
|
|||||||
UpdateAt: now,
|
UpdateAt: now,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
user, err = a.app().GetUser(session.UserID)
|
user, err = a.app.GetUser(session.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -523,7 +519,7 @@ func (a *API) handleDeleteBlock(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||||
auditRec.AddMeta("blockID", blockID)
|
auditRec.AddMeta("blockID", blockID)
|
||||||
|
|
||||||
err = a.app().DeleteBlock(*container, blockID, userID)
|
err = a.app.DeleteBlock(*container, blockID, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -600,7 +596,7 @@ func (a *API) handleGetSubTree(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||||
auditRec.AddMeta("blockID", blockID)
|
auditRec.AddMeta("blockID", blockID)
|
||||||
|
|
||||||
blocks, err := a.app().GetSubTree(*container, blockID, int(levels))
|
blocks, err := a.app.GetSubTree(*container, blockID, int(levels))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -665,9 +661,9 @@ func (a *API) handleExport(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
blocks := []model.Block{}
|
blocks := []model.Block{}
|
||||||
if rootID == "" {
|
if rootID == "" {
|
||||||
blocks, err = a.app().GetAllBlocks(*container)
|
blocks, err = a.app.GetAllBlocks(*container)
|
||||||
} else {
|
} else {
|
||||||
blocks, err = a.app().GetBlocksWithRootID(*container, rootID)
|
blocks, err = a.app.GetBlocksWithRootID(*container, rootID)
|
||||||
}
|
}
|
||||||
|
|
||||||
a.logger.Debug("raw blocks", mlog.Int("block_count", len(blocks)))
|
a.logger.Debug("raw blocks", mlog.Int("block_count", len(blocks)))
|
||||||
@ -790,7 +786,7 @@ func (a *API) handleImport(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
stampModifiedByUser(r, blocks, auditRec)
|
stampModifiedByUser(r, blocks, auditRec)
|
||||||
|
|
||||||
err = a.app().InsertBlocks(*container, blocks)
|
err = a.app.InsertBlocks(*container, blocks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -849,7 +845,7 @@ func (a *API) handleGetSharing(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||||
auditRec.AddMeta("rootID", rootID)
|
auditRec.AddMeta("rootID", rootID)
|
||||||
|
|
||||||
sharing, err := a.app().GetSharing(*container, rootID)
|
sharing, err := a.app.GetSharing(*container, rootID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -945,7 +941,7 @@ func (a *API) handlePostSharing(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
sharing.ModifiedBy = userID
|
sharing.ModifiedBy = userID
|
||||||
|
|
||||||
err = a.app().UpsertSharing(*container, sharing)
|
err = a.app.UpsertSharing(*container, sharing)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -994,12 +990,12 @@ func (a *API) handleGetWorkspace(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
session := ctx.Value("session").(*model.Session)
|
session := ctx.Value("session").(*model.Session)
|
||||||
if !a.app().DoesUserHaveWorkspaceAccess(session.UserID, workspaceID) {
|
if !a.app.DoesUserHaveWorkspaceAccess(session.UserID, workspaceID) {
|
||||||
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
workspace, err = a.app().GetWorkspace(workspaceID)
|
workspace, err = a.app.GetWorkspace(workspaceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
}
|
}
|
||||||
@ -1008,7 +1004,7 @@ func (a *API) handleGetWorkspace(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
workspace, err = a.app().GetRootWorkspace()
|
workspace, err = a.app.GetRootWorkspace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -1053,7 +1049,7 @@ func (a *API) handlePostWorkspaceRegenerateSignupToken(w http.ResponseWriter, r
|
|||||||
// schema:
|
// schema:
|
||||||
// "$ref": "#/definitions/ErrorResponse"
|
// "$ref": "#/definitions/ErrorResponse"
|
||||||
|
|
||||||
workspace, err := a.app().GetRootWorkspace()
|
workspace, err := a.app.GetRootWorkspace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -1064,7 +1060,7 @@ func (a *API) handlePostWorkspaceRegenerateSignupToken(w http.ResponseWriter, r
|
|||||||
|
|
||||||
workspace.SignupToken = utils.CreateGUID()
|
workspace.SignupToken = utils.CreateGUID()
|
||||||
|
|
||||||
err = a.app().UpsertWorkspaceSignupToken(*workspace)
|
err = a.app.UpsertWorkspaceSignupToken(*workspace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -1138,7 +1134,7 @@ func (a *API) handleServeFile(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Header().Set("Content-Type", contentType)
|
w.Header().Set("Content-Type", contentType)
|
||||||
|
|
||||||
fileReader, err := a.app().GetFileReader(workspaceID, rootID, filename)
|
fileReader, err := a.app.GetFileReader(workspaceID, rootID, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -1217,7 +1213,7 @@ func (a *API) handleUploadFile(w http.ResponseWriter, r *http.Request) {
|
|||||||
auditRec.AddMeta("rootID", rootID)
|
auditRec.AddMeta("rootID", rootID)
|
||||||
auditRec.AddMeta("filename", handle.Filename)
|
auditRec.AddMeta("filename", handle.Filename)
|
||||||
|
|
||||||
fileId, err := a.app().SaveFile(file, workspaceID, rootID, handle.Filename)
|
fileId, err := a.app.SaveFile(file, workspaceID, rootID, handle.Filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -1272,7 +1268,7 @@ func (a *API) getWorkspaceUsers(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
session := ctx.Value("session").(*model.Session)
|
session := ctx.Value("session").(*model.Session)
|
||||||
if !a.app().DoesUserHaveWorkspaceAccess(session.UserID, workspaceID) {
|
if !a.app.DoesUserHaveWorkspaceAccess(session.UserID, workspaceID) {
|
||||||
a.errorResponse(w, http.StatusForbidden, "Access denied to workspace", errors.New("Access denied to workspace"))
|
a.errorResponse(w, http.StatusForbidden, "Access denied to workspace", errors.New("Access denied to workspace"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1280,7 +1276,7 @@ func (a *API) getWorkspaceUsers(w http.ResponseWriter, r *http.Request) {
|
|||||||
auditRec := a.makeAuditRecord(r, "getUsers", audit.Fail)
|
auditRec := a.makeAuditRecord(r, "getUsers", audit.Fail)
|
||||||
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
defer a.audit.LogRecord(audit.LevelRead, auditRec)
|
||||||
|
|
||||||
users, err := a.app().GetWorkspaceUsers(workspaceID)
|
users, err := a.app.GetWorkspaceUsers(workspaceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
|
@ -178,7 +178,7 @@ func (a *API) handleLogin(w http.ResponseWriter, r *http.Request) {
|
|||||||
auditRec.AddMeta("type", loginData.Type)
|
auditRec.AddMeta("type", loginData.Type)
|
||||||
|
|
||||||
if loginData.Type == "normal" {
|
if loginData.Type == "normal" {
|
||||||
token, err := a.app().Login(loginData.Username, loginData.Email, loginData.Password, loginData.MfaToken)
|
token, err := a.app.Login(loginData.Username, loginData.Email, loginData.Password, loginData.MfaToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusUnauthorized, "incorrect login", err)
|
a.errorResponse(w, http.StatusUnauthorized, "incorrect login", err)
|
||||||
return
|
return
|
||||||
@ -243,7 +243,7 @@ func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Validate token
|
// Validate token
|
||||||
if len(registerData.Token) > 0 {
|
if len(registerData.Token) > 0 {
|
||||||
workspace, err := a.app().GetRootWorkspace()
|
workspace, err := a.app.GetRootWorkspace()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -255,7 +255,7 @@ func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No signup token, check if no active users
|
// No signup token, check if no active users
|
||||||
userCount, err := a.app().GetRegisteredUserCount()
|
userCount, err := a.app.GetRegisteredUserCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||||
return
|
return
|
||||||
@ -275,7 +275,7 @@ func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
|
|||||||
defer a.audit.LogRecord(audit.LevelAuth, auditRec)
|
defer a.audit.LogRecord(audit.LevelAuth, auditRec)
|
||||||
auditRec.AddMeta("username", registerData.Username)
|
auditRec.AddMeta("username", registerData.Username)
|
||||||
|
|
||||||
err = a.app().RegisterUser(registerData.Username, registerData.Email, registerData.Password)
|
err = a.app.RegisterUser(registerData.Username, registerData.Email, registerData.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.errorResponse(w, http.StatusBadRequest, err.Error(), err)
|
a.errorResponse(w, http.StatusBadRequest, err.Error(), err)
|
||||||
return
|
return
|
||||||
@ -348,7 +348,7 @@ func (a *API) handleChangePassword(w http.ResponseWriter, r *http.Request) {
|
|||||||
auditRec := a.makeAuditRecord(r, "changePassword", audit.Fail)
|
auditRec := a.makeAuditRecord(r, "changePassword", audit.Fail)
|
||||||
defer a.audit.LogRecord(audit.LevelAuth, auditRec)
|
defer a.audit.LogRecord(audit.LevelAuth, auditRec)
|
||||||
|
|
||||||
if err = a.app().ChangePassword(userID, requestData.OldPassword, requestData.NewPassword); err != nil {
|
if err = a.app.ChangePassword(userID, requestData.OldPassword, requestData.NewPassword); err != nil {
|
||||||
a.errorResponse(w, http.StatusBadRequest, err.Error(), err)
|
a.errorResponse(w, http.StatusBadRequest, err.Error(), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -404,7 +404,7 @@ func (a *API) attachSession(handler func(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
session, err := a.app().GetSession(token)
|
session, err := a.app.GetSession(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if required {
|
if required {
|
||||||
a.errorResponse(w, http.StatusUnauthorized, "", err)
|
a.errorResponse(w, http.StatusUnauthorized, "", err)
|
||||||
|
@ -2,16 +2,21 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mattermost/focalboard/server/auth"
|
"github.com/mattermost/focalboard/server/auth"
|
||||||
|
"github.com/mattermost/focalboard/server/model"
|
||||||
"github.com/mattermost/focalboard/server/services/config"
|
"github.com/mattermost/focalboard/server/services/config"
|
||||||
"github.com/mattermost/focalboard/server/services/metrics"
|
"github.com/mattermost/focalboard/server/services/metrics"
|
||||||
"github.com/mattermost/focalboard/server/services/mlog"
|
"github.com/mattermost/focalboard/server/services/mlog"
|
||||||
"github.com/mattermost/focalboard/server/services/store"
|
"github.com/mattermost/focalboard/server/services/store"
|
||||||
"github.com/mattermost/focalboard/server/services/webhook"
|
"github.com/mattermost/focalboard/server/services/webhook"
|
||||||
"github.com/mattermost/focalboard/server/ws"
|
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v5/shared/filestore"
|
"github.com/mattermost/mattermost-server/v5/shared/filestore"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type WebsocketServer interface {
|
||||||
|
BroadcastBlockChange(workspaceID string, block model.Block)
|
||||||
|
BroadcastBlockDelete(workspaceID, blockID, parentID string)
|
||||||
|
}
|
||||||
|
|
||||||
type Services struct {
|
type Services struct {
|
||||||
Auth *auth.Auth
|
Auth *auth.Auth
|
||||||
Store store.Store
|
Store store.Store
|
||||||
@ -25,14 +30,14 @@ type App struct {
|
|||||||
config *config.Configuration
|
config *config.Configuration
|
||||||
store store.Store
|
store store.Store
|
||||||
auth *auth.Auth
|
auth *auth.Auth
|
||||||
wsServer *ws.Server
|
wsServer WebsocketServer
|
||||||
filesBackend filestore.FileBackend
|
filesBackend filestore.FileBackend
|
||||||
webhook *webhook.Client
|
webhook *webhook.Client
|
||||||
metrics *metrics.Metrics
|
metrics *metrics.Metrics
|
||||||
logger *mlog.Logger
|
logger *mlog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(config *config.Configuration, wsServer *ws.Server, services Services) *App {
|
func New(config *config.Configuration, wsServer WebsocketServer, services Services) *App {
|
||||||
return &App{
|
return &App{
|
||||||
config: config,
|
config: config,
|
||||||
store: services.Store,
|
store: services.Store,
|
||||||
|
@ -63,7 +63,6 @@ type Server struct {
|
|||||||
localRouter *mux.Router
|
localRouter *mux.Router
|
||||||
localModeServer *http.Server
|
localModeServer *http.Server
|
||||||
api *api.API
|
api *api.API
|
||||||
appBuilder func() *app.App
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *config.Configuration, singleUserToken string, logger *mlog.Logger) (*Server, error) {
|
func New(cfg *config.Configuration, singleUserToken string, logger *mlog.Logger) (*Server, error) {
|
||||||
@ -132,16 +131,16 @@ func New(cfg *config.Configuration, singleUserToken string, logger *mlog.Logger)
|
|||||||
Metrics: metricsService,
|
Metrics: metricsService,
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
}
|
}
|
||||||
appBuilder := func() *app.App { return app.New(cfg, wsServer, appServices) }
|
app := app.New(cfg, wsServer, appServices)
|
||||||
|
|
||||||
focalboardAPI := api.NewAPI(appBuilder, singleUserToken, cfg.AuthMode, logger, auditService)
|
focalboardAPI := api.NewAPI(app, singleUserToken, cfg.AuthMode, logger, auditService)
|
||||||
|
|
||||||
// Local router for admin APIs
|
// Local router for admin APIs
|
||||||
localRouter := mux.NewRouter()
|
localRouter := mux.NewRouter()
|
||||||
focalboardAPI.RegisterAdminRoutes(localRouter)
|
focalboardAPI.RegisterAdminRoutes(localRouter)
|
||||||
|
|
||||||
// Init workspace
|
// Init workspace
|
||||||
if _, err = appBuilder().GetRootWorkspace(); err != nil {
|
if _, err = app.GetRootWorkspace(); err != nil {
|
||||||
logger.Error("Unable to get root workspace", mlog.Err(err))
|
logger.Error("Unable to get root workspace", mlog.Err(err))
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -164,7 +163,7 @@ func New(cfg *config.Configuration, singleUserToken string, logger *mlog.Logger)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
telemetryOpts := telemetryOptions{
|
telemetryOpts := telemetryOptions{
|
||||||
appBuilder: appBuilder,
|
app: app,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
telemetryID: telemetryID,
|
telemetryID: telemetryID,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
@ -185,7 +184,6 @@ func New(cfg *config.Configuration, singleUserToken string, logger *mlog.Logger)
|
|||||||
logger: logger,
|
logger: logger,
|
||||||
localRouter: localRouter,
|
localRouter: localRouter,
|
||||||
api: focalboardAPI,
|
api: focalboardAPI,
|
||||||
appBuilder: appBuilder,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
server.initHandlers()
|
server.initHandlers()
|
||||||
@ -219,8 +217,7 @@ func (s *Server) Start() error {
|
|||||||
}, cleanupSessionTaskFrequency)
|
}, cleanupSessionTaskFrequency)
|
||||||
|
|
||||||
metricsUpdater := func() {
|
metricsUpdater := func() {
|
||||||
app := s.appBuilder()
|
blockCounts, err := s.store.GetBlockCountsByType()
|
||||||
blockCounts, err := app.GetBlockCountsByType()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Error updating metrics", mlog.String("group", "blocks"), mlog.Err(err))
|
s.logger.Error("Error updating metrics", mlog.String("group", "blocks"), mlog.Err(err))
|
||||||
return
|
return
|
||||||
@ -229,7 +226,7 @@ func (s *Server) Start() error {
|
|||||||
for blockType, count := range blockCounts {
|
for blockType, count := range blockCounts {
|
||||||
s.metricsService.ObserveBlockCount(blockType, count)
|
s.metricsService.ObserveBlockCount(blockType, count)
|
||||||
}
|
}
|
||||||
workspaceCount, err := app.GetWorkspaceCount()
|
workspaceCount, err := s.store.GetWorkspaceCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Error updating metrics", mlog.String("group", "workspaces"), mlog.Err(err))
|
s.logger.Error("Error updating metrics", mlog.String("group", "workspaces"), mlog.Err(err))
|
||||||
return
|
return
|
||||||
@ -351,7 +348,7 @@ func (s *Server) SetWSHub(hub ws.Hub) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type telemetryOptions struct {
|
type telemetryOptions struct {
|
||||||
appBuilder func() *app.App
|
app *app.App
|
||||||
cfg *config.Configuration
|
cfg *config.Configuration
|
||||||
telemetryID string
|
telemetryID string
|
||||||
logger *mlog.Logger
|
logger *mlog.Logger
|
||||||
@ -383,29 +380,29 @@ func initTelemetry(opts telemetryOptions) *telemetry.Service {
|
|||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
var count int
|
var count int
|
||||||
var err error
|
var err error
|
||||||
if count, err = opts.appBuilder().GetRegisteredUserCount(); err != nil {
|
if count, err = opts.app.GetRegisteredUserCount(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m["registered_users"] = count
|
m["registered_users"] = count
|
||||||
|
|
||||||
if count, err = opts.appBuilder().GetDailyActiveUsers(); err != nil {
|
if count, err = opts.app.GetDailyActiveUsers(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m["daily_active_users"] = count
|
m["daily_active_users"] = count
|
||||||
|
|
||||||
if count, err = opts.appBuilder().GetWeeklyActiveUsers(); err != nil {
|
if count, err = opts.app.GetWeeklyActiveUsers(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m["weekly_active_users"] = count
|
m["weekly_active_users"] = count
|
||||||
|
|
||||||
if count, err = opts.appBuilder().GetMonthlyActiveUsers(); err != nil {
|
if count, err = opts.app.GetMonthlyActiveUsers(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
m["monthly_active_users"] = count
|
m["monthly_active_users"] = count
|
||||||
return m, nil
|
return m, nil
|
||||||
})
|
})
|
||||||
telemetryService.RegisterTracker("blocks", func() (telemetry.Tracker, error) {
|
telemetryService.RegisterTracker("blocks", func() (telemetry.Tracker, error) {
|
||||||
blockCounts, err := opts.appBuilder().GetBlockCountsByType()
|
blockCounts, err := opts.app.GetBlockCountsByType()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -416,7 +413,7 @@ func initTelemetry(opts telemetryOptions) *telemetry.Service {
|
|||||||
return m, nil
|
return m, nil
|
||||||
})
|
})
|
||||||
telemetryService.RegisterTracker("workspaces", func() (telemetry.Tracker, error) {
|
telemetryService.RegisterTracker("workspaces", func() (telemetry.Tracker, error) {
|
||||||
count, err := opts.appBuilder().GetWorkspaceCount()
|
count, err := opts.app.GetWorkspaceCount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user