mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 02:34:28 +08:00
DEV: adds support for bannered until (#13417)
ATM it only implements server side of it, as my need is for automation purposes. However it should probably be added in the UI too as it's unexpected to have pinned_until and no bannered_until.
This commit is contained in:
@ -1093,7 +1093,15 @@ class Topic < ActiveRecord::Base
|
||||
@participants_summary ||= TopicParticipantsSummary.new(self, options).summary
|
||||
end
|
||||
|
||||
def make_banner!(user)
|
||||
def make_banner!(user, bannered_until = nil)
|
||||
if bannered_until
|
||||
bannered_until = begin
|
||||
Time.parse(bannered_until)
|
||||
rescue ArgumentError
|
||||
raise Discourse::InvalidParameters.new(:bannered_until)
|
||||
end
|
||||
end
|
||||
|
||||
# only one banner at the same time
|
||||
previous_banner = Topic.where(archetype: Archetype.banner).first
|
||||
previous_banner.remove_banner!(user) if previous_banner.present?
|
||||
@ -1102,18 +1110,25 @@ class Topic < ActiveRecord::Base
|
||||
.update_all(dismissed_banner_key: nil)
|
||||
|
||||
self.archetype = Archetype.banner
|
||||
self.bannered_until = bannered_until
|
||||
self.add_small_action(user, "banner.enabled")
|
||||
self.save
|
||||
|
||||
MessageBus.publish('/site/banner', banner)
|
||||
|
||||
Jobs.cancel_scheduled_job(:remove_banner, topic_id: self.id)
|
||||
Jobs.enqueue_at(bannered_until, :remove_banner, topic_id: self.id) if bannered_until
|
||||
end
|
||||
|
||||
def remove_banner!(user)
|
||||
self.archetype = Archetype.default
|
||||
self.bannered_until = nil
|
||||
self.add_small_action(user, "banner.disabled")
|
||||
self.save
|
||||
|
||||
MessageBus.publish('/site/banner', nil)
|
||||
|
||||
Jobs.cancel_scheduled_job(:remove_banner, topic_id: self.id)
|
||||
end
|
||||
|
||||
def banner
|
||||
@ -1199,12 +1214,13 @@ class Topic < ActiveRecord::Base
|
||||
TopicUser.change(user.id, id, cleared_pinned_at: nil)
|
||||
end
|
||||
|
||||
def update_pinned(status, global = false, pinned_until = "")
|
||||
pinned_until ||= ''
|
||||
|
||||
pinned_until = begin
|
||||
Time.parse(pinned_until)
|
||||
rescue ArgumentError
|
||||
def update_pinned(status, global = false, pinned_until = nil)
|
||||
if pinned_until
|
||||
pinned_until = begin
|
||||
Time.parse(pinned_until)
|
||||
rescue ArgumentError
|
||||
raise Discourse::InvalidParameters.new(:pinned_until)
|
||||
end
|
||||
end
|
||||
|
||||
update_columns(
|
||||
@ -1233,7 +1249,10 @@ class Topic < ActiveRecord::Base
|
||||
|
||||
def self.ensure_consistency!
|
||||
# unpin topics that might have been missed
|
||||
Topic.where("pinned_until < now()").update_all(pinned_at: nil, pinned_globally: false, pinned_until: nil)
|
||||
Topic.where('pinned_until < ?', Time.now).update_all(pinned_at: nil, pinned_globally: false, pinned_until: nil)
|
||||
Topic.where('bannered_until < ?', Time.now).find_each do |topic|
|
||||
topic.remove_banner!(Discourse.system_user)
|
||||
end
|
||||
end
|
||||
|
||||
def inherit_auto_close_from_category(timer_type: :close)
|
||||
|
Reference in New Issue
Block a user