mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-08 00:29:04 +02:00
Merge pull request #3495 from overleaf/ae-prettier-2
Upgrade Prettier to v2 GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
@@ -41,7 +41,7 @@ module.exports = SubscriptionController = {
|
||||
|
||||
return GeoIpLookup.getCurrencyCode(
|
||||
(req.query != null ? req.query.ip : undefined) || req.ip,
|
||||
function(err, recomendedCurrency) {
|
||||
function (err, recomendedCurrency) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
@@ -57,16 +57,17 @@ module.exports = SubscriptionController = {
|
||||
})
|
||||
const user_id = AuthenticationController.getLoggedInUserId(req)
|
||||
if (user_id != null) {
|
||||
return UserGetter.getUser(user_id, { signUpDate: 1 }, function(
|
||||
err,
|
||||
user
|
||||
) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
return UserGetter.getUser(
|
||||
user_id,
|
||||
{ signUpDate: 1 },
|
||||
function (err, user) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
currentUser = user
|
||||
return render()
|
||||
}
|
||||
currentUser = user
|
||||
return render()
|
||||
})
|
||||
)
|
||||
} else {
|
||||
return render()
|
||||
}
|
||||
@@ -81,68 +82,68 @@ module.exports = SubscriptionController = {
|
||||
if (!plan) {
|
||||
return HttpErrorHandler.unprocessableEntity(req, res, 'Plan not found')
|
||||
}
|
||||
return LimitationsManager.userHasV1OrV2Subscription(user, function(
|
||||
err,
|
||||
hasSubscription
|
||||
) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
if (hasSubscription) {
|
||||
return res.redirect('/user/subscription?hasSubscription=true')
|
||||
} else {
|
||||
// LimitationsManager.userHasV2Subscription only checks Mongo. Double check with
|
||||
// Recurly as well at this point (we don't do this most places for speed).
|
||||
return SubscriptionHandler.validateNoSubscriptionInRecurly(
|
||||
user._id,
|
||||
function(error, valid) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
if (!valid) {
|
||||
res.redirect('/user/subscription?hasSubscription=true')
|
||||
} else {
|
||||
let currency =
|
||||
req.query.currency != null
|
||||
? req.query.currency.toUpperCase()
|
||||
: undefined
|
||||
return GeoIpLookup.getCurrencyCode(
|
||||
(req.query != null ? req.query.ip : undefined) || req.ip,
|
||||
function(err, recomendedCurrency, countryCode) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
if (recomendedCurrency != null && currency == null) {
|
||||
currency = recomendedCurrency
|
||||
}
|
||||
return res.render('subscriptions/new', {
|
||||
title: 'subscribe',
|
||||
currency,
|
||||
countryCode,
|
||||
plan,
|
||||
showStudentPlan: req.query.ssp === 'true',
|
||||
recurlyConfig: JSON.stringify({
|
||||
return LimitationsManager.userHasV1OrV2Subscription(
|
||||
user,
|
||||
function (err, hasSubscription) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
if (hasSubscription) {
|
||||
return res.redirect('/user/subscription?hasSubscription=true')
|
||||
} else {
|
||||
// LimitationsManager.userHasV2Subscription only checks Mongo. Double check with
|
||||
// Recurly as well at this point (we don't do this most places for speed).
|
||||
return SubscriptionHandler.validateNoSubscriptionInRecurly(
|
||||
user._id,
|
||||
function (error, valid) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
if (!valid) {
|
||||
res.redirect('/user/subscription?hasSubscription=true')
|
||||
} else {
|
||||
let currency =
|
||||
req.query.currency != null
|
||||
? req.query.currency.toUpperCase()
|
||||
: undefined
|
||||
return GeoIpLookup.getCurrencyCode(
|
||||
(req.query != null ? req.query.ip : undefined) || req.ip,
|
||||
function (err, recomendedCurrency, countryCode) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
if (recomendedCurrency != null && currency == null) {
|
||||
currency = recomendedCurrency
|
||||
}
|
||||
return res.render('subscriptions/new', {
|
||||
title: 'subscribe',
|
||||
currency,
|
||||
subdomain: Settings.apis.recurly.subdomain
|
||||
}),
|
||||
showCouponField: !!req.query.scf,
|
||||
showVatField: !!req.query.svf,
|
||||
gaOptimize: true
|
||||
})
|
||||
}
|
||||
)
|
||||
countryCode,
|
||||
plan,
|
||||
showStudentPlan: req.query.ssp === 'true',
|
||||
recurlyConfig: JSON.stringify({
|
||||
currency,
|
||||
subdomain: Settings.apis.recurly.subdomain
|
||||
}),
|
||||
showCouponField: !!req.query.scf,
|
||||
showVatField: !!req.query.svf,
|
||||
gaOptimize: true
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
userSubscriptionPage(req, res, next) {
|
||||
const user = AuthenticationController.getSessionUser(req)
|
||||
return SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
||||
user,
|
||||
function(error, results) {
|
||||
function (error, results) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
@@ -155,31 +156,31 @@ module.exports = SubscriptionController = {
|
||||
managedPublishers,
|
||||
v1SubscriptionStatus
|
||||
} = results
|
||||
return LimitationsManager.userHasV1OrV2Subscription(user, function(
|
||||
err,
|
||||
hasSubscription
|
||||
) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
return LimitationsManager.userHasV1OrV2Subscription(
|
||||
user,
|
||||
function (err, hasSubscription) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
const fromPlansPage = req.query.hasSubscription
|
||||
const plans = SubscriptionViewModelBuilder.buildPlansList()
|
||||
const data = {
|
||||
title: 'your_subscription',
|
||||
plans,
|
||||
user,
|
||||
hasSubscription,
|
||||
fromPlansPage,
|
||||
personalSubscription,
|
||||
memberGroupSubscriptions,
|
||||
managedGroupSubscriptions,
|
||||
confirmedMemberAffiliations,
|
||||
managedInstitutions,
|
||||
managedPublishers,
|
||||
v1SubscriptionStatus
|
||||
}
|
||||
return res.render('subscriptions/dashboard', data)
|
||||
}
|
||||
const fromPlansPage = req.query.hasSubscription
|
||||
const plans = SubscriptionViewModelBuilder.buildPlansList()
|
||||
const data = {
|
||||
title: 'your_subscription',
|
||||
plans,
|
||||
user,
|
||||
hasSubscription,
|
||||
fromPlansPage,
|
||||
personalSubscription,
|
||||
memberGroupSubscriptions,
|
||||
managedGroupSubscriptions,
|
||||
confirmedMemberAffiliations,
|
||||
managedInstitutions,
|
||||
managedPublishers,
|
||||
v1SubscriptionStatus
|
||||
}
|
||||
return res.render('subscriptions/dashboard', data)
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
@@ -193,54 +194,54 @@ module.exports = SubscriptionController = {
|
||||
}
|
||||
const { subscriptionDetails } = req.body
|
||||
|
||||
return LimitationsManager.userHasV1OrV2Subscription(user, function(
|
||||
err,
|
||||
hasSubscription
|
||||
) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
if (hasSubscription) {
|
||||
logger.warn({ user_id: user._id }, 'user already has subscription')
|
||||
return res.sendStatus(409) // conflict
|
||||
}
|
||||
return SubscriptionHandler.createSubscription(
|
||||
user,
|
||||
subscriptionDetails,
|
||||
recurlyTokenIds,
|
||||
function(err) {
|
||||
if (!err) {
|
||||
return res.sendStatus(201)
|
||||
}
|
||||
|
||||
if (
|
||||
err instanceof SubscriptionErrors.RecurlyTransactionError ||
|
||||
err instanceof Errors.InvalidError
|
||||
) {
|
||||
logger.error({ err }, 'recurly transaction error, potential 422')
|
||||
return HttpErrorHandler.unprocessableEntity(
|
||||
req,
|
||||
res,
|
||||
err.message,
|
||||
OError.getFullInfo(err).public
|
||||
)
|
||||
}
|
||||
|
||||
logger.warn(
|
||||
{ err, user_id: user._id },
|
||||
'something went wrong creating subscription'
|
||||
)
|
||||
next(err)
|
||||
return LimitationsManager.userHasV1OrV2Subscription(
|
||||
user,
|
||||
function (err, hasSubscription) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
)
|
||||
})
|
||||
if (hasSubscription) {
|
||||
logger.warn({ user_id: user._id }, 'user already has subscription')
|
||||
return res.sendStatus(409) // conflict
|
||||
}
|
||||
return SubscriptionHandler.createSubscription(
|
||||
user,
|
||||
subscriptionDetails,
|
||||
recurlyTokenIds,
|
||||
function (err) {
|
||||
if (!err) {
|
||||
return res.sendStatus(201)
|
||||
}
|
||||
|
||||
if (
|
||||
err instanceof SubscriptionErrors.RecurlyTransactionError ||
|
||||
err instanceof Errors.InvalidError
|
||||
) {
|
||||
logger.error({ err }, 'recurly transaction error, potential 422')
|
||||
return HttpErrorHandler.unprocessableEntity(
|
||||
req,
|
||||
res,
|
||||
err.message,
|
||||
OError.getFullInfo(err).public
|
||||
)
|
||||
}
|
||||
|
||||
logger.warn(
|
||||
{ err, user_id: user._id },
|
||||
'something went wrong creating subscription'
|
||||
)
|
||||
next(err)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
successful_subscription(req, res, next) {
|
||||
const user = AuthenticationController.getSessionUser(req)
|
||||
return SubscriptionViewModelBuilder.buildUsersSubscriptionViewModel(
|
||||
user,
|
||||
function(error, { personalSubscription }) {
|
||||
function (error, { personalSubscription }) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
@@ -258,7 +259,7 @@ module.exports = SubscriptionController = {
|
||||
cancelSubscription(req, res, next) {
|
||||
const user = AuthenticationController.getSessionUser(req)
|
||||
logger.log({ user_id: user._id }, 'canceling subscription')
|
||||
return SubscriptionHandler.cancelSubscription(user, function(err) {
|
||||
return SubscriptionHandler.cancelSubscription(user, function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'something went wrong canceling subscription', {
|
||||
user_id: user._id
|
||||
@@ -281,7 +282,7 @@ module.exports = SubscriptionController = {
|
||||
cancelV1Subscription(req, res, next) {
|
||||
const user_id = AuthenticationController.getLoggedInUserId(req)
|
||||
logger.log({ user_id }, 'canceling v1 subscription')
|
||||
return V1SubscriptionManager.cancelV1Subscription(user_id, function(err) {
|
||||
return V1SubscriptionManager.cancelV1Subscription(user_id, function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'something went wrong canceling v1 subscription', {
|
||||
user_id
|
||||
@@ -310,7 +311,7 @@ module.exports = SubscriptionController = {
|
||||
user,
|
||||
planCode,
|
||||
null,
|
||||
function(err) {
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'something went wrong updating subscription', {
|
||||
user_id: user._id
|
||||
@@ -324,20 +325,22 @@ module.exports = SubscriptionController = {
|
||||
|
||||
updateAccountEmailAddress(req, res, next) {
|
||||
const user = AuthenticationController.getSessionUser(req)
|
||||
RecurlyWrapper.updateAccountEmailAddress(user._id, user.email, function(
|
||||
error
|
||||
) {
|
||||
if (error) {
|
||||
return next(error)
|
||||
RecurlyWrapper.updateAccountEmailAddress(
|
||||
user._id,
|
||||
user.email,
|
||||
function (error) {
|
||||
if (error) {
|
||||
return next(error)
|
||||
}
|
||||
res.sendStatus(200)
|
||||
}
|
||||
res.sendStatus(200)
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
reactivateSubscription(req, res, next) {
|
||||
const user = AuthenticationController.getSessionUser(req)
|
||||
logger.log({ user_id: user._id }, 'reactivating subscription')
|
||||
return SubscriptionHandler.reactivateSubscription(user, function(err) {
|
||||
return SubscriptionHandler.reactivateSubscription(user, function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'something went wrong reactivating subscription', {
|
||||
user_id: user._id
|
||||
@@ -363,7 +366,7 @@ module.exports = SubscriptionController = {
|
||||
return SubscriptionHandler.syncSubscription(
|
||||
recurlySubscription,
|
||||
{ ip: req.ip },
|
||||
function(err) {
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
@@ -374,7 +377,7 @@ module.exports = SubscriptionController = {
|
||||
const recurlyAccountCode = eventData.account.account_code
|
||||
return SubscriptionHandler.attemptPaypalInvoiceCollection(
|
||||
recurlyAccountCode,
|
||||
function(err) {
|
||||
function (err) {
|
||||
if (err) {
|
||||
return next(err)
|
||||
}
|
||||
@@ -388,36 +391,38 @@ module.exports = SubscriptionController = {
|
||||
|
||||
renderUpgradeToAnnualPlanPage(req, res, next) {
|
||||
const user = AuthenticationController.getSessionUser(req)
|
||||
return LimitationsManager.userHasV2Subscription(user, function(
|
||||
err,
|
||||
hasSubscription,
|
||||
subscription
|
||||
) {
|
||||
let planName
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
return LimitationsManager.userHasV2Subscription(
|
||||
user,
|
||||
function (err, hasSubscription, subscription) {
|
||||
let planName
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
const planCode =
|
||||
subscription != null ? subscription.planCode.toLowerCase() : undefined
|
||||
if (
|
||||
(planCode != null ? planCode.indexOf('annual') : undefined) !== -1
|
||||
) {
|
||||
planName = 'annual'
|
||||
} else if (
|
||||
(planCode != null ? planCode.indexOf('student') : undefined) !== -1
|
||||
) {
|
||||
planName = 'student'
|
||||
} else if (
|
||||
(planCode != null ? planCode.indexOf('collaborator') : undefined) !==
|
||||
-1
|
||||
) {
|
||||
planName = 'collaborator'
|
||||
}
|
||||
if (!hasSubscription) {
|
||||
return res.redirect('/user/subscription/plans')
|
||||
}
|
||||
return res.render('subscriptions/upgradeToAnnual', {
|
||||
title: 'Upgrade to annual',
|
||||
planName
|
||||
})
|
||||
}
|
||||
const planCode =
|
||||
subscription != null ? subscription.planCode.toLowerCase() : undefined
|
||||
if ((planCode != null ? planCode.indexOf('annual') : undefined) !== -1) {
|
||||
planName = 'annual'
|
||||
} else if (
|
||||
(planCode != null ? planCode.indexOf('student') : undefined) !== -1
|
||||
) {
|
||||
planName = 'student'
|
||||
} else if (
|
||||
(planCode != null ? planCode.indexOf('collaborator') : undefined) !== -1
|
||||
) {
|
||||
planName = 'collaborator'
|
||||
}
|
||||
if (!hasSubscription) {
|
||||
return res.redirect('/user/subscription/plans')
|
||||
}
|
||||
return res.render('subscriptions/upgradeToAnnual', {
|
||||
title: 'Upgrade to annual',
|
||||
planName
|
||||
})
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
processUpgradeToAnnualPlan(req, res, next) {
|
||||
@@ -433,7 +438,7 @@ module.exports = SubscriptionController = {
|
||||
user,
|
||||
annualPlanName,
|
||||
coupon_code,
|
||||
function(err) {
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
OError.tag(err, 'error updating subscription', {
|
||||
user_id: user._id
|
||||
@@ -447,29 +452,32 @@ module.exports = SubscriptionController = {
|
||||
|
||||
extendTrial(req, res, next) {
|
||||
const user = AuthenticationController.getSessionUser(req)
|
||||
return LimitationsManager.userHasV2Subscription(user, function(
|
||||
err,
|
||||
hasSubscription,
|
||||
subscription
|
||||
) {
|
||||
if (err != null) {
|
||||
return next(err)
|
||||
}
|
||||
return SubscriptionHandler.extendTrial(subscription, 14, function(err) {
|
||||
return LimitationsManager.userHasV2Subscription(
|
||||
user,
|
||||
function (err, hasSubscription, subscription) {
|
||||
if (err != null) {
|
||||
return res.sendStatus(500)
|
||||
} else {
|
||||
return res.sendStatus(200)
|
||||
return next(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
return SubscriptionHandler.extendTrial(
|
||||
subscription,
|
||||
14,
|
||||
function (err) {
|
||||
if (err != null) {
|
||||
return res.sendStatus(500)
|
||||
} else {
|
||||
return res.sendStatus(200)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
recurlyNotificationParser(req, res, next) {
|
||||
let xml = ''
|
||||
req.on('data', chunk => (xml += chunk))
|
||||
return req.on('end', () =>
|
||||
RecurlyWrapper._parseXml(xml, function(error, body) {
|
||||
RecurlyWrapper._parseXml(xml, function (error, body) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
@@ -481,7 +489,7 @@ module.exports = SubscriptionController = {
|
||||
|
||||
refreshUserFeatures(req, res, next) {
|
||||
const { user_id } = req.params
|
||||
return FeaturesUpdater.refreshFeatures(user_id, function(error) {
|
||||
return FeaturesUpdater.refreshFeatures(user_id, function (error) {
|
||||
if (error != null) {
|
||||
return next(error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user