From 445bd033d2b8537152f4f5c719695a01f86863e6 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Thu, 24 Sep 2015 00:36:09 +0200 Subject: [PATCH] FIX: Use correct badge slug within notifications --- .../discourse/components/notification-item.js.es6 | 10 ++++++++-- app/services/badge_granter.rb | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/components/notification-item.js.es6 b/app/assets/javascripts/discourse/components/notification-item.js.es6 index 2aa93e141f4..8b4730074d3 100644 --- a/app/assets/javascripts/discourse/components/notification-item.js.es6 +++ b/app/assets/javascripts/discourse/components/notification-item.js.es6 @@ -22,8 +22,14 @@ export default Ember.Component.extend({ const it = this.get('notification'); const badgeId = it.get("data.badge_id"); if (badgeId) { - const badgeName = it.get("data.badge_name"); - return Discourse.getURL('/badges/' + badgeId + '/' + badgeName.replace(/[^A-Za-z0-9_]+/g, '-').toLowerCase()); + var badgeSlug = it.get("data.badge_slug"); + + if (!badgeSlug) { + const badgeName = it.get("data.badge_name"); + badgeSlug = badgeName.replace(/[^A-Za-z0-9_]+/g, '-').toLowerCase(); + } + + return Discourse.getURL('/badges/' + badgeId + '/' + badgeSlug); } const topicId = it.get('topic_id'); diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rb index 75c0f7ef58c..b6d964a6556 100644 --- a/app/services/badge_granter.rb +++ b/app/services/badge_granter.rb @@ -44,7 +44,7 @@ class BadgeGranter I18n.with_locale(@user.effective_locale) do notification = @user.notifications.create( notification_type: Notification.types[:granted_badge], - data: { badge_id: @badge.id, badge_name: @badge.display_name }.to_json) + data: { badge_id: @badge.id, badge_name: @badge.display_name, badge_slug: @badge.slug }.to_json) user_badge.update_attributes notification_id: notification.id end end