Groups can prevent members from getting gems (#8870)

* add possibility for group to block members from getting gems

* fixes

* fix tests

* adds some tests

* unit tests

* finish unit tests

* remove old code
This commit is contained in:
Matteo Pagliazzi
2017-07-16 18:23:57 +02:00
committed by Sabe Jones
parent fe9521a63f
commit 78ba596504
20 changed files with 339 additions and 16 deletions

View File

@@ -70,11 +70,15 @@ api.paypalBillingAgreementCancel = Bluebird.promisify(paypal.billingAgreement.ca
api.ipnVerifyAsync = Bluebird.promisify(ipn.verify, {context: ipn});
api.checkout = async function checkout (options = {}) {
let {gift} = options;
let {gift, user} = options;
let amount = 5.00;
let description = 'Habitica Gems';
if (gift) {
const member = await User.findById(gift.uuid).exec();
gift.member = member;
if (gift.type === 'gems') {
if (gift.gems.amount <= 0) {
throw new BadRequest(i18n.t('badAmountOfGemsToPurchase'));
@@ -87,6 +91,14 @@ api.checkout = async function checkout (options = {}) {
}
}
if (!gift || gift.type === 'gems') {
const receiver = gift ? gift.member : user;
const receiverCanGetGems = await receiver.canGetGems();
if (!receiverCanGetGems) throw new NotAuthorized(shared.i18n.t('groupPolicyCannotGetGems', receiver.preferences.language));
}
let createPayment = {
intent: 'sale',
payer: { payment_method: this.constants.PAYMENT_METHOD },