f1b8d88d6b
* Improving mattermost auth implementation * Making mattermost-auth based on shared database access * Reverting unneeded changes in the config.json file * Fixing tiny problems * Removing the need of using the mattermost session token * Fixing some bugs and allowing to not-bind the server to any port * Small fix to correctly get the templates * Adding the mattermost-plugin code inside focalboard repo * Adding a not working code part of the cluster websocket communication * Updating the mattermost version * Adding the cluster messages for the websockets * Updating to the new node version * Making it compatible with S3 * Addressing some tiny problems * Fixing server tests * Adds support for MySQL migrations and initialization Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"database/sql"
|
|
"log"
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
"github.com/mattermost/focalboard/server/utils"
|
|
)
|
|
|
|
func (a *App) GetRootWorkspace() (*model.Workspace, error) {
|
|
workspaceID := "0"
|
|
workspace, _ := a.store.GetWorkspace(workspaceID)
|
|
if workspace == nil {
|
|
workspace = &model.Workspace{
|
|
ID: workspaceID,
|
|
SignupToken: utils.CreateGUID(),
|
|
}
|
|
err := a.store.UpsertWorkspaceSignupToken(*workspace)
|
|
if err != nil {
|
|
log.Fatal("Unable to initialize workspace", err)
|
|
return nil, err
|
|
}
|
|
workspace, err = a.store.GetWorkspace(workspaceID)
|
|
if err != nil {
|
|
log.Fatal("Unable to get initialized workspace", err)
|
|
return nil, err
|
|
}
|
|
|
|
log.Println("initialized workspace")
|
|
}
|
|
|
|
return workspace, nil
|
|
}
|
|
|
|
func (a *App) GetWorkspace(ID string) (*model.Workspace, error) {
|
|
workspace, err := a.store.GetWorkspace(ID)
|
|
if err == sql.ErrNoRows {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return workspace, nil
|
|
}
|
|
|
|
func (a *App) DoesUserHaveWorkspaceAccess(userID string, workspaceID string) bool {
|
|
return a.auth.DoesUserHaveWorkspaceAccess(userID, workspaceID)
|
|
}
|
|
|
|
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)
|
|
}
|