From e756d020881b3a60122bd76ac740e5aaae028c21 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 21 Dec 2017 11:23:45 +1100 Subject: [PATCH] FIX: create topic keyboard shortcut not checking permissions --- .../javascripts/discourse/lib/keyboard-shortcuts.js.es6 | 4 +++- app/serializers/current_user_serializer.rb | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 index b011f8bab06..c3a7ecd27ca 100644 --- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 +++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 @@ -169,7 +169,9 @@ export default { }, createTopic() { - this.container.lookup('controller:composer').open({action: Composer.CREATE_TOPIC, draftKey: Composer.CREATE_TOPIC}); + if (this.currentUser && this.currentUser.can_create_topic) { + this.container.lookup('controller:composer').open({action: Composer.CREATE_TOPIC, draftKey: Composer.CREATE_TOPIC}); + } }, pinUnpinTopic() { diff --git a/app/serializers/current_user_serializer.rb b/app/serializers/current_user_serializer.rb index c91ebef82cd..46fa8fe05ce 100644 --- a/app/serializers/current_user_serializer.rb +++ b/app/serializers/current_user_serializer.rb @@ -38,7 +38,12 @@ class CurrentUserSerializer < BasicUserSerializer :previous_visit_at, :seen_notification_id, :primary_group_id, - :primary_group_name + :primary_group_name, + :can_create_topic + + def can_create_topic + scope.can_create_topic?(nil) + end def include_site_flagged_posts_count? object.staff?