overleaf/services/web/app/coffee/Features/Institutions/InstitutionsFeatures.coffee

29 lines
1 KiB
CoffeeScript
Raw Normal View History

2018-08-10 07:40:25 -04:00
InstitutionsGetter = require './InstitutionsGetter'
PlansLocator = require '../Subscription/PlansLocator'
Settings = require 'settings-sharelatex'
logger = require 'logger-sharelatex'
module.exports = InstitutionsFeatures =
getInstitutionsFeatures: (userId, callback = (error, features) ->) ->
2018-09-24 08:16:31 -04:00
InstitutionsFeatures.getInstitutionsPlan userId, (error, plan) ->
return callback error if error?
2018-09-24 08:16:31 -04:00
plan = PlansLocator.findLocalPlanInSettings plan
callback(null, plan?.features or {})
2018-09-24 08:16:31 -04:00
getInstitutionsPlan: (userId, callback = (error, plan) ->) ->
InstitutionsFeatures.hasLicence userId, (error, hasLicence) ->
return callback error if error?
return callback(null, null) unless hasLicence
callback(null, Settings.institutionPlanCode)
hasLicence: (userId, callback = (error, hasLicence) ->) ->
2018-08-10 07:40:25 -04:00
InstitutionsGetter.getConfirmedInstitutions userId, (error, institutions) ->
return callback error if error?
2018-08-10 07:40:25 -04:00
hasLicence = institutions.some (institution) ->
institution.licence and institution.licence != 'free'
2018-08-10 07:40:25 -04:00
callback(null, hasLicence)