mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #3681 from overleaf/em-group-plans
Configure group plans for additional licenses GitOrigin-RevId: 57822de9f490505c4b083afa80220e4d5b4c7d23
This commit is contained in:
parent
2138bd2a80
commit
e5c49ea19a
5 changed files with 72 additions and 120 deletions
|
@ -1,18 +1,6 @@
|
|||
/* eslint-disable
|
||||
camelcase,
|
||||
max-len,
|
||||
no-path-concat,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const Settings = require('settings-sharelatex')
|
||||
const fs = require('fs')
|
||||
const Path = require('path')
|
||||
|
||||
// The groups.json file encodes the various group plan options we provide, and
|
||||
// is used in the app the render the appropriate dialog in the plans page, and
|
||||
|
@ -21,7 +9,7 @@ const fs = require('fs')
|
|||
// Recurly has a plan configured for all the groups, and that the prices are
|
||||
// up to date with the data in groups.json.
|
||||
const data = fs.readFileSync(
|
||||
__dirname + '/../../../templates/plans/groups.json'
|
||||
Path.join(__dirname, '/../../../templates/plans/groups.json')
|
||||
)
|
||||
const groups = JSON.parse(data.toString())
|
||||
|
||||
|
@ -34,27 +22,31 @@ const capitalize = string => string.charAt(0).toUpperCase() + string.slice(1)
|
|||
// a particularly clean pattern, since it's a little surprising that settings
|
||||
// are modified at boot-time, but I think it's a better option than trying to
|
||||
// keep two sources of data in sync.
|
||||
for (let usage in groups) {
|
||||
const plan_data = groups[usage]
|
||||
for (let plan_code in plan_data) {
|
||||
const currency_data = plan_data[plan_code]
|
||||
for (let currency in currency_data) {
|
||||
const price_data = currency_data[currency]
|
||||
for (let size in price_data) {
|
||||
const price = price_data[size]
|
||||
Settings.plans.push({
|
||||
planCode: `group_${plan_code}_${size}_${usage}`,
|
||||
name: `${Settings.appName} ${capitalize(
|
||||
plan_code
|
||||
)} - Group Account (${size} licenses) - ${capitalize(usage)}`,
|
||||
hideFromUsers: true,
|
||||
annual: true,
|
||||
features: Settings.features[plan_code],
|
||||
groupPlan: true,
|
||||
membersLimit: parseInt(size)
|
||||
})
|
||||
for (const [usage, planData] of Object.entries(groups)) {
|
||||
for (const [planCode, currencyData] of Object.entries(planData)) {
|
||||
// Gather all possible sizes that are set up in at least one currency
|
||||
const sizes = new Set()
|
||||
for (const priceData of Object.values(currencyData)) {
|
||||
for (const size in priceData) {
|
||||
sizes.add(size)
|
||||
}
|
||||
}
|
||||
|
||||
// Generate plans in settings
|
||||
for (const size of sizes) {
|
||||
Settings.plans.push({
|
||||
planCode: `group_${planCode}_${size}_${usage}`,
|
||||
name: `${Settings.appName} ${capitalize(
|
||||
planCode
|
||||
)} - Group Account (${size} licenses) - ${capitalize(usage)}`,
|
||||
hideFromUsers: true,
|
||||
annual: true,
|
||||
features: Settings.features[planCode],
|
||||
groupPlan: true,
|
||||
membersLimit: parseInt(size),
|
||||
membersLimitAddOn: 'additional-license'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,34 +1,16 @@
|
|||
/* eslint-disable
|
||||
node/handle-callback-err,
|
||||
max-len,
|
||||
no-return-assign,
|
||||
no-unused-vars,
|
||||
*/
|
||||
// TODO: This file was created by bulk-decaffeinate.
|
||||
// Fix any style issues and re-enable lint.
|
||||
/*
|
||||
* decaffeinate suggestions:
|
||||
* DS101: Remove unnecessary use of Array.from
|
||||
* DS102: Remove unnecessary code created because of implicit returns
|
||||
* DS103: Rewrite code to no longer use __guard__
|
||||
* DS207: Consider shorter variations of null checks
|
||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||
*/
|
||||
const Settings = require('settings-sharelatex')
|
||||
const RecurlyWrapper = require('./RecurlyWrapper')
|
||||
const PlansLocator = require('./PlansLocator')
|
||||
const SubscriptionFormatters = require('./SubscriptionFormatters')
|
||||
const LimitationsManager = require('./LimitationsManager')
|
||||
const SubscriptionLocator = require('./SubscriptionLocator')
|
||||
const V1SubscriptionManager = require('./V1SubscriptionManager')
|
||||
const InstitutionsGetter = require('../Institutions/InstitutionsGetter')
|
||||
const PublishersGetter = require('../Publishers/PublishersGetter')
|
||||
const sanitizeHtml = require('sanitize-html')
|
||||
const logger = require('logger-sharelatex')
|
||||
const _ = require('underscore')
|
||||
const async = require('async')
|
||||
|
||||
const buildHostedLink = function(recurlySubscription, type) {
|
||||
function buildHostedLink(recurlySubscription, type) {
|
||||
const recurlySubdomain = Settings.apis.recurly.subdomain
|
||||
const hostedLoginToken = recurlySubscription.account.hosted_login_token
|
||||
let path = ''
|
||||
|
@ -48,28 +30,22 @@ const buildHostedLink = function(recurlySubscription, type) {
|
|||
|
||||
module.exports = {
|
||||
buildUsersSubscriptionViewModel(user, callback) {
|
||||
if (callback == null) {
|
||||
callback = function(error, data) {}
|
||||
}
|
||||
return async.auto(
|
||||
async.auto(
|
||||
{
|
||||
personalSubscription(cb) {
|
||||
return SubscriptionLocator.getUsersSubscription(user, cb)
|
||||
SubscriptionLocator.getUsersSubscription(user, cb)
|
||||
},
|
||||
recurlySubscription: [
|
||||
'personalSubscription',
|
||||
function(cb, { personalSubscription }) {
|
||||
(cb, { personalSubscription }) => {
|
||||
if (
|
||||
(personalSubscription != null
|
||||
? personalSubscription.recurlySubscription_id
|
||||
: undefined) == null ||
|
||||
(personalSubscription != null
|
||||
? personalSubscription.recurlySubscription_id
|
||||
: undefined) === ''
|
||||
personalSubscription == null ||
|
||||
personalSubscription.recurlySubscription_id == null ||
|
||||
personalSubscription.recurlySubscription_id === ''
|
||||
) {
|
||||
return cb(null, null)
|
||||
}
|
||||
return RecurlyWrapper.getSubscription(
|
||||
RecurlyWrapper.getSubscription(
|
||||
personalSubscription.recurlySubscription_id,
|
||||
{ includeAccount: true },
|
||||
cb
|
||||
|
@ -78,17 +54,17 @@ module.exports = {
|
|||
],
|
||||
recurlyCoupons: [
|
||||
'recurlySubscription',
|
||||
function(cb, { recurlySubscription }) {
|
||||
(cb, { recurlySubscription }) => {
|
||||
if (!recurlySubscription) {
|
||||
return cb(null, null)
|
||||
}
|
||||
const accountId = recurlySubscription.account.account_code
|
||||
return RecurlyWrapper.getAccountActiveCoupons(accountId, cb)
|
||||
RecurlyWrapper.getAccountActiveCoupons(accountId, cb)
|
||||
}
|
||||
],
|
||||
plan: [
|
||||
'personalSubscription',
|
||||
function(cb, { personalSubscription }) {
|
||||
(cb, { personalSubscription }) => {
|
||||
if (personalSubscription == null) {
|
||||
return cb()
|
||||
}
|
||||
|
@ -102,38 +78,38 @@ module.exports = {
|
|||
)
|
||||
)
|
||||
}
|
||||
return cb(null, plan)
|
||||
cb(null, plan)
|
||||
}
|
||||
],
|
||||
memberGroupSubscriptions(cb) {
|
||||
return SubscriptionLocator.getMemberSubscriptions(user, cb)
|
||||
SubscriptionLocator.getMemberSubscriptions(user, cb)
|
||||
},
|
||||
managedGroupSubscriptions(cb) {
|
||||
return SubscriptionLocator.getManagedGroupSubscriptions(user, cb)
|
||||
SubscriptionLocator.getManagedGroupSubscriptions(user, cb)
|
||||
},
|
||||
confirmedMemberAffiliations(cb) {
|
||||
return InstitutionsGetter.getConfirmedAffiliations(user._id, cb)
|
||||
InstitutionsGetter.getConfirmedAffiliations(user._id, cb)
|
||||
},
|
||||
managedInstitutions(cb) {
|
||||
return InstitutionsGetter.getManagedInstitutions(user._id, cb)
|
||||
InstitutionsGetter.getManagedInstitutions(user._id, cb)
|
||||
},
|
||||
managedPublishers(cb) {
|
||||
return PublishersGetter.getManagedPublishers(user._id, cb)
|
||||
PublishersGetter.getManagedPublishers(user._id, cb)
|
||||
},
|
||||
v1SubscriptionStatus(cb) {
|
||||
return V1SubscriptionManager.getSubscriptionStatusFromV1(
|
||||
V1SubscriptionManager.getSubscriptionStatusFromV1(
|
||||
user._id,
|
||||
function(error, status, v1Id) {
|
||||
if (error != null) {
|
||||
(error, status, v1Id) => {
|
||||
if (error) {
|
||||
return cb(error)
|
||||
}
|
||||
return cb(null, status)
|
||||
cb(null, status)
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
function(err, results) {
|
||||
if (err != null) {
|
||||
(err, results) => {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
let {
|
||||
|
@ -168,9 +144,8 @@ module.exports = {
|
|||
}
|
||||
|
||||
if (
|
||||
(personalSubscription != null
|
||||
? personalSubscription.toObject
|
||||
: undefined) != null
|
||||
personalSubscription &&
|
||||
typeof personalSubscription.toObject === 'function'
|
||||
) {
|
||||
// Downgrade from Mongoose object, so we can add a recurly and plan attribute
|
||||
personalSubscription = personalSubscription.toObject()
|
||||
|
@ -180,15 +155,13 @@ module.exports = {
|
|||
personalSubscription.plan = plan
|
||||
}
|
||||
|
||||
if (personalSubscription != null && recurlySubscription != null) {
|
||||
const tax =
|
||||
(recurlySubscription != null
|
||||
? recurlySubscription.tax_in_cents
|
||||
: undefined) || 0
|
||||
if (personalSubscription && recurlySubscription) {
|
||||
const tax = recurlySubscription.tax_in_cents || 0
|
||||
// Some plans allow adding more seats than the base plan provides.
|
||||
// This is recorded as a subscription add on.
|
||||
// Note: tax_in_cents already includes the tax for any addon.
|
||||
let addOnPrice = 0
|
||||
let additionalLicenses = 0
|
||||
if (
|
||||
plan.membersLimitAddOn &&
|
||||
Array.isArray(recurlySubscription.subscription_add_ons)
|
||||
|
@ -196,18 +169,15 @@ module.exports = {
|
|||
recurlySubscription.subscription_add_ons.forEach(addOn => {
|
||||
if (addOn.add_on_code === plan.membersLimitAddOn) {
|
||||
addOnPrice += addOn.quantity * addOn.unit_amount_in_cents
|
||||
additionalLicenses += addOn.quantity
|
||||
}
|
||||
})
|
||||
}
|
||||
const totalLicenses = (plan.membersLimit || 0) + additionalLicenses
|
||||
personalSubscription.recurly = {
|
||||
tax,
|
||||
taxRate: parseFloat(
|
||||
__guard__(
|
||||
recurlySubscription != null
|
||||
? recurlySubscription.tax_rate
|
||||
: undefined,
|
||||
x => x._
|
||||
)
|
||||
recurlySubscription.tax_rate && recurlySubscription.tax_rate._
|
||||
),
|
||||
billingDetailsLink: buildHostedLink(
|
||||
recurlySubscription,
|
||||
|
@ -215,26 +185,18 @@ module.exports = {
|
|||
),
|
||||
accountManagementLink: buildHostedLink(recurlySubscription),
|
||||
price: SubscriptionFormatters.formatPrice(
|
||||
(recurlySubscription != null
|
||||
? recurlySubscription.unit_amount_in_cents
|
||||
: undefined) +
|
||||
addOnPrice +
|
||||
tax,
|
||||
recurlySubscription != null
|
||||
? recurlySubscription.currency
|
||||
: undefined
|
||||
recurlySubscription.unit_amount_in_cents + addOnPrice + tax,
|
||||
recurlySubscription.currency
|
||||
),
|
||||
additionalLicenses,
|
||||
totalLicenses,
|
||||
nextPaymentDueAt: SubscriptionFormatters.formatDate(
|
||||
recurlySubscription != null
|
||||
? recurlySubscription.current_period_ends_at
|
||||
: undefined
|
||||
recurlySubscription.current_period_ends_at
|
||||
),
|
||||
currency: recurlySubscription.currency,
|
||||
state: recurlySubscription.state,
|
||||
trialEndsAtFormatted: SubscriptionFormatters.formatDate(
|
||||
recurlySubscription != null
|
||||
? recurlySubscription.trial_ends_at
|
||||
: undefined
|
||||
recurlySubscription.trial_ends_at
|
||||
),
|
||||
trial_ends_at: recurlySubscription.trial_ends_at,
|
||||
activeCoupons: recurlyCoupons,
|
||||
|
@ -242,9 +204,7 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
for (let memberGroupSubscription of Array.from(
|
||||
memberGroupSubscriptions
|
||||
)) {
|
||||
for (const memberGroupSubscription of memberGroupSubscriptions) {
|
||||
if (memberGroupSubscription.teamNotice) {
|
||||
memberGroupSubscription.teamNotice = sanitizeHtml(
|
||||
memberGroupSubscription.teamNotice
|
||||
|
@ -252,7 +212,7 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
return callback(null, {
|
||||
callback(null, {
|
||||
personalSubscription,
|
||||
managedGroupSubscriptions,
|
||||
memberGroupSubscriptions,
|
||||
|
@ -308,9 +268,3 @@ module.exports = {
|
|||
return result
|
||||
}
|
||||
}
|
||||
|
||||
function __guard__(value, transform) {
|
||||
return typeof value !== 'undefined' && value !== null
|
||||
? transform(value)
|
||||
: undefined
|
||||
}
|
||||
|
|
|
@ -8,7 +8,10 @@ div(ng-controller="RecurlySubscriptionController")
|
|||
case personalSubscription.recurly.state
|
||||
when "active"
|
||||
p !{translate("currently_subscribed_to_plan", {planName: personalSubscription.plan.name}, ['strong'])}
|
||||
|
|
||||
-if (personalSubscription.recurly.additionalLicenses > 0)
|
||||
|
|
||||
| !{translate("additional_licenses", {additionalLicenses: personalSubscription.recurly.additionalLicenses, totalLicenses: personalSubscription.recurly.totalLicenses}, ['strong', 'strong'])}
|
||||
|
|
||||
a(href, ng-click="switchToChangePlanView()", ng-if="showChangePlanButton") !{translate("change_plan")}.
|
||||
-if (personalSubscription.recurly.trialEndsAtFormatted && personalSubscription.recurly.trial_ends_at > Date.now())
|
||||
p You're on a free trial which ends on <strong ng-non-bindable>#{personalSubscription.recurly.trialEndsAtFormatted}</strong>
|
||||
|
|
|
@ -1005,6 +1005,7 @@
|
|||
"currently_subscribed_to_plan": "You are currently subscribed to the <0>__planName__</0> plan.",
|
||||
"change_plan": "Change plan",
|
||||
"next_payment_of_x_collectected_on_y": "The next payment of <0>__paymentAmmount__</0> will be collected on <1>__collectionDate__</1>.",
|
||||
"additional_licenses": "Your subscription includes <0>__additionalLicenses__</0> additional license(s) for a total of <1>__totalLicenses__</1> licenses.",
|
||||
"update_your_billing_details": "Update Your Billing Details",
|
||||
"subscription_canceled_and_terminate_on_x": " Your subscription has been canceled and will terminate on <0>__terminateDate__</0>. No further payments will be taken.",
|
||||
"your_subscription_has_expired": "Your subscription has expired.",
|
||||
|
|
|
@ -134,7 +134,9 @@ describe('Subscriptions', function() {
|
|||
account_code: this.user._id,
|
||||
email: 'mock@email.com',
|
||||
hosted_login_token: 'mock-login-token'
|
||||
}
|
||||
},
|
||||
additionalLicenses: 0,
|
||||
totalLicenses: 0
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue