2021-08-06 14:10:24 +02:00
|
|
|
//go:generate mockgen --build_flags=--mod=mod -destination=mockstore/mockstore.go -package mockstore . Store
|
2021-10-22 12:48:53 +02:00
|
|
|
//go:generate go run ./generators/main.go
|
2020-10-16 19:20:43 +02:00
|
|
|
package store
|
|
|
|
|
2021-12-03 18:32:57 +01:00
|
|
|
import (
|
2021-12-10 16:46:37 +01:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2021-12-03 18:32:57 +01:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
|
|
)
|
2020-10-16 19:20:43 +02:00
|
|
|
|
2020-10-22 15:22:36 +02:00
|
|
|
// Store represents the abstraction of the data storage.
|
2020-10-16 19:20:43 +02:00
|
|
|
type Store interface {
|
2022-03-22 15:24:34 +01:00
|
|
|
GetBlocksWithParentAndType(boardID, parentID string, blockType string) ([]model.Block, error)
|
|
|
|
GetBlocksWithParent(boardID, parentID string) ([]model.Block, error)
|
|
|
|
GetBlocksWithBoardID(boardID string) ([]model.Block, error)
|
|
|
|
GetBlocksWithType(boardID, blockType string) ([]model.Block, error)
|
|
|
|
GetSubTree2(boardID, blockID string, opts model.QuerySubtreeOptions) ([]model.Block, error)
|
|
|
|
GetSubTree3(boardID, blockID string, opts model.QuerySubtreeOptions) ([]model.Block, error)
|
|
|
|
GetBlocksForBoard(boardID string) ([]model.Block, error)
|
2021-10-22 12:48:53 +02:00
|
|
|
// @withTransaction
|
2022-03-22 15:24:34 +01:00
|
|
|
InsertBlock(block *model.Block, userID string) error
|
2021-10-22 12:48:53 +02:00
|
|
|
// @withTransaction
|
2022-03-22 15:24:34 +01:00
|
|
|
DeleteBlock(blockID string, modifiedBy string) error
|
2021-12-10 15:17:00 +01:00
|
|
|
// @withTransaction
|
2022-03-22 15:24:34 +01:00
|
|
|
InsertBlocks(blocks []model.Block, userID string) error
|
2022-02-22 18:42:49 +01:00
|
|
|
// @withTransaction
|
2022-03-22 15:24:34 +01:00
|
|
|
UndeleteBlock(blockID string, modifiedBy string) error
|
2021-06-04 16:38:49 +02:00
|
|
|
GetBlockCountsByType() (map[string]int64, error)
|
2022-03-22 15:24:34 +01:00
|
|
|
GetBlock(blockID string) (*model.Block, error)
|
|
|
|
// @withTransaction
|
|
|
|
PatchBlock(blockID string, blockPatch *model.BlockPatch, userID string) error
|
|
|
|
GetBlockHistory(blockID string, opts model.QueryBlockHistoryOptions) ([]model.Block, error)
|
|
|
|
GetBoardAndCardByID(blockID string) (board *model.Board, card *model.Block, err error)
|
|
|
|
GetBoardAndCard(block *model.Block) (board *model.Board, card *model.Block, err error)
|
2021-10-22 12:48:53 +02:00
|
|
|
// @withTransaction
|
2022-03-22 15:24:34 +01:00
|
|
|
DuplicateBoard(boardID string, userID string, toTeam string, asTemplate bool) (*model.BoardsAndBlocks, []*model.BoardMember, error)
|
2021-12-10 15:17:00 +01:00
|
|
|
// @withTransaction
|
2022-03-22 15:24:34 +01:00
|
|
|
DuplicateBlock(boardID string, blockID string, userID string, asTemplate bool) ([]model.Block, error)
|
|
|
|
// @withTransaction
|
|
|
|
PatchBlocks(blockPatches *model.BlockPatchBatch, userID string) error
|
2021-01-13 00:35:30 +01:00
|
|
|
|
2020-10-16 22:26:47 +02:00
|
|
|
Shutdown() error
|
2021-01-13 00:35:30 +01:00
|
|
|
|
2021-11-11 17:01:43 +01:00
|
|
|
GetSystemSetting(key string) (string, error)
|
2020-10-19 14:55:20 +02:00
|
|
|
GetSystemSettings() (map[string]string, error)
|
2021-03-21 09:28:26 +01:00
|
|
|
SetSystemSetting(key, value string) error
|
2021-01-13 00:35:30 +01:00
|
|
|
|
2021-01-27 18:22:33 +01:00
|
|
|
GetRegisteredUserCount() (int, error)
|
2021-06-21 11:21:42 +02:00
|
|
|
GetUserByID(userID string) (*model.User, error)
|
2020-11-06 16:46:35 +01:00
|
|
|
GetUserByEmail(email string) (*model.User, error)
|
|
|
|
GetUserByUsername(username string) (*model.User, error)
|
|
|
|
CreateUser(user *model.User) error
|
|
|
|
UpdateUser(user *model.User) error
|
2021-03-21 09:28:26 +01:00
|
|
|
UpdateUserPassword(username, password string) error
|
|
|
|
UpdateUserPasswordByID(userID, password string) error
|
2022-03-22 15:24:34 +01:00
|
|
|
GetUsersByTeam(teamID string) ([]*model.User, error)
|
|
|
|
SearchUsersByTeam(teamID string, searchQuery string) ([]*model.User, error)
|
2022-02-28 12:28:16 +01:00
|
|
|
PatchUserProps(userID string, patch model.UserPropPatch) error
|
2021-01-13 00:35:30 +01:00
|
|
|
|
2021-01-27 19:01:24 +01:00
|
|
|
GetActiveUserCount(updatedSecondsAgo int64) (int, error)
|
2020-12-07 17:04:35 +01:00
|
|
|
GetSession(token string, expireTime int64) (*model.Session, error)
|
2020-12-02 21:12:14 +01:00
|
|
|
CreateSession(session *model.Session) error
|
|
|
|
RefreshSession(session *model.Session) error
|
|
|
|
UpdateSession(session *model.Session) error
|
2021-06-21 11:21:42 +02:00
|
|
|
DeleteSession(sessionID string) error
|
2020-12-07 17:04:35 +01:00
|
|
|
CleanUpSessions(expireTime int64) error
|
2021-01-13 00:35:30 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
UpsertSharing(sharing model.Sharing) error
|
|
|
|
GetSharing(rootID string) (*model.Sharing, error)
|
|
|
|
|
|
|
|
UpsertTeamSignupToken(team model.Team) error
|
|
|
|
UpsertTeamSettings(team model.Team) error
|
|
|
|
GetTeam(ID string) (*model.Team, error)
|
|
|
|
GetTeamsForUser(userID string) ([]*model.Team, error)
|
|
|
|
GetAllTeams() ([]*model.Team, error)
|
|
|
|
GetTeamCount() (int64, error)
|
|
|
|
|
|
|
|
InsertBoard(board *model.Board, userID string) (*model.Board, error)
|
|
|
|
// @withTransaction
|
|
|
|
InsertBoardWithAdmin(board *model.Board, userID string) (*model.Board, *model.BoardMember, error)
|
|
|
|
// @withTransaction
|
|
|
|
PatchBoard(boardID string, boardPatch *model.BoardPatch, userID string) (*model.Board, error)
|
|
|
|
GetBoard(id string) (*model.Board, error)
|
|
|
|
GetBoardsForUserAndTeam(userID, teamID string) ([]*model.Board, error)
|
|
|
|
// @withTransaction
|
|
|
|
DeleteBoard(boardID, userID string) error
|
|
|
|
|
|
|
|
SaveMember(bm *model.BoardMember) (*model.BoardMember, error)
|
|
|
|
DeleteMember(boardID, userID string) error
|
|
|
|
GetMemberForBoard(boardID, userID string) (*model.BoardMember, error)
|
2022-03-29 10:17:19 +02:00
|
|
|
GetBoardMemberHistory(boardID, userID string, limit uint64) ([]*model.BoardMemberHistoryEntry, error)
|
2022-03-22 15:24:34 +01:00
|
|
|
GetMembersForBoard(boardID string) ([]*model.BoardMember, error)
|
|
|
|
GetMembersForUser(userID string) ([]*model.BoardMember, error)
|
|
|
|
SearchBoardsForUserAndTeam(term, userID, teamID string) ([]*model.Board, error)
|
|
|
|
|
|
|
|
// @withTransaction
|
|
|
|
CreateBoardsAndBlocksWithAdmin(bab *model.BoardsAndBlocks, userID string) (*model.BoardsAndBlocks, []*model.BoardMember, error)
|
|
|
|
// @withTransaction
|
|
|
|
CreateBoardsAndBlocks(bab *model.BoardsAndBlocks, userID string) (*model.BoardsAndBlocks, error)
|
|
|
|
// @withTransaction
|
|
|
|
PatchBoardsAndBlocks(pbab *model.PatchBoardsAndBlocks, userID string) (*model.BoardsAndBlocks, error)
|
|
|
|
// @withTransaction
|
|
|
|
DeleteBoardsAndBlocks(dbab *model.DeleteBoardsAndBlocks, userID string) error
|
|
|
|
|
|
|
|
GetCategory(id string) (*model.Category, error)
|
|
|
|
CreateCategory(category model.Category) error
|
|
|
|
UpdateCategory(category model.Category) error
|
|
|
|
DeleteCategory(categoryID, userID, teamID string) error
|
|
|
|
|
|
|
|
GetUserCategoryBlocks(userID, teamID string) ([]model.CategoryBlocks, error)
|
|
|
|
AddUpdateCategoryBlock(userID, categoryID, blockID string) error
|
|
|
|
|
|
|
|
CreateSubscription(sub *model.Subscription) (*model.Subscription, error)
|
|
|
|
DeleteSubscription(blockID string, subscriberID string) error
|
|
|
|
GetSubscription(blockID string, subscriberID string) (*model.Subscription, error)
|
|
|
|
GetSubscriptions(subscriberID string) ([]*model.Subscription, error)
|
|
|
|
GetSubscribersForBlock(blockID string) ([]*model.Subscriber, error)
|
|
|
|
GetSubscribersCountForBlock(blockID string) (int, error)
|
|
|
|
UpdateSubscribersNotifiedAt(blockID string, notifiedAt int64) error
|
2021-12-10 16:46:37 +01:00
|
|
|
|
|
|
|
UpsertNotificationHint(hint *model.NotificationHint, notificationFreq time.Duration) (*model.NotificationHint, error)
|
2022-03-22 15:24:34 +01:00
|
|
|
DeleteNotificationHint(blockID string) error
|
|
|
|
GetNotificationHint(blockID string) (*model.NotificationHint, error)
|
2021-12-10 16:46:37 +01:00
|
|
|
GetNextNotificationHint(remove bool) (*model.NotificationHint, error)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
RemoveDefaultTemplates(boards []*model.Board) error
|
|
|
|
GetTemplateBoards(teamID string) ([]*model.Board, error)
|
2022-02-01 19:36:12 +01:00
|
|
|
|
2022-02-22 22:30:47 +01:00
|
|
|
DBType() string
|
|
|
|
|
2021-12-10 16:46:37 +01:00
|
|
|
IsErrNotFound(err error) bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// ErrNotFound is an error type that can be returned by store APIs when a query unexpectedly fetches no records.
|
|
|
|
type ErrNotFound struct {
|
|
|
|
resource string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewErrNotFound creates a new ErrNotFound instance.
|
|
|
|
func NewErrNotFound(resource string) *ErrNotFound {
|
|
|
|
return &ErrNotFound{
|
|
|
|
resource: resource,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (nf *ErrNotFound) Error() string {
|
|
|
|
return fmt.Sprintf("{%s} not found", nf.resource)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsErrNotFound returns true if `err` is or wraps a ErrNotFound.
|
|
|
|
func IsErrNotFound(err error) bool {
|
|
|
|
if err == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
var nf *ErrNotFound
|
|
|
|
return errors.As(err, &nf)
|
2020-10-16 19:20:43 +02:00
|
|
|
}
|