From d7ea6f93e741efd6508a84bab4b25637d5f54fbf Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 9 Apr 2018 14:27:00 -0400 Subject: [PATCH] FIX: preference page error when badges are disabled --- .../discourse/routes/preferences-account.js.es6 | 12 ++++++++---- .../acceptance/preferences-test.js.es6 | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/routes/preferences-account.js.es6 b/app/assets/javascripts/discourse/routes/preferences-account.js.es6 index b5e574c7728..29200b6fd11 100644 --- a/app/assets/javascripts/discourse/routes/preferences-account.js.es6 +++ b/app/assets/javascripts/discourse/routes/preferences-account.js.es6 @@ -6,10 +6,14 @@ export default RestrictedUserRoute.extend({ model: function() { const user = this.modelFor('user'); - return UserBadge.findByUsername(this.modelFor('user').get('username')).then(userBadges => { - user.set('badges', userBadges.map(ub => ub.badge)); - return user; - }); + if (this.siteSettings.enable_badges) { + return UserBadge.findByUsername(this.modelFor('user').get('username')).then(userBadges => { + user.set('badges', userBadges.map(ub => ub.badge)); + return user; + }); + } else { + return user; + } }, setupController(controller, user) { diff --git a/test/javascripts/acceptance/preferences-test.js.es6 b/test/javascripts/acceptance/preferences-test.js.es6 index 5176eed55cd..ac9dd14529d 100644 --- a/test/javascripts/acceptance/preferences-test.js.es6 +++ b/test/javascripts/acceptance/preferences-test.js.es6 @@ -121,3 +121,19 @@ QUnit.test("second factor", assert => { ); }); }); + +acceptance("User Preferences when badges are disabled", { + loggedIn: true, + settings: { + enable_badges: false + } +}); + +QUnit.test("visit my preferences", assert => { + visit("/u/eviltrout/preferences"); + andThen(() => { + assert.ok($('body.user-preferences-page').length, "has the body class"); + assert.equal(currentURL(), '/u/eviltrout/preferences/account', "defaults to account tab"); + assert.ok(exists('.user-preferences'), 'it shows the preferences'); + }); +}); \ No newline at end of file