Merge pull request #1061 from sharelatex/ja-remove-domain-license-code

Remove deprecated domain license code

GitOrigin-RevId: c9eebe1a657b07b69d618cdb5e73b64782109714
This commit is contained in:
Timothée Alby 2019-01-29 11:52:58 +00:00 committed by sharelatex
parent bc2ee419eb
commit 9a0dd31d8c
15 changed files with 1 additions and 405 deletions

View file

@ -6,19 +6,6 @@ settings = require "settings-sharelatex"
module.exports =
# Note: notification keys should be url-safe
groupPlan: (user, licence)->
key : "join-sub-#{licence.subscription_id}"
create: (callback = ->)->
messageOpts =
groupName: licence.name
subscription_id: licence.subscription_id
logger.log user_id:user._id, key:@key, "creating notification key for user"
NotificationsHandler.createNotification user._id, @key, "notification_group_invite", messageOpts, null, callback
read: (callback = ->)->
NotificationsHandler.markAsReadWithKey user._id, @key, callback
projectInvite: (invite, project, sendingUser, user) ->
key: "project-invite-#{invite._id}"
create: (callback=()->) ->

View file

@ -1,47 +0,0 @@
SubscriptionGroupHandler = require("./SubscriptionGroupHandler")
logger = require("logger-sharelatex")
SubscriptionLocator = require("./SubscriptionLocator")
ErrorsController = require("../Errors/ErrorController")
SubscriptionDomainHandler = require("./SubscriptionDomainHandler")
AuthenticationController = require('../Authentication/AuthenticationController')
TeamInvitesHandler = require('./TeamInvitesHandler')
async = require("async")
module.exports =
join: (req, res)->
user = AuthenticationController.getSessionUser(req)
licence = SubscriptionDomainHandler.getLicenceUserCanJoin(user)
if !licence?
return ErrorsController.notFound(req, res)
jobs =
partOfGroup: (cb)->
SubscriptionGroupHandler.isUserPartOfGroup user._id, licence.group_subscription_id, cb
subscription: (cb)->
SubscriptionLocator.getUsersSubscription user._id, cb
async.series jobs, (err, results)->
{ partOfGroup, subscription } = results
if partOfGroup
return res.redirect("/user/subscription/custom_account")
else
res.render "subscriptions/domain/join",
title: "Group Invitation"
group_subscription_id: licence.group_subscription_id
licenceName: licence.name
has_personal_subscription: subscription?
createInvite: (req, res, next)->
user = AuthenticationController.getSessionUser(req)
licence = SubscriptionDomainHandler.getLicenceUserCanJoin(user)
if !licence?
return ErrorsController.notFound(req, res)
TeamInvitesHandler.createDomainInvite user, licence, (err) ->
if err?
next(err)
else
res.sendStatus 200

View file

@ -7,7 +7,6 @@ RecurlyWrapper = require './RecurlyWrapper'
Settings = require 'settings-sharelatex'
logger = require('logger-sharelatex')
GeoIpLookup = require("../../infrastructure/GeoIpLookup")
SubscriptionDomainHandler = require("./SubscriptionDomainHandler")
UserGetter = require "../User/UserGetter"
FeaturesUpdater = require './FeaturesUpdater'
planFeatures = require './planFeatures'

View file

@ -1,30 +0,0 @@
async = require("async")
_ = require("underscore")
settings = require("settings-sharelatex")
module.exports = SubscriptionDomainHandler =
getLicenceUserCanJoin: (user)->
licence = SubscriptionDomainHandler._findDomainLicence(user.email)
return licence
getDomainLicencePage: (user)->
licence = SubscriptionDomainHandler._findDomainLicence(user.email)
if licence?.verifyEmail
return "/user/subscription/domain/join"
else
return undefined
_findDomainLicence: (email)->
licence = _.find settings.domainLicences, (licence)->
_.find licence.domains, (domain)->
regex = "[@\.]#{domain}"
return email.match(regex)
return licence
findDomainLicenceBySubscriptionId: (subscription_id)->
licence = _.find settings.domainLicences, (licence)->
licence?.subscription_id == subscription_id
return licence

View file

@ -1,7 +1,6 @@
AuthenticationController = require('../Authentication/AuthenticationController')
SubscriptionController = require('./SubscriptionController')
SubscriptionGroupController = require './SubscriptionGroupController'
DomainLicenceController = require './DomainLicenceController'
TeamInvitesController = require './TeamInvitesController'
RateLimiterMiddlewear = require('../Security/RateLimiterMiddlewear')
Settings = require "settings-sharelatex"
@ -34,17 +33,6 @@ module.exports =
}),
TeamInvitesController.acceptInvite
# Routes to join a domain licence team
webRouter.get '/user/subscription/domain/join', AuthenticationController.requireLogin(), DomainLicenceController.join
webRouter.post '/user/subscription/domain/join',
AuthenticationController.requireLogin(),
RateLimiterMiddlewear.rateLimit({
endpointName: 'join-domain-subscription',
maxRequests: 10
timeInterval: 60
}),
DomainLicenceController.createInvite
#recurly callback
publicApiRouter.post '/user/subscription/callback', SubscriptionController.recurlyNotificationParser, SubscriptionController.recurlyCallback

