InstitutionsFeatures.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* eslint-disable
  2. handle-callback-err,
  3. max-len,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * DS207: Consider shorter variations of null checks
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. let InstitutionsFeatures
  15. const InstitutionsGetter = require('./InstitutionsGetter')
  16. const PlansLocator = require('../Subscription/PlansLocator')
  17. const Settings = require('settings-sharelatex')
  18. const logger = require('logger-sharelatex')
  19. module.exports = InstitutionsFeatures = {
  20. getInstitutionsFeatures(userId, callback) {
  21. if (callback == null) {
  22. callback = function(error, features) {}
  23. }
  24. return InstitutionsFeatures.getInstitutionsPlan(userId, function(
  25. error,
  26. plan
  27. ) {
  28. if (error != null) {
  29. return callback(error)
  30. }
  31. plan = PlansLocator.findLocalPlanInSettings(plan)
  32. return callback(null, (plan != null ? plan.features : undefined) || {})
  33. })
  34. },
  35. getInstitutionsPlan(userId, callback) {
  36. if (callback == null) {
  37. callback = function(error, plan) {}
  38. }
  39. return InstitutionsFeatures.hasLicence(userId, function(error, hasLicence) {
  40. if (error != null) {
  41. return callback(error)
  42. }
  43. if (!hasLicence) {
  44. return callback(null, null)
  45. }
  46. return callback(null, Settings.institutionPlanCode)
  47. })
  48. },
  49. hasLicence(userId, callback) {
  50. if (callback == null) {
  51. callback = function(error, hasLicence) {}
  52. }
  53. return InstitutionsGetter.getConfirmedAffiliations(userId, function(
  54. error,
  55. affiliations
  56. ) {
  57. if (error != null) {
  58. return callback(error)
  59. }
  60. const hasLicence = affiliations.some(
  61. affiliation => affiliation.licence && affiliation.licence !== 'free'
  62. )
  63. return callback(null, hasLicence)
  64. })
  65. }
  66. }