{{/if}}
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb
index 7c617514e..16335f2e2 100644
--- a/app/controllers/topics_controller.rb
+++ b/app/controllers/topics_controller.rb
@@ -75,6 +75,7 @@ class TopicsController < ApplicationController
params.require(:best)
params.require(:topic_id)
params.permit(:min_trust_level, :min_score, :min_replies, :bypass_trust_level_score, :only_moderator_liked)
+
opts = { best: params[:best].to_i,
min_trust_level: params[:min_trust_level] ? 1 : params[:min_trust_level].to_i,
min_score: params[:min_score].to_i,
@@ -105,13 +106,9 @@ class TopicsController < ApplicationController
def update
topic = Topic.find_by(id: params[:topic_id])
- title, archetype = params[:title], params[:archetype]
guardian.ensure_can_edit!(topic)
- topic.title = params[:title] if title.present?
- # TODO: we may need smarter rules about converting archetypes
- topic.archetype = "regular" if current_user.admin? && archetype == 'regular'
-
+ topic.title = params[:title] if params[:title].present?
topic.acting_user = current_user
success = false
@@ -176,6 +173,32 @@ class TopicsController < ApplicationController
end
end
+ def make_banner
+ topic = Topic.find_by(id: params[:topic_id].to_i)
+ guardian.ensure_can_moderate!(topic)
+
+ # TODO: only one banner at the same time
+
+ topic.archetype = Archetype.banner
+ topic.add_moderator_post(current_user, I18n.t("archetypes.banner.message.make"))
+
+ topic.save
+
+ render nothing: true
+ end
+
+ def remove_banner
+ topic = Topic.find_by(id: params[:topic_id].to_i)
+ guardian.ensure_can_moderate!(topic)
+
+ topic.archetype = Archetype.default
+ topic.add_moderator_post(current_user, I18n.t("archetypes.banner.message.remove"))
+
+ topic.save
+
+ render nothing: true
+ end
+
def destroy
topic = Topic.find_by(id: params[:id])
guardian.ensure_can_delete!(topic)
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 946a2b32c..6ebca8c88 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -837,6 +837,8 @@ en:
open: "Open Topic"
close: "Close Topic"
auto_close: "Auto Close"
+ make_banner: "Banner Topic"
+ remove_banner: "Remove Banner Topic"
unpin: "Un-Pin Topic"
pin: "Pin Topic"
pin_globally: "Pin Topic Globally"
@@ -846,7 +848,6 @@ en:
visible: "Make Visible"
reset_read: "Reset Read Data"
multi_select: "Select Posts"
- convert_to_topic: "Convert to Regular Topic"
reply:
title: 'Reply'
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index e33219821..314e682ff 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -423,6 +423,10 @@ en:
archetypes:
regular:
title: "Regular Topic"
+ banner:
+ message:
+ make: "This topic is now a banner topic. It will appear at the top of every pages until it is dismissed by the users."
+ remove: "This topic is not a banner topic anymore. It will no longer appear at the top of every pages."
unsubscribed:
title: 'Unsubscribed'
@@ -989,7 +993,6 @@ en:
autoclosed_disabled: "This topic is now opened. New replies are allowed."
pinned_enabled: "This topic is now pinned. It will appear at the top of its category until it is unpinned by staff for everyone, or by individual users for themselves."
pinned_disabled: "This topic is now unpinned. It will no longer appear at the top of its category."
-
pinned_globally_enabled: "This topic is now pinned globally. It will appear at the top of its category and all topic lists until it is unpinned by staff for everyone, or by individual users for themselves."
pinned_globally_disabled: "This topic is now unpinned. It will no longer appear at the top of its category."
visible_enabled: "This topic is now visible. It will be displayed in topic lists."
diff --git a/config/routes.rb b/config/routes.rb
index b26263e8b..ab2a09911 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -340,6 +340,8 @@ Discourse::Application.routes.draw do
put "t/:topic_id/mute" => "topics#mute", constraints: {topic_id: /\d+/}
put "t/:topic_id/unmute" => "topics#unmute", constraints: {topic_id: /\d+/}
put "t/:topic_id/autoclose" => "topics#autoclose", constraints: {topic_id: /\d+/}
+ put "t/:topic_id/make-banner" => "topics#make_banner", constraints: {topic_id: /\d+/}
+ put "t/:topic_id/remove-banner" => "topics#remove_banner", constraints: {topic_id: /\d+/}
put "t/:topic_id/remove-allowed-user" => "topics#remove_allowed_user", constraints: {topic_id: /\d+/}
put "t/:topic_id/recover" => "topics#recover", constraints: {topic_id: /\d+/}
get "t/:topic_id/:post_number" => "topics#show", constraints: {topic_id: /\d+/, post_number: /\d+/}
diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb
index 7be236f08..69692a818 100644
--- a/spec/controllers/topics_controller_spec.rb
+++ b/spec/controllers/topics_controller_spec.rb
@@ -847,6 +847,58 @@ describe TopicsController do
end
+ describe 'make_banner' do
+
+ it 'needs you to be a staff member' do
+ log_in
+ xhr :put, :make_banner, topic_id: 99
+ response.should be_forbidden
+ end
+
+ describe 'when logged in' do
+
+ before do
+ @admin = log_in(:admin)
+ @topic = Fabricate(:topic, user: @admin)
+ end
+
+ it "changes the topic archetype to 'banner'" do
+ Topic.any_instance.expects(:archetype=).with(Archetype.banner)
+ Topic.any_instance.expects(:add_moderator_post)
+ xhr :put, :make_banner, topic_id: @topic.id
+ response.should be_success
+ end
+
+ end
+
+ end
+
+ describe 'remove_banner' do
+
+ it 'needs you to be a staff member' do
+ log_in
+ xhr :put, :remove_banner, topic_id: 99
+ response.should be_forbidden
+ end
+
+ describe 'when logged in' do
+
+ before do
+ @admin = log_in(:admin)
+ @topic = Fabricate(:topic, user: @admin)
+ end
+
+ it "resets the topic archetype" do
+ Topic.any_instance.expects(:archetype=).with(Archetype.default)
+ Topic.any_instance.expects(:add_moderator_post)
+ xhr :put, :remove_banner, topic_id: @topic.id
+ response.should be_success
+ end
+
+ end
+
+ end
+
describe "bulk" do
it 'needs you to be logged in' do
lambda { xhr :put, :bulk }.should raise_error(Discourse::NotLoggedIn)