2019-05-29 05:21:06 -04:00
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
const fs = require('fs')
|
2021-02-22 11:36:18 -05:00
|
|
|
const Path = require('path')
|
2019-05-29 05:21:06 -04:00
|
|
|
|
|
|
|
// The groups.json file encodes the various group plan options we provide, and
|
|
|
|
// is used in the app the render the appropriate dialog in the plans page, and
|
|
|
|
// to generate the appropriate entries in the Settings.plans array.
|
|
|
|
// It is also used by scripts/recurly/sync_recurly.rb, which will make sure
|
|
|
|
// Recurly has a plan configured for all the groups, and that the prices are
|
|
|
|
// up to date with the data in groups.json.
|
|
|
|
const data = fs.readFileSync(
|
2021-02-22 11:36:18 -05:00
|
|
|
Path.join(__dirname, '/../../../templates/plans/groups.json')
|
2019-05-29 05:21:06 -04:00
|
|
|
)
|
|
|
|
const groups = JSON.parse(data.toString())
|
|
|
|
|
|
|
|
const capitalize = string => string.charAt(0).toUpperCase() + string.slice(1)
|
|
|
|
|
|
|
|
// With group accounts in Recurly, we end up with a lot of plans to manage.
|
|
|
|
// Rather than hand coding them in the settings file, and then needing to keep
|
|
|
|
// that data in sync with the data in groups.json, we can auto generate the
|
|
|
|
// group plan entries and append them to Settings.plans at boot time. This is not
|
|
|
|
// a particularly clean pattern, since it's a little surprising that settings
|
|
|
|
// are modified at boot-time, but I think it's a better option than trying to
|
|
|
|
// keep two sources of data in sync.
|
2021-02-22 11:36:18 -05:00
|
|
|
for (const [usage, planData] of Object.entries(groups)) {
|
|
|
|
for (const [planCode, currencyData] of Object.entries(planData)) {
|
|
|
|
// Gather all possible sizes that are set up in at least one currency
|
|
|
|
const sizes = new Set()
|
|
|
|
for (const priceData of Object.values(currencyData)) {
|
|
|
|
for (const size in priceData) {
|
|
|
|
sizes.add(size)
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
}
|
2021-02-22 11:36:18 -05:00
|
|
|
|
|
|
|
// Generate plans in settings
|
|
|
|
for (const size of sizes) {
|
|
|
|
Settings.plans.push({
|
|
|
|
planCode: `group_${planCode}_${size}_${usage}`,
|
|
|
|
name: `${Settings.appName} ${capitalize(
|
|
|
|
planCode
|
|
|
|
)} - Group Account (${size} licenses) - ${capitalize(usage)}`,
|
|
|
|
hideFromUsers: true,
|
|
|
|
annual: true,
|
|
|
|
features: Settings.features[planCode],
|
|
|
|
groupPlan: true,
|
|
|
|
membersLimit: parseInt(size),
|
|
|
|
membersLimitAddOn: 'additional-license'
|
|
|
|
})
|
|
|
|
}
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = groups
|