From 877f0c8316079c53b8684447f920664ef6d3f901 Mon Sep 17 00:00:00 2001 From: wiggin77 Date: Thu, 5 Jan 2023 20:26:57 -0500 Subject: [PATCH] Revert "Cherry pick pr4400 rolling stable (#4404)" This reverts commit 6e69de0791d82ac5b0b1e5cec09199c5a45649e8. --- mattermost-plugin/product/boards_product.go | 105 +++++++----------- .../server/boards/boards_service_api.go | 84 -------------- server/app/app.go | 2 - server/app/permissions.go | 9 -- server/model/board.go | 15 --- 5 files changed, 40 insertions(+), 175 deletions(-) delete mode 100644 mattermost-plugin/server/boards/boards_service_api.go delete mode 100644 server/app/permissions.go diff --git a/mattermost-plugin/product/boards_product.go b/mattermost-plugin/product/boards_product.go index 77230b863..3da896863 100644 --- a/mattermost-plugin/product/boards_product.go +++ b/mattermost-plugin/product/boards_product.go @@ -31,7 +31,6 @@ func init() { product.ChannelKey: {}, product.UserKey: {}, product.PostKey: {}, - product.PermissionsKey: {}, product.BotKey: {}, product.ClusterKey: {}, product.ConfigKey: {}, @@ -45,7 +44,6 @@ func init() { product.StoreKey: {}, product.SystemKey: {}, product.PreferencesKey: {}, - product.HooksKey: {}, }, }) } @@ -75,150 +73,127 @@ type boardsProduct struct { } func newBoardsProduct(services map[product.ServiceKey]interface{}) (product.Product, error) { - boardsProd := &boardsProduct{} + boards := &boardsProduct{} - if err := populateServices(boardsProd, services); err != nil { - return nil, err - } - - boardsProd.logger.Info("Creating boards service") - - adapter := newServiceAPIAdapter(boardsProd) - boardsApp, err := boards.NewBoardsApp(adapter) - if err != nil { - return nil, fmt.Errorf("failed to create Boards service: %w", err) - } - - boardsProd.boardsApp = boardsApp - - // Add the Boards services API to the services map so other products can access Boards functionality. - boardsAPI := boards.NewBoardsServiceAPI(boardsApp) - services[product.BoardsKey] = boardsAPI - - return boardsProd, nil -} - -// populateServices populates the boardProduct with all the services needed from the suite. -func populateServices(boardsProd *boardsProduct, services map[product.ServiceKey]interface{}) error { for key, service := range services { switch key { case product.TeamKey: teamService, ok := service.(product.TeamService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.teamService = teamService + boards.teamService = teamService case product.ChannelKey: channelService, ok := service.(product.ChannelService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.channelService = channelService + boards.channelService = channelService case product.UserKey: userService, ok := service.(product.UserService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.userService = userService + boards.userService = userService case product.PostKey: postService, ok := service.(product.PostService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.postService = postService + boards.postService = postService case product.PermissionsKey: permissionsService, ok := service.(product.PermissionService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.permissionsService = permissionsService + boards.permissionsService = permissionsService case product.BotKey: botService, ok := service.(product.BotService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.botService = botService + boards.botService = botService case product.ClusterKey: clusterService, ok := service.(product.ClusterService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.clusterService = clusterService + boards.clusterService = clusterService case product.ConfigKey: configService, ok := service.(product.ConfigService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.configService = configService + boards.configService = configService case product.LogKey: logger, ok := service.(mlog.LoggerIFace) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.logger = logger.With(mlog.String("product", boardsProductName)) + boards.logger = logger.With(mlog.String("product", boardsProductName)) case product.LicenseKey: licenseService, ok := service.(product.LicenseService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.licenseService = licenseService + boards.licenseService = licenseService case product.FilestoreKey: filestoreService, ok := service.(product.FilestoreService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.filestoreService = filestoreService + boards.filestoreService = filestoreService case product.FileInfoStoreKey: fileInfoStoreService, ok := service.(product.FileInfoStoreService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.fileInfoStoreService = fileInfoStoreService + boards.fileInfoStoreService = fileInfoStoreService case product.RouterKey: routerService, ok := service.(product.RouterService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.routerService = routerService + boards.routerService = routerService case product.CloudKey: cloudService, ok := service.(product.CloudService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.cloudService = cloudService + boards.cloudService = cloudService case product.KVStoreKey: kvStoreService, ok := service.(product.KVStoreService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.kvStoreService = kvStoreService + boards.kvStoreService = kvStoreService case product.StoreKey: storeService, ok := service.(product.StoreService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.storeService = storeService + boards.storeService = storeService case product.SystemKey: systemService, ok := service.(product.SystemService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.systemService = systemService + boards.systemService = systemService case product.PreferencesKey: preferencesService, ok := service.(product.PreferencesService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.preferencesService = preferencesService + boards.preferencesService = preferencesService case product.HooksKey: hooksService, ok := service.(product.HooksService) if !ok { - return fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) + return nil, fmt.Errorf("invalid service key '%s': %w", key, errServiceTypeAssert) } - boardsProd.hooksService = hooksService + boards.hooksService = hooksService } } - return nil + return boards, nil } func (bp *boardsProduct) Start() error { diff --git a/mattermost-plugin/server/boards/boards_service_api.go b/mattermost-plugin/server/boards/boards_service_api.go deleted file mode 100644 index b9d6af689..000000000 --- a/mattermost-plugin/server/boards/boards_service_api.go +++ /dev/null @@ -1,84 +0,0 @@ -package boards - -import ( - "github.com/mattermost/focalboard/server/app" - "github.com/mattermost/focalboard/server/model" - - mm_model "github.com/mattermost/mattermost-server/v6/model" - "github.com/mattermost/mattermost-server/v6/product" -) - -// boardsServiceAPI provides a service API for other products such as Channels. -type boardsServiceAPI struct { - app *app.App -} - -func NewBoardsServiceAPI(app *BoardsApp) *boardsServiceAPI { - return &boardsServiceAPI{ - app: app.server.App(), - } -} - -func (bs *boardsServiceAPI) GetTemplates(teamID string, userID string) ([]*model.Board, error) { - return bs.app.GetTemplateBoards(teamID, userID) -} - -func (bs *boardsServiceAPI) GetBoard(boardID string) (*model.Board, error) { - return bs.app.GetBoard(boardID) -} - -func (bs *boardsServiceAPI) CreateBoard(board *model.Board, userID string, addmember bool) (*model.Board, error) { - return bs.app.CreateBoard(board, userID, addmember) -} - -func (bs *boardsServiceAPI) PatchBoard(boardPatch *model.BoardPatch, boardID string, userID string) (*model.Board, error) { - return bs.app.PatchBoard(boardPatch, boardID, userID) -} - -func (bs *boardsServiceAPI) DeleteBoard(boardID string, userID string) error { - return bs.app.DeleteBoard(boardID, userID) -} - -func (bs *boardsServiceAPI) SearchBoards(searchTerm string, searchField model.BoardSearchField, - userID string, includePublicBoards bool) ([]*model.Board, error) { - return bs.app.SearchBoardsForUser(searchTerm, searchField, userID, includePublicBoards) -} - -func (bs *boardsServiceAPI) LinkBoardToChannel(boardID string, channelID string, userID string) (*model.Board, error) { - patch := &model.BoardPatch{ - ChannelID: &channelID, - } - return bs.app.PatchBoard(patch, boardID, userID) -} - -func (bs *boardsServiceAPI) GetCards(boardID string) ([]*model.Card, error) { - return bs.app.GetCardsForBoard(boardID, 0, 0) -} - -func (bs *boardsServiceAPI) GetCard(cardID string) (*model.Card, error) { - return bs.app.GetCardByID(cardID) -} - -func (bs *boardsServiceAPI) CreateCard(card *model.Card, boardID string, userID string) (*model.Card, error) { - return bs.app.CreateCard(card, boardID, userID, false) -} - -func (bs *boardsServiceAPI) PatchCard(cardPatch *model.CardPatch, cardID string, userID string) (*model.Card, error) { - return bs.app.PatchCard(cardPatch, cardID, userID, false) -} - -func (bs *boardsServiceAPI) DeleteCard(cardID string, userID string) error { - return bs.app.DeleteBlock(cardID, userID) -} - -func (bs *boardsServiceAPI) HasPermissionToBoard(userID, boardID string, permission *mm_model.Permission) bool { - return bs.app.HasPermissionToBoard(userID, boardID, permission) -} - -func (bs *boardsServiceAPI) DuplicateBoard(boardID string, userID string, - toTeam string, asTemplate bool) (*model.BoardsAndBlocks, []*model.BoardMember, error) { - return bs.app.DuplicateBoard(boardID, userID, toTeam, asTemplate) -} - -// Ensure boardsServiceAPI implements product.BoardsService interface. -var _ product.BoardsService = (*boardsServiceAPI)(nil) diff --git a/server/app/app.go b/server/app/app.go index 4825c9882..de6697b6c 100644 --- a/server/app/app.go +++ b/server/app/app.go @@ -64,7 +64,6 @@ type App struct { metrics *metrics.Metrics notifications *notify.Service logger mlog.LoggerIFace - permissions permissions.PermissionsService blockChangeNotifier *utils.CallbackQueue servicesAPI servicesAPI @@ -91,7 +90,6 @@ func New(config *config.Configuration, wsAdapter ws.Adapter, services Services) metrics: services.Metrics, notifications: services.Notifications, logger: services.Logger, - permissions: services.Permissions, blockChangeNotifier: utils.NewCallbackQueue("blockChangeNotifier", blockChangeNotifierQueueSize, blockChangeNotifierPoolSize, services.Logger), servicesAPI: services.ServicesAPI, } diff --git a/server/app/permissions.go b/server/app/permissions.go deleted file mode 100644 index bbd7c91da..000000000 --- a/server/app/permissions.go +++ /dev/null @@ -1,9 +0,0 @@ -package app - -import ( - mm_model "github.com/mattermost/mattermost-server/v6/model" -) - -func (a *App) HasPermissionToBoard(userID, boardID string, permission *mm_model.Permission) bool { - return a.permissions.HasPermissionToBoard(userID, boardID, permission) -} diff --git a/server/model/board.go b/server/model/board.go index 56bd6a613..e38db46e7 100644 --- a/server/model/board.go +++ b/server/model/board.go @@ -105,21 +105,6 @@ type Board struct { DeleteAt int64 `json:"deleteAt"` } -// GetPropertyString returns the value of the specified property as a string, -// or error if the property does not exist or is not of type string. -func (b *Board) GetPropertyString(propName string) (string, error) { - val, ok := b.Properties[propName] - if !ok { - return "", NewErrNotFound(propName) - } - - s, ok := val.(string) - if !ok { - return "", ErrInvalidPropertyValueType - } - return s, nil -} - // BoardPatch is a patch for modify boards // swagger:model type BoardPatch struct {