View file

@ -43,18 +43,6 @@ module.exports = TeamInvitesHandler =
return callback(error) if error?
createInvite(subscription, email, inviterName, callback)
createDomainInvite: (user, licence, callback) ->
email = EmailHelper.parseEmail(user.email)
return callback(new Error('invalid email')) if !email?
logger.log {licence, email: email}, "Creating domain team invite"
# If name == 'Uni of X License', make the email read only
# 'Uni of X has invited you...'
inviterName = licence.name.replace(/\s+(site\s+)?licence$/i, '')
SubscriptionLocator.getSubscription licence.subscription_id, (error, subscription) ->
return callback(error) if error?
createInvite(subscription, email, inviterName, callback)
importInvite: (subscription, inviterName, email, token, sentAt, callback) ->
checkIfInviteIsPossible subscription, email, (error, possible, reason) ->
return callback(error) if error?

View file

@ -1,31 +1,8 @@
SubscriptionDomainHandler = require("../Subscription/SubscriptionDomainHandler")
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
SubscriptionGroupHandler = require("../Subscription/SubscriptionGroupHandler")
TeamInvitesHandler = require("../Subscription/TeamInvitesHandler")
logger = require("logger-sharelatex")
module.exports = UserHandler =
populateTeamInvites: (user, callback) ->
UserHandler.notifyDomainLicence user, (err) ->
return callback(err) if err?
TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail(user.email, callback)
notifyDomainLicence: (user, callback = ->)->
logger.log user_id:user._id, "notiying user about a potential domain licence"
licence = SubscriptionDomainHandler.getLicenceUserCanJoin user
if !licence?
return callback()
SubscriptionGroupHandler.isUserPartOfGroup user._id, licence.subscription_id, (err, alreadyPartOfGroup)->
if err?
return callback(err)
else if alreadyPartOfGroup
logger.log user_id:user._id, "user already part of team, not creating notifcation for them"
return callback()
else
NotificationsBuilder.groupPlan(user, licence).create(callback)
TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail(user.email, callback)
setupLoginData: (user, callback = ->)->
@populateTeamInvites user, callback

View file

@ -26,16 +26,6 @@ span(ng-controller="NotificationsController").userNotifications
button(ng-click="dismiss(notification)").close.pull-right
span(aria-hidden="true") ×
span.sr-only #{translate("close")}
.alert.alert-info(ng-switch-when="notification_group_invite")
div.notification_inner
.notification_body
| #{translate("invited_to_join_team")}: {{ notification.messageOpts.groupName }}
a.pull-right.btn.btn-sm.btn-info(href="/user/subscription/domain/join")
| #{translate("join_team")}
span().notification_close
button(ng-click="dismiss(notification)").close.pull-right
span(aria-hidden="true") ×
span.sr-only #{translate("close")}
.alert.alert-info(ng-switch-when="notification_ip_matched_affiliation")
div.notification_inner
.notification_body

View file

@ -1,39 +0,0 @@
extends ../../layout
block scripts
script(type='text/javascript').
window.group_subscription_id = '#{group_subscription_id}'
window.has_personal_subscription = #{has_personal_subscription}
block content
.content.content-alt
.container
.row
.col-md-8.col-md-offset-2
-if (query.expired)
.alert.alert-warning #{translate("email_link_expired")}
.row.row-spaced
.col-md-8.col-md-offset-2.text-center(ng-cloak)
.card(ng-controller="DomainSubscriptionJoinController")
.page-header
h1.text-centered #{translate("you_are_invited_to_group", {groupName:licenceName})}
div(ng-show="view =='personalSubscription'")
p #{translate("cancel_personal_subscription_first")}
p
a.btn.btn.btn-default(ng-click="keepPersonalSubscription()", ng-disabled="inflight") #{translate("not_now")}
|  
a.btn.btn.btn-primary(ng-click="cancelSubscription()", ng-disabled="inflight") #{translate("cancel_your_subscription")}
div(ng-show="view =='domainSubscriptionJoin'")
p #{translate("group_provides_you_with_premium_account", {groupName:licenceName})}
p
a.btn.btn-default(href="/project") #{translate("not_now")}
|  
a.btn.btn.btn-primary(ng-click="joinGroup()", ng-disabled="inflight") #{translate("verify_email_address")}
div(ng-show="view =='requestSent'")
p #{translate("check_email_to_complete_the_upgrade")}
p
a.btn.btn.btn-primary(href="/project") #{translate("done")}

