diff --git a/app/assets/javascripts/discourse/controllers/user-dropdown.js.es6 b/app/assets/javascripts/discourse/controllers/user-dropdown.js.es6
index 3413e61f276..203ada0b3ee 100644
--- a/app/assets/javascripts/discourse/controllers/user-dropdown.js.es6
+++ b/app/assets/javascripts/discourse/controllers/user-dropdown.js.es6
@@ -1,6 +1,8 @@
export default Ember.ArrayController.extend(Discourse.HasCurrentUser, {
showAdminLinks: Em.computed.alias("currentUser.staff"),
+ showBookmarksLink: Em.computed.alias("currentUser.hasBookmark"),
+
actions: {
logout: function() {
Discourse.logout();
diff --git a/app/assets/javascripts/discourse/controllers/user.js.es6 b/app/assets/javascripts/discourse/controllers/user.js.es6
index e446f5957f7..05e7527ec79 100644
--- a/app/assets/javascripts/discourse/controllers/user.js.es6
+++ b/app/assets/javascripts/discourse/controllers/user.js.es6
@@ -32,5 +32,3 @@ export default Discourse.ObjectController.extend({
privateMessagesUnreadActive: Em.computed.equal('pmView', 'unread')
});
-
-
diff --git a/app/assets/javascripts/discourse/models/user.js b/app/assets/javascripts/discourse/models/user.js
index 4d1b1fd3137..8764f21434c 100644
--- a/app/assets/javascripts/discourse/models/user.js
+++ b/app/assets/javascripts/discourse/models/user.js
@@ -11,6 +11,7 @@ Discourse.User = Discourse.Model.extend({
hasPMs: Em.computed.gt("private_messages_stats.all", 0),
hasStartedPMs: Em.computed.gt("private_messages_stats.mine", 0),
hasUnreadPMs: Em.computed.gt("private_messages_stats.unread", 0),
+ hasBookmark: Em.computed.gt('bookmarks_count', 0),
/**
The user's stream
@@ -288,7 +289,6 @@ Discourse.User = Discourse.Model.extend({
return this.get('stats').rejectProperty('isPM');
}.property('stats.@each.isPM'),
-
findDetails: function() {
var user = this;
diff --git a/app/assets/javascripts/discourse/models/user_action_stat.js b/app/assets/javascripts/discourse/models/user_action_stat.js
index f0584bca8f3..7a73d3bca95 100644
--- a/app/assets/javascripts/discourse/models/user_action_stat.js
+++ b/app/assets/javascripts/discourse/models/user_action_stat.js
@@ -24,5 +24,3 @@ Discourse.UserActionStat = Discourse.Model.extend({
}.property('action_type')
});
-
-
diff --git a/app/assets/javascripts/discourse/templates/user_dropdown.js.handlebars b/app/assets/javascripts/discourse/templates/user_dropdown.js.handlebars
index 5046e1bed44..569eb9020c5 100644
--- a/app/assets/javascripts/discourse/templates/user_dropdown.js.handlebars
+++ b/app/assets/javascripts/discourse/templates/user_dropdown.js.handlebars
@@ -9,6 +9,9 @@
{{#if currentUser.unread_private_messages}}{{currentUser.unread_private_messages}}{{/if}}{{i18n user.unread_message_count}}
{{/link-to}}
+ {{#if showBookmarksLink}}
+
{{#link-to 'userActivity.bookmarks' currentUser}}{{i18n user.bookmarks}}{{/link-to}}
+ {{/if}}
{{#link-to 'preferences' currentUser}}{{i18n user.preferences}}{{/link-to}}
diff --git a/app/models/user_action.rb b/app/models/user_action.rb
index e79f062997e..366db02ccff 100644
--- a/app/models/user_action.rb
+++ b/app/models/user_action.rb
@@ -85,6 +85,10 @@ SQL
{ all: all, mine: mine, unread: unread }
end
+ def self.bookmarks_stats(user_id)
+ UserAction.where(action_type: BOOKMARK, user_id: user_id).count
+ end
+
def self.stream_item(action_id, guardian)
stream(action_id: action_id, guardian: guardian).first
end
diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb
index 75824c96aed..5253a049505 100644
--- a/app/serializers/current_user_serializer.rb
+++ b/app/serializers/current_user_serializer.rb
@@ -10,6 +10,7 @@ class CurrentUserSerializer < BasicUserSerializer
:staff?,
:reply_count,
:topic_count,
+ :bookmarks_count,
:enable_quoting,
:external_links_in_new_tab,
:dynamic_favicon,
@@ -35,6 +36,10 @@ class CurrentUserSerializer < BasicUserSerializer
object.user_stat.topic_reply_count
end
+ def bookmarks_count
+ UserAction.bookmarks_stats(object.id)
+ end
+
def site_flagged_posts_count
PostAction.flagged_posts_count
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index eb075ba41c8..8bbc7eea033 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -249,6 +249,7 @@ en:
private_messages: "Messages"
activity_stream: "Activity"
preferences: "Preferences"
+ bookmarks: "Bookmarks"
bio: "About me"
invited_by: "Invited By"
trust_level: "Trust Level"
diff --git a/test/javascripts/controllers/user_dropdown_controller_test.js b/test/javascripts/controllers/user_dropdown_controller_test.js
index e1ef035b696..9a624ed61cd 100644
--- a/test/javascripts/controllers/user_dropdown_controller_test.js
+++ b/test/javascripts/controllers/user_dropdown_controller_test.js
@@ -1,4 +1,10 @@
-module("Discourse.UserDropdownController");
+var controller;
+
+module("controller:user-dropdown", {
+ setup: function() {
+ controller = testController('user-dropdown');
+ }
+});
test("logout action logs out the current user", function () {
var logout_mock = sinon.mock(Discourse, "logout");
@@ -14,10 +20,20 @@ test("showAdminLinks", function() {
var currentUserStub = Ember.Object.create();
this.stub(Discourse.User, "current").returns(currentUserStub);
- var controller = controllerFor('user-dropdown');
currentUserStub.set("staff", true);
equal(controller.get("showAdminLinks"), true, "is true when current user is a staff member");
currentUserStub.set("staff", false);
equal(controller.get("showAdminLinks"), false, "is false when current user is not a staff member");
});
+
+test("showBookmarksLink", function() {
+ var currentUserStub = Ember.Object.create();
+ this.stub(Discourse.User, "current").returns(currentUserStub);
+
+ currentUserStub.set("hasBookmark", true);
+ equal(controller.get("showBookmarksLink"), true, "is true when current user have bookmarks");
+
+ currentUserStub.set("hasBookmark", false);
+ equal(controller.get("showBookmarksLink"), false, "is false when current user does not have bookmarks");
+});