From a7069e19bda6d67973e09681c4afb7ce46448ec8 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Mon, 17 Nov 2014 08:44:53 -0800 Subject: [PATCH] Ignore (and warn about) achievements with empty queries. Fixed embarrassing bug with more-practice / skip-ahead branching not doing anything for non-admins. --- app/views/play/level/modal/HeroVictoryModal.coffee | 4 ++-- server/achievements/earned_achievement_handler.coffee | 5 +++-- server/plugins/achievements.coffee | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/play/level/modal/HeroVictoryModal.coffee b/app/views/play/level/modal/HeroVictoryModal.coffee index 85d5991f1..6e16c442e 100644 --- a/app/views/play/level/modal/HeroVictoryModal.coffee +++ b/app/views/play/level/modal/HeroVictoryModal.coffee @@ -116,8 +116,8 @@ module.exports = class HeroVictoryModal extends ModalView c.readyToRank = @level.get('type', true) is 'hero-ladder' and @session.readyToRank() c.level = @level @continueLevelLink = @getNextLevelLink 'continue' - @morePracticeLevelLink = me.isAdmin() and @getNextLevelLink 'more_practice' - @skipAheadLevelLink = me.isAdmin() and @getNextLevelLink 'skip_ahead' + @morePracticeLevelLink = @getNextLevelLink 'more_practice' + @skipAheadLevelLink = @getNextLevelLink 'skip_ahead' c.continueButtons = [ {key: 'skip_ahead', link: @skipAheadLevelLink, 'choice-explicit': 'skip', 'choice-implicit': 'too_easy'} {key: 'continue', link: @continueLevelLink, 'choice-explicit': 'next_level', 'choice-implicit': 'just_right'} diff --git a/server/achievements/earned_achievement_handler.coffee b/server/achievements/earned_achievement_handler.coffee index 4c7cc979f..e39e1dd4c 100644 --- a/server/achievements/earned_achievement_handler.coffee +++ b/server/achievements/earned_achievement_handler.coffee @@ -23,12 +23,12 @@ class EarnedAchievementHandler extends Handler ids = req.query.achievementIDs if (not ids) or (ids.length is 0) return @sendBadInputError(res, 'For a get-by-achievement-ids request, need to provide ids.') - + ids = ids.split(',') for id in ids if not Handler.isID(id) return @sendBadInputError(res, "Not a MongoDB ObjectId: #{id}") - + query.achievement = {$in: ids} EarnedAchievement.find query, (err, earnedAchievements) -> return @sendDatabaseError(res, err) if err @@ -121,6 +121,7 @@ class EarnedAchievementHandler extends Handler return doneWithAchievement new Error "Model with collection '#{achievement.get 'collection'}' doesn't exist." unless model? finalQuery = _.clone achievement.get 'query' + return doneWithAchievement() if _.isEmpty finalQuery finalQuery.$or = [{}, {}] # Allow both ObjectIDs or hex string IDs finalQuery.$or[0][achievement.userField] = userID finalQuery.$or[1][achievement.userField] = mongoose.Types.ObjectId userID diff --git a/server/plugins/achievements.coffee b/server/plugins/achievements.coffee index b252981e4..c29d25374 100644 --- a/server/plugins/achievements.coffee +++ b/server/plugins/achievements.coffee @@ -36,6 +36,7 @@ AchievablePlugin = (schema, options) -> for achievement in loadedAchievements[category] do (achievement) -> query = achievement.get('query') + return log.warn("Empty achievement query for #{achievement.get('name')}.") if _.isEmpty query isRepeatable = achievement.get('proportionalTo')? alreadyAchieved = if isNew then false else LocalMongo.matchesQuery originalDocObj, query newlyAchieved = LocalMongo.matchesQuery(docObj, query)