Merge pull request #2935 from overleaf/cmg-covid-upgrades

Add script for WFH offer ending

GitOrigin-RevId: b9291824a0712740d5d40439f759eb8a7d11d9ca
This commit is contained in:
Chrystal Maria Griffiths 2020-06-29 10:40:56 +01:00 committed by Copybot
parent 153a9c5790
commit 05abdd18d7
3 changed files with 92 additions and 4 deletions

View file

@ -40,9 +40,9 @@ include ../../_mixins/saml
ng-switch-when="wfh_2020_upgrade_offer"
)
.notification-body
span Good news! Your WFH2020 free upgrade is extended to June 30th 2020. We're also providing specially discounted annual plans to help you continue collaborating throughout 2020.
span Important notice: Your free WFH2020 upgrade is coming to an end on June 30th 2020. We're providing specially discounted annual plans to help you continue collaborating throughout 2020.
.notification-action
a.pull-right.btn.btn-sm.btn-info(href="https://www.overleaf.com/events/wfh2020") See options
a.pull-right.btn.btn-sm.btn-info(href="https://www.overleaf.com/events/wfh2020") Upgrade
.notification-close
button(ng-click="dismiss(notification)").close.pull-right
span(aria-hidden="true") ×

View file

@ -1,6 +1,6 @@
const NotificationsHandler = require('../app/src/Features/Notifications/NotificationsHandler')
const NotificationsHandler = require('../../app/src/Features/Notifications/NotificationsHandler')
const mongojs = require('../app/src/infrastructure/mongojs')
const mongojs = require('../../app/src/infrastructure/mongojs')
const { db } = mongojs
const async = require('async')

View file

@ -0,0 +1,88 @@
const NotificationsHandler = require('../../app/src/Features/Notifications/NotificationsHandler')
const mongojs = require('../../app/src/infrastructure/mongojs')
const { db } = mongojs
const async = require('async')
const templateKey = 'wfh_2020_upgrade_offer'
const oldKey = 'wfh-2020-upgrade-2020-06-01'
const key = 'wfh-2020-upgrade-2020-06-18'
db.subscriptions.aggregate(
{ $match: { teamName: /(Work From Home|Work from Home)/ } },
{ $unwind: '$member_ids' },
{ $group: { _id: null, memberIds: { $addToSet: '$member_ids' } } },
function(err, results) {
if (err) {
throw err
}
const userIds = results[0].memberIds
async.eachLimit(
userIds,
10,
function(userId, callback) {
async.series(
[
function(cb) {
db.notifications.findOne(
{ user_id: userId, key: oldKey },
function(err, notification) {
if (err) {
console.log('Error finding notification for ' + userId)
cb(err)
} else if (!notification) {
cb()
} else {
if (notification.templateKey && notification.messageOpts) {
db.notifications.update(
{
_id: notification._id
},
{
$unset: { templateKey: true, messageOpts: true }
},
cb
)
} else {
cb()
}
}
}
)
},
function(cb) {
NotificationsHandler.createNotification(
userId,
key,
templateKey,
{},
null,
true,
cb
)
}
],
function(err) {
if (err) {
callback(err)
} else {
console.log('Notification created for user ' + userId)
callback()
}
}
)
},
function(err) {
if (err) {
console.log(err)
process.exit(1)
} else {
console.log('Done')
process.exit(0)
}
}
)
}
)