From e33443235d51dd4fe964b21fedbcbdd76558c2bf Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 10 Nov 2023 16:52:50 +0100 Subject: [PATCH] Different team slots config value for premium users --- www/common/application_config_internal.js | 4 ++++ www/common/common-constants.js | 2 ++ www/common/common-ui-elements.js | 2 +- www/teams/inner.js | 23 +++++++++++++++-------- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/www/common/application_config_internal.js b/www/common/application_config_internal.js index cdcf6014c..bb045cfc5 100644 --- a/www/common/application_config_internal.js +++ b/www/common/application_config_internal.js @@ -270,6 +270,10 @@ define(function() { // You can change the value here. // AppConfig.maxOwnedTeams = 5; + // Same settings but for premium users (users with a custom limit included) + // AppConfig.maxPremiumTeamsSlots = 10; + // AppConfig.maxPremiumTeamsOwned = 10; + // The userlist displayed in collaborative documents is stored alongside the document data. // Everytime someone with edit rights joins a document or modify their user data (display // name, avatar, color, etc.), they update the "userlist" part of the document. When too many diff --git a/www/common/common-constants.js b/www/common/common-constants.js index 888edeafd..35d6fa0ab 100644 --- a/www/common/common-constants.js +++ b/www/common/common-constants.js @@ -18,6 +18,8 @@ define(['/customize/application_config.js'], function (AppConfig) { deprecatedKey: 'deprecated', MAX_TEAMS_SLOTS: AppConfig.maxTeamsSlots || 5, MAX_TEAMS_OWNED: AppConfig.maxOwnedTeams || 5, + MAX_PREMIUM_TEAMS_SLOTS: Math.max(AppConfig.maxTeamsSlots || 0, AppConfig.maxPremiumTeamsSlots || 0) || 5, + MAX_PREMIUM_TEAMS_OWNED: Math.max(AppConfig.maxTeamsOwned || 0, AppConfig.maxPremiumTeamsOwned || 0) || 5, // Apps criticalApps: ['profile', 'settings', 'debug', 'admin', 'support', 'notifications', 'calendar'], earlyAccessApps: ['doc', 'presentation'] diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 3a03807f2..8059caff0 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -3599,9 +3599,9 @@ define([ }); }; - var MAX_TEAMS_SLOTS = Constants.MAX_TEAMS_SLOTS; var todo = function (yes) { var priv = common.getMetadataMgr().getPrivateData(); + var MAX_TEAMS_SLOTS = priv.plan ? Constants.MAX_PREMIUM_TEAMS_SLOTS : Constants.MAX_TEAMS_SLOTS; var numberOfTeams = Object.keys(priv.teams || {}).length; if (yes) { if (numberOfTeams >= MAX_TEAMS_SLOTS) { diff --git a/www/teams/inner.js b/www/teams/inner.js index 80cad3bd6..d8291ab7b 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -393,7 +393,6 @@ define([ ]); }); - var MAX_TEAMS_SLOTS = Constants.MAX_TEAMS_SLOTS; var openTeam = function (common, id, team) { var sframeChan = common.getSframeChannel(); APP.module.execCommand('SUBSCRIBE', id, function () { @@ -421,14 +420,18 @@ define([ }); }); }; - var canCreateTeams = function (teams) { + var canCreateTeams = function (common, teams) { var owned = Object.keys(teams || {}).filter(function (id) { return teams[id].owner; }).length; - return Constants.MAX_TEAMS_OWNED - owned; + var priv = common.getMetadataMgr().getPrivateData(); + var MAX_TEAMS_OWNED = priv.plan ? Constants.MAX_PREMIUM_TEAMS_OWNED : Constants.MAX_TEAMS_OWNED; + return MAX_TEAMS_OWNED - owned; }; var refreshList = function (common, cb) { var content = []; + var priv = common.getMetadataMgr().getPrivateData(); + var MAX_TEAMS_SLOTS = priv.plan ? Constants.MAX_PREMIUM_TEAMS_SLOTS : Constants.MAX_TEAMS_SLOTS; APP.module.execCommand('LIST_TEAMS', null, function (obj) { if (!obj) { return; } if (obj.error === "OFFLINE") { return UI.alert(Messages.driveOfflineError); } @@ -436,7 +439,7 @@ define([ var list = []; var keys = Object.keys(obj).slice(0,MAX_TEAMS_SLOTS); var slots = '('+Math.min(keys.length, MAX_TEAMS_SLOTS)+'/'+MAX_TEAMS_SLOTS+')'; - var createSlots = canCreateTeams(obj); + var createSlots = canCreateTeams(common, obj); for (var i = keys.length; i < MAX_TEAMS_SLOTS; i++) { obj[i] = { empty: true @@ -513,9 +516,12 @@ define([ var privateData = metadataMgr.getPrivateData(); var content = []; + var MAX_TEAMS_OWNED = privateData.plan ? Constants.MAX_PREMIUM_TEAMS_OWNED : Constants.MAX_TEAMS_OWNED; + var MAX_TEAMS_SLOTS = privateData.plan ? Constants.MAX_PREMIUM_TEAMS_SLOTS : Constants.MAX_TEAMS_SLOTS; + var isOwner = Object.keys(privateData.teams || {}).filter(function (id) { return privateData.teams[id].owner; - }).length >= Constants.MAX_TEAMS_OWNED && !privateData.devMode; + }).length >= MAX_TEAMS_OWNED && !privateData.devMode; var getWarningBox = function () { return h('div.alert.alert-warning', { @@ -523,7 +529,7 @@ define([ }, Messages._getKey('team_maxTeams', [MAX_TEAMS_SLOTS])); }; - if (Object.keys(privateData.teams || {}).length >= Constants.MAX_TEAMS_SLOTS || isOwner) { + if (Object.keys(privateData.teams || {}).length >= MAX_TEAMS_SLOTS || isOwner) { content.push(getWarningBox()); return void cb(content); } @@ -1252,12 +1258,13 @@ define([ var password = hashData.password; var seeds = InviteInner.deriveSeeds(hashData.key); var sframeChan = common.getSframeChannel(); + var MAX_TEAMS_SLOTS = privateData.plan ? Constants.MAX_PREMIUM_TEAMS_SLOTS : Constants.MAX_TEAMS_SLOTS; - if (Object.keys(privateData.teams || {}).length >= Constants.MAX_TEAMS_SLOTS) { + if (Object.keys(privateData.teams || {}).length >= MAX_TEAMS_SLOTS) { return void cb([ h('div.alert.alert-danger', { role: 'alert' - }, Messages._getKey('team_maxTeams', [Constants.MAX_TEAMS_SLOTS])) + }, Messages._getKey('team_maxTeams', [MAX_TEAMS_SLOTS])) ]); }