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

@@ -283,7 +283,15 @@ schema.methods.closeChal = async function closeChal (broken = {}) {
// Award prize to winner and notify
if (winner) {
winner.achievements.challenges.push(challenge.name);
winner.balance += challenge.prize / 4;
// If the winner cannot get gems (because of a group policy)
// reimburse the leader
const winnerCanGetGems = await winner.canGetGems();
if (!winnerCanGetGems) {
await User.update({_id: challenge.leader}, {$inc: {balance: challenge.prize / 4}}).exec();
} else {
winner.balance += challenge.prize / 4;
}
winner.addNotification('WON_CHALLENGE');