teams.go
TLDR
This file contains a Go package named app
that includes several methods related to teams in a project. The methods in this file allow retrieving, updating, and managing team-related data.
Methods
GetRootTeam
This method retrieves the root team of the project. It initializes the team if it does not exist and returns the team object.
GetTeam
This method retrieves a specific team by its ID. It returns the team object if found, or nil
if the team does not exist.
GetTeamsForUser
This method retrieves all the teams that a user belongs to. It returns an array of team objects.
DoesUserHaveTeamAccess
This method determines if a user has access to a specific team. It takes the user ID and team ID as parameters and returns a boolean indicating whether the user has access.
UpsertTeamSettings
This method updates or inserts team settings. It takes a team object as a parameter and returns an error if the operation fails.
UpsertTeamSignupToken
This method updates or inserts the sign-up token for a team. It takes a team object as a parameter and returns an error if the operation fails.
GetTeamCount
This method retrieves the total number of teams in the project. It returns the count as an integer.
package app
import (
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/utils"
"github.com/mattermost/mattermost-server/v6/shared/mlog"
)
func (a *App) GetRootTeam() (*model.Team, error) {
teamID := "0"
team, _ := a.store.GetTeam(teamID)
if team == nil {
team = &model.Team{
ID: teamID,
SignupToken: utils.NewID(utils.IDTypeToken),
}
err := a.store.UpsertTeamSignupToken(*team)
if err != nil {
a.logger.Error("Unable to initialize team", mlog.Err(err))
return nil, err
}
team, err = a.store.GetTeam(teamID)
if err != nil {
a.logger.Error("Unable to get initialized team", mlog.Err(err))
return nil, err
}
a.logger.Info("initialized team")
}
return team, nil
}
func (a *App) GetTeam(id string) (*model.Team, error) {
team, err := a.store.GetTeam(id)
if model.IsErrNotFound(err) {
return nil, nil
}
if err != nil {
return nil, err
}
return team, nil
}
func (a *App) GetTeamsForUser(userID string) ([]*model.Team, error) {
return a.store.GetTeamsForUser(userID)
}
func (a *App) DoesUserHaveTeamAccess(userID string, teamID string) bool {
return a.auth.DoesUserHaveTeamAccess(userID, teamID)
}
func (a *App) UpsertTeamSettings(team model.Team) error {
return a.store.UpsertTeamSettings(team)
}
func (a *App) UpsertTeamSignupToken(team model.Team) error {
return a.store.UpsertTeamSignupToken(team)
}
func (a *App) GetTeamCount() (int64, error) {
return a.store.GetTeamCount()
}