GroupPlansData.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const Settings = require('settings-sharelatex')
  2. const fs = require('fs')
  3. const Path = require('path')
  4. // The groups.json file encodes the various group plan options we provide, and
  5. // is used in the app the render the appropriate dialog in the plans page, and
  6. // to generate the appropriate entries in the Settings.plans array.
  7. // It is also used by scripts/recurly/sync_recurly.rb, which will make sure
  8. // Recurly has a plan configured for all the groups, and that the prices are
  9. // up to date with the data in groups.json.
  10. const data = fs.readFileSync(
  11. Path.join(__dirname, '/../../../templates/plans/groups.json')
  12. )
  13. const groups = JSON.parse(data.toString())
  14. const capitalize = string => string.charAt(0).toUpperCase() + string.slice(1)
  15. // With group accounts in Recurly, we end up with a lot of plans to manage.
  16. // Rather than hand coding them in the settings file, and then needing to keep
  17. // that data in sync with the data in groups.json, we can auto generate the
  18. // group plan entries and append them to Settings.plans at boot time. This is not
  19. // a particularly clean pattern, since it's a little surprising that settings
  20. // are modified at boot-time, but I think it's a better option than trying to
  21. // keep two sources of data in sync.
  22. for (const [usage, planData] of Object.entries(groups)) {
  23. for (const [planCode, currencyData] of Object.entries(planData)) {
  24. // Gather all possible sizes that are set up in at least one currency
  25. const sizes = new Set()
  26. for (const priceData of Object.values(currencyData)) {
  27. for (const size in priceData) {
  28. sizes.add(size)
  29. }
  30. }
  31. // Generate plans in settings
  32. for (const size of sizes) {
  33. Settings.plans.push({
  34. planCode: `group_${planCode}_${size}_${usage}`,
  35. name: `${Settings.appName} ${capitalize(
  36. planCode
  37. )} - Group Account (${size} licenses) - ${capitalize(usage)}`,
  38. hideFromUsers: true,
  39. price: groups[usage][planCode].USD[size],
  40. annual: true,
  41. features: Settings.features[planCode],
  42. groupPlan: true,
  43. membersLimit: parseInt(size),
  44. membersLimitAddOn: 'additional-license',
  45. })
  46. }
  47. }
  48. }
  49. module.exports = groups