mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #1781 from overleaf/ta-institution-subscriptions
List Institution Subscriptions GitOrigin-RevId: b259b4729f031bb6a50b27f6740df3df21017818
This commit is contained in:
parent
efd7cf5b01
commit
004272619e
2 changed files with 30 additions and 0 deletions
|
@ -9,6 +9,7 @@ UserGetter = require('../User/UserGetter')
|
|||
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
|
||||
SubscriptionLocator = require("../Subscription/SubscriptionLocator")
|
||||
Institution = require("../../models/Institution").Institution
|
||||
Subscription = require("../../models/Subscription").Subscription
|
||||
|
||||
ASYNC_LIMIT = 10
|
||||
module.exports = InstitutionsManager =
|
||||
|
@ -33,6 +34,15 @@ module.exports = InstitutionsManager =
|
|||
callback(error, checkFeatures(users))
|
||||
)
|
||||
|
||||
getInstitutionUsersSubscriptions: (institutionId, callback = (error, subscriptions) ->) ->
|
||||
getInstitutionAffiliations institutionId, (error, affiliations) ->
|
||||
return callback(error) if error?
|
||||
userIds = affiliations.map (affiliation) -> ObjectId(affiliation.user_id)
|
||||
Subscription
|
||||
.find admin_id: userIds
|
||||
.populate 'admin_id', 'email'
|
||||
.exec callback
|
||||
|
||||
fetchInstitutionAndAffiliations = (institutionId, callback) ->
|
||||
async.waterfall [
|
||||
(cb) ->
|
||||
|
|
|
@ -29,6 +29,12 @@ describe "InstitutionsManager", ->
|
|||
@InstitutionModel =
|
||||
Institution:
|
||||
findOne: sinon.stub().callsArgWith(1, null, @institution)
|
||||
@subscriptionExec = sinon.stub().yields()
|
||||
SubscriptionModel =
|
||||
Subscription:
|
||||
find: () =>
|
||||
populate: () =>
|
||||
exec: @subscriptionExec
|
||||
@Mongo =
|
||||
ObjectId: sinon.stub().returnsArg(0)
|
||||
|
||||
|
@ -42,6 +48,7 @@ describe "InstitutionsManager", ->
|
|||
'../Notifications/NotificationsBuilder': @NotificationsBuilder
|
||||
'../Subscription/SubscriptionLocator': @SubscriptionLocator
|
||||
'../../models/Institution': @InstitutionModel
|
||||
"../../models/Subscription": SubscriptionModel
|
||||
'../../infrastructure/mongojs': @Mongo
|
||||
|
||||
describe 'upgradeInstitutionUsers', ->
|
||||
|
@ -115,3 +122,16 @@ describe "InstitutionsManager", ->
|
|||
usersSummary.totalConfirmedNonProUsers.should.equal 2
|
||||
expect(usersSummary.confirmedNonProUsers).to.deep.equal ['456def456def456def456def', '789def789def789def789def']
|
||||
done()
|
||||
|
||||
describe 'getInstitutionUsersSubscriptions', ->
|
||||
it 'returns all institution users subscriptions', (done) ->
|
||||
stubbedUsers = [
|
||||
{ user_id: '123abc123abc123abc123abc' }
|
||||
{ user_id: '456def456def456def456def' }
|
||||
{ user_id: '789def789def789def789def' }
|
||||
]
|
||||
@getInstitutionAffiliations.yields(null, stubbedUsers)
|
||||
@InstitutionsManager.getInstitutionUsersSubscriptions @institutionId, (error, subscriptions) =>
|
||||
should.not.exist(error)
|
||||
sinon.assert.calledOnce(@subscriptionExec)
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue