Merge pull request #567 from sharelatex/ja-admin-panel-additions

Some refactoring and methods needed to support the admin panel
This commit is contained in:
James Allen 2017-08-03 10:34:33 +02:00 committed by GitHub
commit 28838eff60
3 changed files with 46 additions and 0 deletions

View file

@ -62,6 +62,15 @@ module.exports = SubscriptionUpdater =
invited_emails: email
}, callback
deleteSubscription: (subscription_id, callback = (error) ->) ->
SubscriptionLocator.getSubscription subscription_id, (err, subscription) ->
return callback(err) if err?
affected_user_ids = [subscription.admin_id].concat(subscription.member_ids or [])
logger.log {subscription_id, affected_user_ids}, "deleting subscription and downgrading users"
Subscription.remove {_id: ObjectId(subscription_id)}, (err) ->
return callback(err) if err?
async.mapSeries affected_user_ids, SubscriptionUpdater._setUsersMinimumFeatures, callback
_createNewSubscription: (adminUser_id, callback)->
logger.log adminUser_id:adminUser_id, "creating new subscription"
subscription = new Subscription(admin_id:adminUser_id)

View file

@ -225,6 +225,10 @@
// Hide tabbable panes to start, show them when `.active`
.tab-content {
background-color: @nav-tabs-active-link-hover-bg;
border: 1px solid @nav-tabs-border-color;
border-top: none;
padding: @line-height-computed / 2;
> .tab-pane {
display: none;
}

View file

@ -37,6 +37,7 @@ describe "SubscriptionUpdater", ->
constructor: (opts)->
subscription.admin_id = opts.admin_id
return subscription
@remove: sinon.stub().yields()
@SubscriptionModel.update = @updateStub
@SubscriptionModel.findAndModify = @findAndModifyStub
@ -230,3 +231,35 @@ describe "SubscriptionUpdater", ->
@ReferalAllocator.assignBonus.calledWith(@adminuser_id).should.equal true
done()
describe "deleteSubscription", ->
beforeEach (done) ->
@subscription_id = ObjectId().toString()
@subscription = {
"mock": "subscription",
admin_id: ObjectId(),
member_ids: [ ObjectId(), ObjectId(), ObjectId() ]
}
@SubscriptionLocator.getSubscription = sinon.stub().yields(null, @subscription)
@SubscriptionUpdater._setUsersMinimumFeatures = sinon.stub().yields()
@SubscriptionUpdater.deleteSubscription @subscription_id, done
it "should look up the subscription", ->
@SubscriptionLocator.getSubscription
.calledWith(@subscription_id)
.should.equal true
it "should remove the subscription", ->
@SubscriptionModel.remove
.calledWith({_id: ObjectId(@subscription_id)})
.should.equal true
it "should downgrade the admin_id", ->
@SubscriptionUpdater._setUsersMinimumFeatures
.calledWith(@subscription.admin_id)
.should.equal true
it "should downgrade all of the members", ->
for user_id in @subscription.member_ids
@SubscriptionUpdater._setUsersMinimumFeatures
.calledWith(user_id)
.should.equal true