GroupPlansData.coffee 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. Settings = require 'settings-sharelatex'
  2. fs = require('fs')
  3. # The groups.json file encodes the various group plan options we provide, and
  4. # is used in the app the render the appropriate dialog in the plans page, and
  5. # to generate the appropriate entries in the Settings.plans array.
  6. # It is also used by scripts/recurly/sync_recurly.rb, which will make sure
  7. # Recurly has a plan configured for all the groups, and that the prices are
  8. # up to date with the data in groups.json.
  9. data = fs.readFileSync(__dirname + '/../../../templates/plans/groups.json')
  10. groups = JSON.parse(data.toString())
  11. capitalize = (string) ->
  12. string.charAt(0).toUpperCase() + string.slice(1);
  13. # With group accounts in Recurly, we end up with a lot of plans to manage.
  14. # Rather than hand coding them in the settings file, and then needing to keep
  15. # that data in sync with the data in groups.json, we can auto generate the
  16. # group plan entries and append them to Settings.plans at boot time. This is not
  17. # a particularly clean pattern, since it's a little surprising that settings
  18. # are modified at boot-time, but I think it's a better option than trying to
  19. # keep two sources of data in sync.
  20. for usage, plan_data of groups
  21. for plan_code, currency_data of plan_data
  22. for currency, price_data of currency_data
  23. for size, price of price_data
  24. Settings.plans.push {
  25. planCode: "group_#{plan_code}_#{size}_#{usage}",
  26. name: "#{Settings.appName} #{capitalize(plan_code)} - Group Account (#{size} licenses) - #{capitalize(usage)}",
  27. hideFromUsers: true,
  28. annual: true
  29. features: Settings.features[plan_code]
  30. groupPlan: true
  31. membersLimit: parseInt(size)
  32. }
  33. module.exports = groups