FEATURE: Hide welcome topic if it hasn't been edited (#18632)
This commit is contained in:
parent
66904f2cd2
commit
505aec123f
|
@ -207,6 +207,15 @@ class Site
|
|||
"show_welcome_topic_banner:#{user_id}"
|
||||
end
|
||||
|
||||
def self.welcome_topic_exists_and_is_not_edited?
|
||||
Post.joins(:topic)
|
||||
.where(
|
||||
"topics.id = :topic_id AND topics.deleted_at IS NULL AND posts.post_number = 1 AND posts.version = 1 AND posts.created_at > :created_at",
|
||||
topic_id: SiteSetting.welcome_topic_id,
|
||||
created_at: 1.month.ago
|
||||
).exists?
|
||||
end
|
||||
|
||||
def self.show_welcome_topic_banner?(guardian)
|
||||
return false if !guardian.is_admin?
|
||||
user_id = guardian.user.id
|
||||
|
@ -215,12 +224,7 @@ class Site
|
|||
return show_welcome_topic_banner unless show_welcome_topic_banner.nil?
|
||||
|
||||
show_welcome_topic_banner = if (user_id == User.first_login_admin_id)
|
||||
Post.joins(:topic)
|
||||
.find_by(
|
||||
"topics.id = :topic_id AND topics.deleted_at IS NULL AND posts.post_number = 1 AND posts.version = 1 AND posts.created_at > :created_at",
|
||||
topic_id: SiteSetting.welcome_topic_id,
|
||||
created_at: 1.month.ago
|
||||
).present?
|
||||
welcome_topic_exists_and_is_not_edited?
|
||||
else
|
||||
false
|
||||
end
|
||||
|
|
|
@ -18,6 +18,19 @@ module TopicQueryParams
|
|||
options[:topic_ids] = param_to_integer_list(:topic_ids)
|
||||
options[:no_subcategories] = options[:no_subcategories] == 'true' if options[:no_subcategories].present?
|
||||
|
||||
if hide_welcome_topic?
|
||||
options[:except_topic_ids] ||= []
|
||||
options[:except_topic_ids] << SiteSetting.welcome_topic_id
|
||||
end
|
||||
|
||||
options
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def hide_welcome_topic?
|
||||
return false if !SiteSetting.bootstrap_mode_enabled
|
||||
return false if @guardian.is_admin?
|
||||
Site.welcome_topic_exists_and_is_not_edited?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -961,4 +961,56 @@ RSpec.describe ListController do
|
|||
expect(response.body).to have_tag "body", with: { class: "category-myparentslug-mychildslug" }
|
||||
end
|
||||
end
|
||||
|
||||
describe "welcome topic" do
|
||||
fab!(:welcome_topic) { Fabricate(:topic) }
|
||||
fab!(:post) { Fabricate(:post, topic: welcome_topic) }
|
||||
|
||||
before do
|
||||
SiteSetting.welcome_topic_id = welcome_topic.id
|
||||
SiteSetting.editing_grace_period = 1.minute.to_i
|
||||
SiteSetting.bootstrap_mode_enabled = true
|
||||
end
|
||||
|
||||
it "is hidden for non-admins" do
|
||||
|
||||
get "/latest.json"
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body
|
||||
expect(parsed["topic_list"]["topics"].length).to eq(1)
|
||||
expect(parsed["topic_list"]["topics"].first["id"]).not_to eq(welcome_topic.id)
|
||||
end
|
||||
|
||||
it "is shown to non-admins when there is an edit" do
|
||||
post.revise(post.user, { raw: "#{post.raw}2" }, revised_at: post.updated_at + 2.minutes)
|
||||
post.reload
|
||||
expect(post.version).to eq(2)
|
||||
|
||||
get "/latest.json"
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body
|
||||
expect(parsed["topic_list"]["topics"].length).to eq(2)
|
||||
expect(parsed["topic_list"]["topics"].first["id"]).to eq(welcome_topic.id)
|
||||
end
|
||||
|
||||
it "is shown to admins" do
|
||||
sign_in(admin)
|
||||
|
||||
get "/latest.json"
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body
|
||||
expect(parsed["topic_list"]["topics"].length).to eq(2)
|
||||
expect(parsed["topic_list"]["topics"].first["id"]).to eq(welcome_topic.id)
|
||||
end
|
||||
|
||||
it "is shown to users when bootstrap mode is disabled" do
|
||||
SiteSetting.bootstrap_mode_enabled = false
|
||||
|
||||
get "/latest.json"
|
||||
expect(response.status).to eq(200)
|
||||
parsed = response.parsed_body
|
||||
expect(parsed["topic_list"]["topics"].length).to eq(2)
|
||||
expect(parsed["topic_list"]["topics"].first["id"]).to eq(welcome_topic.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue