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

23 lines
876 B
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) ->) ->
InstitutionsFeatures.hasLicence userId, (error, hasLicence) ->
return callback error if error?
return callback(null, {}) unless hasLicence
plan = PlansLocator.findLocalPlanInSettings Settings.institutionPlanCode
callback(null, plan?.features or {})
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)