Merge pull request #3809 from gschlager/patch1

FIX: Only enabled badges can be granted
This commit is contained in:
Régis Hanol 2015-09-24 09:45:54 +02:00
commit 3acb00c2a3
2 changed files with 9 additions and 6 deletions

View File

@ -56,12 +56,12 @@ export default Ember.ArrayController.extend({
var badges = []; var badges = [];
this.get('badges').forEach(function(badge) { this.get('badges').forEach(function(badge) {
if (badge.get('multiple_grant') || !granted[badge.get('id')]) { if (badge.get('enabled') && (badge.get('multiple_grant') || !granted[badge.get('id')])) {
badges.push(badge); badges.push(badge);
} }
}); });
return _.sortBy(badges, "name"); return _.sortBy(badges, badge => badge.get('displayName'));
}.property('badges.@each', 'model.@each'), }.property('badges.@each', 'model.@each'),
/** /**

View File

@ -5,14 +5,17 @@ moduleFor('controller:admin-user-badges', {
}); });
test("grantableBadges", function() { test("grantableBadges", function() {
const badgeFirst = Badge.create({id: 3, name: "A Badge"}); const badgeFirst = Badge.create({id: 3, name: "A Badge", enabled: true});
const badgeMiddle = Badge.create({id: 1, name: "My Badge"}); const badgeMiddle = Badge.create({id: 1, name: "My Badge", enabled: true});
const badgeLast = Badge.create({id: 2, name: "Zoo Badge"}); const badgeLast = Badge.create({id: 2, name: "Zoo Badge", enabled: true});
const controller = this.subject({ badges: [badgeLast, badgeFirst, badgeMiddle] }); const badgeDisabled = Badge.create({id: 4, name: "Disabled Badge", enabled: false});
const controller = this.subject({ badges: [badgeLast, badgeFirst, badgeMiddle, badgeDisabled] });
const sortedNames = [badgeFirst.name, badgeMiddle.name, badgeLast.name]; const sortedNames = [badgeFirst.name, badgeMiddle.name, badgeLast.name];
const badgeNames = controller.get('grantableBadges').map(function(badge) { const badgeNames = controller.get('grantableBadges').map(function(badge) {
return badge.name; return badge.name;
}); });
not(badgeNames.contains(badgeDisabled), "excludes disabled badges");
deepEqual(badgeNames, sortedNames, "sorts badges by name"); deepEqual(badgeNames, sortedNames, "sorts badges by name");
}); });