Merge pull request #853 from sharelatex/ta-institution-features-fix

Check Institution Confirmation Status
This commit is contained in:
Timothée Alby 2018-08-28 14:03:22 +02:00 committed by GitHub
commit 946726c898
3 changed files with 17 additions and 7 deletions

View file

@ -7,7 +7,7 @@ module.exports = InstitutionsGetter =
return callback error if error? return callback error if error?
confirmedInstitutions = emailsData.filter (emailData) -> confirmedInstitutions = emailsData.filter (emailData) ->
emailData.confirmedAt? and emailData.affiliation?.institution? emailData.confirmedAt? and emailData.affiliation?.institution?.confirmed
.map (emailData) -> .map (emailData) ->
emailData.affiliation?.institution emailData.affiliation?.institution

View file

@ -89,22 +89,31 @@ describe "FeatureUpdater.refreshFeatures", ->
@institutionPlan = settings.plans.find (plan) -> @institutionPlan = settings.plans.find (plan) ->
plan.planCode == settings.institutionPlanCode plan.planCode == settings.institutionPlanCode
@email = @user.emails[0].email @email = @user.emails[0].email
affiliationData = @affiliationData =
email: @email email: @email
institution: { licence: 'pro_plus' } institution: { licence: 'pro_plus', confirmed: true }
MockV1Api.setAffiliations [affiliationData]
it "should not set their features if email is not confirmed", (done) -> it "should not set their features if email is not confirmed", (done) ->
MockV1Api.setAffiliations [@affiliationData]
syncUserAndGetFeatures @user, (error, features) => syncUserAndGetFeatures @user, (error, features) =>
expect(features).to.deep.equal(settings.defaultFeatures) expect(features).to.deep.equal(settings.defaultFeatures)
done() done()
it "should set their features if email is confirmed", (done) -> it "should set their features if email is confirmed", (done) ->
MockV1Api.setAffiliations [@affiliationData]
@user.confirmEmail @email, (error) => @user.confirmEmail @email, (error) =>
syncUserAndGetFeatures @user, (error, features) => syncUserAndGetFeatures @user, (error, features) =>
expect(features).to.deep.equal(@institutionPlan.features) expect(features).to.deep.equal(@institutionPlan.features)
done() done()
it "should not set their features if institution is not confirmed", (done) ->
@affiliationData.institution.confirmed = false
MockV1Api.setAffiliations [@affiliationData]
@user.confirmEmail @email, (error) =>
syncUserAndGetFeatures @user, (error, features) =>
expect(features).to.deep.equal(settings.defaultFeatures)
done()
describe "when the user is due bonus features and has extra features that no longer apply", -> describe "when the user is due bonus features and has extra features that no longer apply", ->
beforeEach -> beforeEach ->
User.update { User.update {

View file

@ -16,12 +16,13 @@ describe 'InstitutionsGetter', ->
@userId = '12345abcde' @userId = '12345abcde'
describe "getConfirmedInstitutions", -> describe "getConfirmedInstitutions", ->
it 'filters unconfirmed emails', (done) -> it 'filters unconfirmed affiliations', (done) ->
@userEmails = [ @userEmails = [
{ confirmedAt: null, affiliation: institution: { id: 123 } } { confirmedAt: null, affiliation: institution: { id: 123, confirmed: true } }
{ confirmedAt: new Date(), affiliation: institution: { id: 456 } } { confirmedAt: new Date(), affiliation: institution: { id: 456, confirmed: true } }
{ confirmedAt: new Date(), affiliation: null } { confirmedAt: new Date(), affiliation: null }
{ confirmedAt: new Date(), affiliation: institution: null } { confirmedAt: new Date(), affiliation: institution: null }
{ confirmedAt: new Date(), affiliation: institution: { id: 789, confirmed: false } }
] ]
@UserGetter.getUserFullEmails.yields(null, @userEmails) @UserGetter.getUserFullEmails.yields(null, @userEmails)
@InstitutionsGetter.getConfirmedInstitutions @userId, (error, institutions) -> @InstitutionsGetter.getConfirmedInstitutions @userId, (error, institutions) ->