View file

@ -27,7 +27,6 @@ define([
'main/annual-upgrade',
'main/announcements',
'main/register-users',
'main/subscription/domain-subscription-join-controller',
'main/subscription/team-invite-controller',
'main/contact-us',
'main/learn',

View file

@ -1,55 +0,0 @@
/* eslint-disable
camelcase,
max-len,
no-return-assign,
no-undef,
*/
// 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
*/
define(['base'], App =>
App.controller('DomainSubscriptionJoinController', function($scope, $http) {
$scope.inflight = false
if (has_personal_subscription) {
$scope.view = 'personalSubscription'
} else {
$scope.view = 'domainSubscriptionJoin'
}
$scope.keepPersonalSubscription = () =>
($scope.view = 'domainSubscriptionJoin')
$scope.cancelSubscription = function() {
$scope.inflight = true
const request = $http.post('/user/subscription/cancel', {
_csrf: window.csrfToken
})
request.then(function() {
$scope.inflight = false
return ($scope.view = 'domainSubscriptionJoin')
})
return request.catch(() => console.log('the request failed'))
}
return ($scope.joinGroup = function() {
$scope.view = 'requestSent'
$scope.inflight = true
const request = $http.post('/user/subscription/domain/join', {
_csrf: window.csrfToken
})
request.then(function(response) {
const { status } = response
$scope.inflight = false
if (status !== 200) {
// assume request worked
return ($scope.requestSent = false)
}
})
return request.catch(() => console.log('the request failed'))
})
}))

View file

@ -59,8 +59,6 @@ describe "SubscriptionController", ->
gaExperiments:{}
@GeoIpLookup =
getCurrencyCode:sinon.stub()
@SubscriptionDomainHandler =
getDomainLicencePage:sinon.stub()
@UserGetter =
getUser: sinon.stub().callsArgWith(2, null, @user)
@SubscriptionController = SandboxedModule.require modulePath, requires:
@ -74,7 +72,6 @@ describe "SubscriptionController", ->
log:->
warn:->
"settings-sharelatex": @settings
"./SubscriptionDomainHandler":@SubscriptionDomainHandler
"../User/UserGetter": @UserGetter
"./RecurlyWrapper": @RecurlyWrapper = {}
"./FeaturesUpdater": @FeaturesUpdater = {}

View file

@ -1,56 +0,0 @@
should = require('chai').should()
SandboxedModule = require('sandboxed-module')
assert = require('assert')
path = require('path')
sinon = require('sinon')
modulePath = path.join __dirname, "../../../../app/js/Features/Subscription/SubscriptionDomainHandler"
expect = require("chai").expect
describe "SubscriptionDomainHandler", ->
beforeEach ->
@adminUser_id = 12345
@otherAdminUser_id = 32131231234
@ThirdOtherAdminUser_id = 33424324
@settings =
domainLicences: [
{domains:["uni.edu", "student.uni.edu"], adminUser_id:@adminUser_id}
{domains:["student.myuni.com", "teacher.myuni.com"], adminUser_id:@otherAdminUser_id}
{domains:["highcools.site"], adminUser_id:@ThirdOtherAdminUser_id}
]
@SubscriptionGroupHandler =
addUserToGroup: sinon.stub().callsArg(2)
@SubscriptionDomainHandler = SandboxedModule.require modulePath, requires:
"settings-sharelatex":@settings
"logger-sharelatex": log:->
"./SubscriptionGroupHandler": @SubscriptionGroupHandler
describe "_findDomainLicence", ->
it "should find the domain", (done)->
licence = @SubscriptionDomainHandler._findDomainLicence "bob@uni.edu"
licence.adminUser_id.should.equal @adminUser_id
done()
it "should find the if email is subdomain", (done)->
licence = @SubscriptionDomainHandler._findDomainLicence "bob@somewherelse.highcools.site"
licence.adminUser_id.should.equal @ThirdOtherAdminUser_id
done()
it "should find one of the other emails in the domain list", (done)->
licence = @SubscriptionDomainHandler._findDomainLicence "sally@teacher.myuni.com"
licence.adminUser_id.should.equal @otherAdminUser_id
done()
it "should return undefined if no licence matches even if end of email is same", (done)->
licence = @SubscriptionDomainHandler._findDomainLicence "bob@someotherhighcools.site"
expect(licence).to.not.exist
done(licence)
it "should return undefined if no licence matches", (done)->
licence = @SubscriptionDomainHandler._findDomainLicence "bob@other.edu"
expect(licence).to.not.exist
done(licence)

View file

@ -147,56 +147,6 @@ describe "TeamInvitesHandler", ->
).should.eq true
done()
describe "createDomainInvite", ->
beforeEach ->
@licence =
subscription_id: @subscription.id
name: "Team Daenerys"
@user =
email: "John.Snow@example.com"
it "adds the team invite to the subscription", (done) ->
@TeamInvitesHandler.createDomainInvite @user, @licence, (err, invite) =>
expect(err).to.eq(null)
expect(invite.token).to.eq(@newToken)
expect(invite.email).to.eq("john.snow@example.com")
expect(invite.inviterName).to.eq("Team Daenerys")
expect(@subscription.teamInvites).to.deep.include(invite)
done()
it "sends an email", (done) ->
@TeamInvitesHandler.createDomainInvite @user, @licence, (err, invite) =>
@EmailHandler.sendEmail.calledWith("verifyEmailToJoinTeam",
sinon.match({
to: "john.snow@example.com"
inviterName: "Team Daenerys"
acceptInviteUrl: "http://example.com/subscription/invites/#{@newToken}/"
})
).should.equal true
done()
it "stripe licence from name", (done) ->
@licence.name = 'Foo Licence'
@TeamInvitesHandler.createDomainInvite @user, @licence, (err, invite) =>
@EmailHandler.sendEmail.calledWith("verifyEmailToJoinTeam",
sinon.match({
inviterName: 'Foo'
})
).should.equal true
done()
it "stripe site licence from name", (done) ->
@licence.name = 'Foo Site Licence'
@TeamInvitesHandler.createDomainInvite @user, @licence, (err, invite) =>
@EmailHandler.sendEmail.calledWith("verifyEmailToJoinTeam",
sinon.match({
inviterName: 'Foo'
})
).should.equal true
done()
describe "importInvite", ->
beforeEach ->
@sentAt = new Date()

View file

@ -12,69 +12,17 @@ describe "UserHandler", ->
email: "bob@bob.com"
remove: sinon.stub().callsArgWith(0)
@licence =
subscription_id: 12323434
@SubscriptionDomainHandler =
getLicenceUserCanJoin: sinon.stub()
@SubscriptionGroupHandler =
isUserPartOfGroup:sinon.stub()
@createStub = sinon.stub().callsArgWith(0)
@NotificationsBuilder =
groupPlan:sinon.stub().returns({create:@createStub})
@TeamInvitesHandler =
createTeamInvitesForLegacyInvitedEmail: sinon.stub().yields()
@UserHandler = SandboxedModule.require modulePath, requires:
"logger-sharelatex": @logger = { log: sinon.stub() }
"../Notifications/NotificationsBuilder":@NotificationsBuilder
"../Subscription/SubscriptionDomainHandler":@SubscriptionDomainHandler
"../Subscription/SubscriptionGroupHandler":@SubscriptionGroupHandler
"../Subscription/TeamInvitesHandler": @TeamInvitesHandler
describe "populateTeamInvites", ->
beforeEach (done)->
@UserHandler.notifyDomainLicence = sinon.stub().yields()
@UserHandler.populateTeamInvites @user, done
it "notifies the user about domain licences zzzzz", ->
@UserHandler.notifyDomainLicence.calledWith(@user).should.eq true
it "notifies the user about legacy team invites", ->
@TeamInvitesHandler.createTeamInvitesForLegacyInvitedEmail
.calledWith(@user.email).should.eq true
describe "notifyDomainLicence", ->
describe "no licence", ->
beforeEach (done)->
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns()
@UserHandler.populateTeamInvites @user, done
it "should not call NotificationsBuilder", (done)->
@NotificationsBuilder.groupPlan.called.should.equal false
done()
it "should not call isUserPartOfGroup", (done)->
@SubscriptionGroupHandler.isUserPartOfGroup.called.should.equal false
done()
describe "with matching licence user is not in", ->
beforeEach (done)->
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns(@licence)
@SubscriptionGroupHandler.isUserPartOfGroup.callsArgWith(2, null, false)
@UserHandler.populateTeamInvites @user, done
it "should create notifcation", (done)->
@NotificationsBuilder.groupPlan.calledWith(@user, @licence).should.equal true
done()
describe "with matching licence user is already in", ->
beforeEach (done)->
@SubscriptionDomainHandler.getLicenceUserCanJoin.returns(@licence)
@SubscriptionGroupHandler.isUserPartOfGroup.callsArgWith(2, null, true)
@UserHandler.populateTeamInvites @user, done
it "should create notifcation", (done)->
@NotificationsBuilder.groupPlan.called.should.equal false
done()