mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 23:52:27 +08:00
FEATURE: Hide welcome topic if it hasn't been edited (#18632)
This commit is contained in:
@ -207,6 +207,15 @@ class Site
|
|||||||
"show_welcome_topic_banner:#{user_id}"
|
"show_welcome_topic_banner:#{user_id}"
|
||||||
end
|
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)
|
def self.show_welcome_topic_banner?(guardian)
|
||||||
return false if !guardian.is_admin?
|
return false if !guardian.is_admin?
|
||||||
user_id = guardian.user.id
|
user_id = guardian.user.id
|
||||||
@ -215,12 +224,7 @@ class Site
|
|||||||
return show_welcome_topic_banner unless show_welcome_topic_banner.nil?
|
return show_welcome_topic_banner unless show_welcome_topic_banner.nil?
|
||||||
|
|
||||||
show_welcome_topic_banner = if (user_id == User.first_login_admin_id)
|
show_welcome_topic_banner = if (user_id == User.first_login_admin_id)
|
||||||
Post.joins(:topic)
|
welcome_topic_exists_and_is_not_edited?
|
||||||
.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?
|
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
@ -18,6 +18,19 @@ module TopicQueryParams
|
|||||||
options[:topic_ids] = param_to_integer_list(:topic_ids)
|
options[:topic_ids] = param_to_integer_list(:topic_ids)
|
||||||
options[:no_subcategories] = options[:no_subcategories] == 'true' if options[:no_subcategories].present?
|
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
|
options
|
||||||
end
|
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
|
end
|
||||||
|
@ -961,4 +961,56 @@ RSpec.describe ListController do
|
|||||||
expect(response.body).to have_tag "body", with: { class: "category-myparentslug-mychildslug" }
|
expect(response.body).to have_tag "body", with: { class: "category-myparentslug-mychildslug" }
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
Reference in New Issue
Block a user