You've already forked focalboard
							
							
				mirror of
				https://github.com/mattermost/focalboard.git
				synced 2025-10-31 00:17:42 +02:00 
			
		
		
		
	Disable cloud limits (#4268)
* Disable cloud limits * Fix linter * Disable limits initialization and shortcircuit GetBoardsCloudLimits Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							bdf3e81b07
						
					
				
				
					commit
					fd4cf95f8a
				
			| @@ -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" | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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 | ||||
| 		} | ||||
|  | ||||
| 	// < 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 | ||||
| 		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 | ||||
| 	*/ | ||||
|  | ||||
| 	return true, nil | ||||
| } | ||||
|  | ||||
| func (a *App) InsertBlocks(blocks []*model.Block, modifiedByID string) ([]*model.Block, error) { | ||||
|   | ||||
| @@ -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{ | ||||
| @@ -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() | ||||
|  | ||||
| @@ -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, | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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 | ||||
| 	} | ||||
|  | ||||
| 	productLimits, err := a.store.GetCloudLimits() | ||||
| 	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 | ||||
| 	} | ||||
|  | ||||
| 	boardsCloudLimits := &model.BoardsCloudLimits{ | ||||
| 		UsedCards:          usedCards, | ||||
| 		CardLimitTimestamp: cardLimitTimestamp, | ||||
| 	} | ||||
| 	if productLimits != nil && productLimits.Boards != nil { | ||||
| 		if productLimits.Boards.Cards != nil { | ||||
| 			boardsCloudLimits.Cards = *productLimits.Boards.Cards | ||||
| 	// 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 | ||||
| 		} | ||||
| 		if productLimits.Boards.Views != nil { | ||||
| 			boardsCloudLimits.Views = *productLimits.Boards.Views | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return boardsCloudLimits, nil | ||||
| 		productLimits, err := a.store.GetCloudLimits() | ||||
| 		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 | ||||
| 		} | ||||
|  | ||||
| 		boardsCloudLimits := &model.BoardsCloudLimits{ | ||||
| 			UsedCards:          usedCards, | ||||
| 			CardLimitTimestamp: cardLimitTimestamp, | ||||
| 		} | ||||
| 		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 &model.BoardsCloudLimits{}, nil | ||||
| } | ||||
|  | ||||
| func (a *App) GetUsedCardsCount() (int, error) { | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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() | ||||
| @@ -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) | ||||
| @@ -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)}, | ||||
| 	} | ||||
| @@ -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() | ||||
| @@ -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)}, | ||||
| 	} | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user