FEATURE: allow moderators to globally pin topics

This commit is contained in:
Sam 2014-04-07 16:38:51 +10:00
parent ae3b2a6e02
commit 0372b81d11
10 changed files with 31 additions and 7 deletions

View File

@ -167,6 +167,11 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
this.get('content').setStatus('pinned', this.get('pinned_at') ? false : true);
},
togglePinnedGlobally: function() {
// Note that this is different than clearPin
this.get('content').setStatus('pinned_globally', this.get('pinned_at') ? false : true);
},
toggleArchived: function() {
this.get('content').toggleStatus('archived');
},

View File

@ -33,6 +33,7 @@
<button {{action togglePinned}} class='btn btn-admin'><i class='fa fa-thumb-tack'></i> {{i18n topic.actions.unpin}}</button>
{{else}}
<button {{action togglePinned}} class='btn btn-admin'><i class='fa fa-thumb-tack'></i> {{i18n topic.actions.pin}}</button>
<button {{action togglePinnedGlobally}} class='btn btn-admin'><i class='fa fa-thumb-tack'></i> {{i18n topic.actions.pin_globally}}</button>
{{/if}}
</li>

View File

@ -365,7 +365,7 @@ class TopicsController < ApplicationController
end
def check_for_status_presence(key, attr)
invalid_param(key) unless %w(visible closed pinned archived).include?(attr)
invalid_param(key) unless %w(pinned_globally visible closed pinned archived).include?(attr)
end
def invalid_param(key)

View File

@ -618,8 +618,9 @@ class Topic < ActiveRecord::Base
TopicUser.change(user.id, id, cleared_pinned_at: Time.now)
end
def update_pinned(status)
def update_pinned(status, global=false)
update_column(:pinned_at, status ? Time.now : nil)
update_column(:pinned_globally, global)
end
def draft_key

View File

@ -14,8 +14,8 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
private
def change(status)
if status.pinned?
topic.update_pinned status.enabled?
if status.pinned? || status.pinned_globally?
topic.update_pinned status.enabled?, status.pinned_globally?
elsif status.autoclosed?
topic.update_column 'closed', status.enabled?
else
@ -67,7 +67,7 @@ TopicStatusUpdate = Struct.new(:topic, :user) do
end
Status = Struct.new(:name, :enabled) do
%w(pinned autoclosed closed).each do |status|
%w(pinned_globally pinned autoclosed closed).each do |status|
define_method("#{status}?") { name == status }
end

View File

@ -796,6 +796,7 @@ en:
auto_close: "Auto Close"
unpin: "Un-Pin Topic"
pin: "Pin Topic"
pin_globally: "Pin Topic Globally"
unarchive: "Unarchive Topic"
archive: "Archive Topic"
invisible: "Make Invisible"

View File

@ -930,6 +930,9 @@ 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 either unpinned by a moderator, or the Clear Pin button is pressed."
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 either unpinned by a moderator, or the Clear Pin button is pressed."
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."
visible_disabled: "This topic is now invisible. It will no longer be displayed in any topic lists. The only way to access this topic is via direct link."

View File

@ -0,0 +1,12 @@
class AddPinnedGloballyToTopics < ActiveRecord::Migration
def up
add_column :topics, :pinned_globally, :boolean, null: false, default: false
execute "UPDATE topics set pinned_globally = 't' where category_id = (
SELECT value::int FROM site_settings WHERE name = 'uncategorized_category_id') AND pinned_at IS NOT NULL
"
end
def down
remove_column :topics, :pinned_globally
end
end

View File

@ -31,7 +31,7 @@ module TopicQuerySQL
# If you've clearned the pin, use bumped_at, otherwise put it at the top
def order_nocategory_with_pinned_sql
"CASE
WHEN topics.category_id = #{SiteSetting.uncategorized_category_id.to_i} and (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}'))
WHEN topics.pinned_globally and (COALESCE(topics.pinned_at, '#{lowest_date}') > COALESCE(tu.cleared_pinned_at, '#{lowest_date}'))
THEN '#{highest_date}'
ELSE topics.bumped_at
END DESC"
@ -42,7 +42,7 @@ module TopicQuerySQL
end
def order_nocategory_basic_bumped
"CASE WHEN topics.category_id = #{SiteSetting.uncategorized_category_id.to_i} and (topics.pinned_at IS NOT NULL) THEN 0 ELSE 1 END, topics.bumped_at DESC"
"CASE WHEN topics.pinned_globally and (topics.pinned_at IS NOT NULL) THEN 0 ELSE 1 END, topics.bumped_at DESC"
end
def order_top_for(score)

View File

@ -101,6 +101,7 @@ describe TopicQuery do
posts_count: 5,
participant_count: 12,
pinned_at: 10.minutes.ago,
pinned_globally: true,
bumped_at: 10.minutes.ago)
end
let!(:archived_topic) do