Merge pull request #1569 from sharelatex/hb-v2-metrics-email-opt-out

v2 metrics email opt out and last sent tracking

GitOrigin-RevId: d45ac653c26e780dc380883c0ac1da7436bf8c2b
This commit is contained in:
Hugh O'Brien 2019-03-01 14:44:00 +00:00 committed by James Allen
parent 9b6ac8f715
commit 491c29bad1
3 changed files with 47 additions and 0 deletions

View file

@ -8,6 +8,10 @@ request = require 'request'
InstitutionSchema = new Schema
v1Id: { type: Number, required: true }
managerIds: [ type:ObjectId, ref:'User' ]
metricsEmail: {
optedOutUserIds: [ type:ObjectId, ref:'User' ]
lastSent: { type : Date }
}
# fetch institution's data from v1 API. Errors are ignored
InstitutionSchema.method 'fetchV1Data', (callback = (error, institution)->) ->

View file

@ -1,3 +1,6 @@
script(type='text/javascript').
window.managedInstitutions = !{JSON.stringify(managedInstitutions)}
each institution in managedInstitutions
p
| You are a manager of
@ -18,4 +21,10 @@ each institution in managedInstitutions
i.fa.fa-fw.fa-users
|  
| Manage institution managers
div(ng-controller="MetricsEmailController", ng-cloak)
p
span Monthly metrics emails:
a(ng-bind-html="institutionEmailSubscription('"+institution.v1Id+"')" ng-show="!subscriptionChanging" ng-click="changeInstitutionalEmailSubscription('"+institution.v1Id+"')")
span(ng-show="subscriptionChanging")
i.fa.fa-spin.fa-refresh(aria-hidden="true")
hr

View file

@ -23,6 +23,40 @@ define(['base'], function(App) {
recurly.configure(window.recurlyApiKey)
})
App.controller('MetricsEmailController', function($scope, $http) {
$scope.institutionEmailSubscription = function(institutionId) {
var inst = _.find(window.managedInstitutions, function(institution) {
return institution.v1Id === parseInt(institutionId)
})
if (inst.metricsEmail.optedOutUserIds.includes(window.user_id)) {
return 'Subscribe'
} else {
return 'Unsubscribe'
}
}
$scope.changeInstitutionalEmailSubscription = function(institutionId) {
$scope.subscriptionChanging = true
return $http({
method: 'POST',
url: `/institutions/${institutionId}/emailSubscription`,
headers: {
'X-CSRF-Token': window.csrfToken
}
}).then(function successCallback(response) {
window.managedInstitutions = _.map(window.managedInstitutions, function(
institution
) {
if (institution.v1Id === parseInt(institutionId)) {
institution.metricsEmail.optedOutUserIds = response.data
}
return institution
})
$scope.subscriptionChanging = false
})
}
})
App.factory('RecurlyPricing', function($q, MultiCurrencyPricing) {
return {
loadDisplayPriceWithTax: function(planCode, currency, taxRate) {