2021-01-14 01:56:01 +01:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2021-06-21 11:21:42 +02:00
|
|
|
"errors"
|
2021-01-14 01:56:01 +01:00
|
|
|
|
2021-01-26 23:13:46 +01:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
2021-08-25 22:08:01 +02:00
|
|
|
|
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
2021-01-14 01:56:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func (a *App) GetRootWorkspace() (*model.Workspace, error) {
|
|
|
|
workspaceID := "0"
|
|
|
|
workspace, _ := a.store.GetWorkspace(workspaceID)
|
|
|
|
if workspace == nil {
|
|
|
|
workspace = &model.Workspace{
|
|
|
|
ID: workspaceID,
|
2021-10-05 15:52:59 +02:00
|
|
|
SignupToken: utils.NewID(utils.IDTypeToken),
|
2021-01-14 01:56:01 +01:00
|
|
|
}
|
|
|
|
err := a.store.UpsertWorkspaceSignupToken(*workspace)
|
|
|
|
if err != nil {
|
2021-11-22 07:46:51 +01:00
|
|
|
a.logger.Error("Unable to initialize workspace", mlog.Err(err))
|
2021-01-14 01:56:01 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
workspace, err = a.store.GetWorkspace(workspaceID)
|
|
|
|
if err != nil {
|
2021-11-22 07:46:51 +01:00
|
|
|
a.logger.Error("Unable to get initialized workspace", mlog.Err(err))
|
2021-01-14 01:56:01 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-05-29 08:23:10 +02:00
|
|
|
a.logger.Info("initialized workspace")
|
2021-01-14 01:56:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return workspace, nil
|
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:42 +02:00
|
|
|
func (a *App) GetWorkspace(id string) (*model.Workspace, error) {
|
|
|
|
workspace, err := a.store.GetWorkspace(id)
|
|
|
|
if errors.Is(err, sql.ErrNoRows) {
|
2021-01-14 01:56:01 +01:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return workspace, nil
|
|
|
|
}
|
|
|
|
|
2021-05-24 19:06:11 +02:00
|
|
|
func (a *App) DoesUserHaveWorkspaceAccess(userID string, workspaceID string) bool {
|
|
|
|
return a.auth.DoesUserHaveWorkspaceAccess(userID, workspaceID)
|
|
|
|
}
|
|
|
|
|
2021-01-14 01:56:01 +01:00
|
|
|
func (a *App) UpsertWorkspaceSettings(workspace model.Workspace) error {
|
|
|
|
return a.store.UpsertWorkspaceSettings(workspace)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) UpsertWorkspaceSignupToken(workspace model.Workspace) error {
|
|
|
|
return a.store.UpsertWorkspaceSignupToken(workspace)
|
|
|
|
}
|
2021-06-04 16:38:49 +02:00
|
|
|
|
|
|
|
func (a *App) GetWorkspaceCount() (int64, error) {
|
|
|
|
return a.store.GetWorkspaceCount()
|
|
|
|
}
|
2021-09-08 06:52:03 +02:00
|
|
|
|
|
|
|
func (a *App) GetUserWorkspaces(userID string) ([]model.UserWorkspace, error) {
|
|
|
|
return a.store.GetUserWorkspaces(userID)
|
|
|
|
}
|