Skip to content

Commit

Permalink
Disable cloud limits (#4268)
Browse files Browse the repository at this point in the history
* Disable cloud limits

* Fix linter

* Disable limits initialization and shortcircuit GetBoardsCloudLimits

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
  • Loading branch information
mgdelacroix and mattermod authored Dec 22, 2022
1 parent bdf3e81 commit fd4cf95
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 53 deletions.
23 changes: 13 additions & 10 deletions mattermost-plugin/server/boards/boardsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/mattermost/focalboard/server/services/store"
"github.com/mattermost/focalboard/server/services/store/mattermostauthlayer"
"github.com/mattermost/focalboard/server/services/store/sqlstore"
"github.com/mattermost/focalboard/server/utils"
"github.com/mattermost/focalboard/server/ws"

mm_model "github.com/mattermost/mattermost-server/v6/model"
Expand Down Expand Up @@ -147,16 +146,20 @@ func NewBoardsApp(api model.ServicesAPI) (*BoardsApp, error) {

backendParams.appAPI.init(db, server.App())

if utils.IsCloudLicense(api.GetLicense()) {
limits, err := api.GetCloudLimits()
if err != nil {
return nil, fmt.Errorf("error fetching cloud limits when starting Boards: %w", err)
// ToDo: Cloud Limits have been disabled by design. We should
// revisit the decision and update the related code accordingly
/*
if utils.IsCloudLicense(api.GetLicense()) {
limits, err := api.GetCloudLimits()
if err != nil {
return nil, fmt.Errorf("error fetching cloud limits when starting Boards: %w", err)
}
if err := server.App().SetCloudLimits(limits); err != nil {
return nil, fmt.Errorf("error setting cloud limits when starting Boards: %w", err)
}
}

if err := server.App().SetCloudLimits(limits); err != nil {
return nil, fmt.Errorf("error setting cloud limits when starting Boards: %w", err)
}
}
*/

return &BoardsApp{
server: server,
Expand Down
39 changes: 23 additions & 16 deletions server/app/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,32 @@ func (a *App) InsertBlockAndNotify(block *model.Block, modifiedByID string, disa
}

func (a *App) isWithinViewsLimit(boardID string, block *model.Block) (bool, error) {
limits, err := a.GetBoardsCloudLimits()
if err != nil {
return false, err
}
// ToDo: Cloud Limits have been disabled by design. We should
// revisit the decision and update the related code accordingly

if limits.Views == model.LimitUnlimited {
return true, nil
}
/*
limits, err := a.GetBoardsCloudLimits()
if err != nil {
return false, err
}
views, err := a.store.GetBlocksWithParentAndType(boardID, block.ParentID, model.TypeView)
if err != nil {
return false, err
}
if limits.Views == model.LimitUnlimited {
return true, nil
}
views, err := a.store.GetBlocksWithParentAndType(boardID, block.ParentID, model.TypeView)
if err != nil {
return false, err
}
// < rather than <= because we'll be creating new view if this
// check passes. When that view is created, the limit will be reached.
// That's why we need to check for if existing + the being-created
// view doesn't exceed the limit.
return len(views) < limits.Views, nil
*/

// < rather than <= because we'll be creating new view if this
// check passes. When that view is created, the limit will be reached.
// That's why we need to check for if existing + the being-created
// view doesn't exceed the limit.
return len(views) < limits.Views, nil
return true, nil
}

func (a *App) InsertBlocks(blocks []*model.Block, modifiedByID string) ([]*model.Block, error) {
Expand Down
8 changes: 8 additions & 0 deletions server/app/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func TestPatchBlocks(t *testing.T) {
})

t.Run("cloud limit error scenario", func(t *testing.T) {
t.Skipf("The Cloud Limits feature has been disabled")

th.App.SetCardLimit(5)

fakeLicense := &mmModel.License{
Expand Down Expand Up @@ -185,6 +187,8 @@ func TestUndeleteBlock(t *testing.T) {
}

func TestIsWithinViewsLimit(t *testing.T) {
t.Skipf("The Cloud Limits feature has been disabled")

th, tearDown := SetupTestHelper(t)
defer tearDown()

Expand Down Expand Up @@ -302,6 +306,8 @@ func TestInsertBlocks(t *testing.T) {
})

t.Run("create view within limits", func(t *testing.T) {
t.Skipf("The Cloud Limits feature has been disabled")

boardID := testBoardID
block := &model.Block{
Type: model.TypeView,
Expand Down Expand Up @@ -334,6 +340,8 @@ func TestInsertBlocks(t *testing.T) {
})

t.Run("create view exceeding limits", func(t *testing.T) {
t.Skipf("The Cloud Limits feature has been disabled")

boardID := testBoardID
block := &model.Block{
Type: model.TypeView,
Expand Down
65 changes: 38 additions & 27 deletions server/app/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,45 @@ var ErrNilPluginAPI = errors.New("server not running in plugin mode")
// GetBoardsCloudLimits returns the limits of the server, and an empty
// limits struct if there are no limits set.
func (a *App) GetBoardsCloudLimits() (*model.BoardsCloudLimits, error) {
if !a.IsCloud() {
return &model.BoardsCloudLimits{}, nil
}
// ToDo: Cloud Limits have been disabled by design. We should
// revisit the decision and update the related code accordingly
/*
if !a.IsCloud() {
return &model.BoardsCloudLimits{}, nil
}
productLimits, err := a.store.GetCloudLimits()
if err != nil {
return nil, err
}
productLimits, err := a.store.GetCloudLimits()
if err != nil {
return nil, err
}
usedCards, err := a.store.GetUsedCardsCount()
if err != nil {
return nil, err
}
usedCards, err := a.store.GetUsedCardsCount()
if err != nil {
return nil, err
}
cardLimitTimestamp, err := a.store.GetCardLimitTimestamp()
if err != nil {
return nil, err
}
cardLimitTimestamp, err := a.store.GetCardLimitTimestamp()
if err != nil {
return nil, err
}
boardsCloudLimits := &model.BoardsCloudLimits{
UsedCards: usedCards,
CardLimitTimestamp: cardLimitTimestamp,
}
if productLimits != nil && productLimits.Boards != nil {
if productLimits.Boards.Cards != nil {
boardsCloudLimits.Cards = *productLimits.Boards.Cards
boardsCloudLimits := &model.BoardsCloudLimits{
UsedCards: usedCards,
CardLimitTimestamp: cardLimitTimestamp,
}
if productLimits.Boards.Views != nil {
boardsCloudLimits.Views = *productLimits.Boards.Views
if productLimits != nil && productLimits.Boards != nil {
if productLimits.Boards.Cards != nil {
boardsCloudLimits.Cards = *productLimits.Boards.Cards
}
if productLimits.Boards.Views != nil {
boardsCloudLimits.Views = *productLimits.Boards.Views
}
}
}
return boardsCloudLimits, nil
return boardsCloudLimits, nil
*/

return &model.BoardsCloudLimits{}, nil
}

func (a *App) GetUsedCardsCount() (int, error) {
Expand All @@ -68,7 +74,12 @@ func (a *App) IsCloud() bool {
// IsCloudLimited returns true if the server is running in cloud mode
// and the card limit has been set.
func (a *App) IsCloudLimited() bool {
return a.CardLimit() != 0 && a.IsCloud()
// ToDo: Cloud Limits have been disabled by design. We should
// revisit the decision and update the related code accordingly

// return a.CardLimit() != 0 && a.IsCloud()

return false
}

// SetCloudLimits sets the limits of the server.
Expand Down
12 changes: 12 additions & 0 deletions server/app/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func TestIsCloud(t *testing.T) {
}

func TestIsCloudLimited(t *testing.T) {
t.Skipf("The Cloud Limits feature has been disabled")

t.Run("if no limit has been set, it should be false", func(t *testing.T) {
th, tearDown := SetupTestHelper(t)
defer tearDown()
Expand All @@ -91,6 +93,8 @@ func TestIsCloudLimited(t *testing.T) {
}

func TestSetCloudLimits(t *testing.T) {
t.Skipf("The Cloud Limits feature has been disabled")

t.Run("if the limits are empty, it should do nothing", func(t *testing.T) {
t.Run("limits empty", func(t *testing.T) {
th, tearDown := SetupTestHelper(t)
Expand Down Expand Up @@ -179,6 +183,8 @@ func TestSetCloudLimits(t *testing.T) {
}

func TestUpdateCardLimitTimestamp(t *testing.T) {
t.Skipf("The Cloud Limits feature has been disabled")

fakeLicense := &mmModel.License{
Features: &mmModel.Features{Cloud: mmModel.NewBool(true)},
}
Expand Down Expand Up @@ -215,6 +221,8 @@ func TestUpdateCardLimitTimestamp(t *testing.T) {
}

func TestGetTemplateMapForBlocks(t *testing.T) {
t.Skipf("The Cloud Limits feature has been disabled")

t.Run("should fetch the necessary boards from the database", func(t *testing.T) {
th, tearDown := SetupTestHelper(t)
defer tearDown()
Expand Down Expand Up @@ -301,6 +309,8 @@ func TestGetTemplateMapForBlocks(t *testing.T) {
}

func TestApplyCloudLimits(t *testing.T) {
t.Skipf("The Cloud Limits feature has been disabled")

fakeLicense := &mmModel.License{
Features: &mmModel.Features{Cloud: mmModel.NewBool(true)},
}
Expand Down Expand Up @@ -395,6 +405,8 @@ func TestApplyCloudLimits(t *testing.T) {
}

func TestContainsLimitedBlocks(t *testing.T) {
t.Skipf("The Cloud Limits feature has been disabled")

// for all the following tests, the timestamp will be set to 150,
// which means that blocks with an UpdateAt set to 100 will be
// outside the active window and possibly limited, and blocks with
Expand Down

0 comments on commit fd4cf95

Please sign in to comment.