diff --git a/app/assets/javascripts/discourse/widgets/topic-admin-menu.js.es6 b/app/assets/javascripts/discourse/widgets/topic-admin-menu.js.es6 index 212d549d42d..003de97cead 100644 --- a/app/assets/javascripts/discourse/widgets/topic-admin-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/topic-admin-menu.js.es6 @@ -177,7 +177,7 @@ export default createWidget('topic-admin-menu', { icon: visible ? 'eye-slash' : 'eye', label: visible ? 'actions.invisible' : 'actions.visible' }); - if (this.currentUser.get('staff')) { + if (details.get('can_convert_topic')) { buttons.push({ className: 'topic-admin-convert', action: isPrivateMessage ? 'convertToPublicTopic' : 'convertToPrivateMessage', icon: isPrivateMessage ? 'comment' : 'envelope', diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb index ab1068e4a51..c5ccc917894 100644 --- a/app/serializers/topic_view_serializer.rb +++ b/app/serializers/topic_view_serializer.rb @@ -118,6 +118,7 @@ class TopicViewSerializer < ApplicationSerializer result[:can_create_post] = true if scope.can_create?(Post, object.topic) result[:can_reply_as_new_topic] = true if scope.can_reply_as_new_topic?(object.topic) result[:can_flag_topic] = actions_summary.any? { |a| a[:can_act] } + result[:can_convert_topic] = true if scope.can_convert_topic?(object.topic) result end diff --git a/lib/guardian/topic_guardian.rb b/lib/guardian/topic_guardian.rb index 8b8f08a12d0..b8db72d3158 100644 --- a/lib/guardian/topic_guardian.rb +++ b/lib/guardian/topic_guardian.rb @@ -63,7 +63,9 @@ module TopicGuardian end def can_convert_topic?(topic) + return false if topic.blank? return false if topic && topic.trashed? + return false if Category.where("topic_id = ?", topic.id).exists? return true if is_admin? is_moderator? && can_create_post?(topic) end diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 9b43ac97651..82ee29609a3 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -996,6 +996,12 @@ describe Guardian do expect(Guardian.new(trust_level_4).can_convert_topic?(topic)).to be_falsey end + it 'returns false for category definition topics' do + c = Fabricate(:category) + topic = Topic.find_by(id: c.topic_id) + expect(Guardian.new(admin).can_convert_topic?(topic)).to be_falsey + end + it 'returns true when a moderator' do expect(Guardian.new(moderator).can_convert_topic?(topic)).to be_truthy end