2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-03 23:54:20 +08:00
discourse/spec/system/flagging_post_spec.rb
Krzysztof Kotlarek 53d799eb8b
DEV: Remove reviewable_ui_refresh feature flag and legacy code (#36752)
Following PR #36711 which enabled the refreshed review UI for all users, this commit removes the old feature flag infrastructure and cleans up legacy code that is no longer needed.

Backend Changes:
  - Removed ReviewableActionLog model and its spec entirely
  - Removed CalculateFinalStatusFromLogs service and spec
  - Removed site settings: force_old_reviewable_ui, reviewable_old_moderator_actions
  - Simplified ReviewableActionBuilder — stripped out legacy action-building methods (build_user_actions_bundle, build_post_actions_bundle, build_new_separated_actions)
  - Cleaned up reviewable models (ReviewableFlaggedPost, ReviewablePost, ReviewableQueuedPost, ReviewableUser, Chat::ReviewableMessage, ReviewablePostVotingComment) — removed unused/legacy action definitions
  - Removed legacy specs for action builder, action logs, flagged post actions, post actions, user actions, and status-from-logs
  - Updated system tests and page objects to reflect the new UI structure

  Frontend Changes:

  - Deleted legacy components: reviewable-item.gjs, reviewable-user.gjs, review-index-legacy.gjs
  - Renamed reviewable-refresh/ → reviewable/ — moved all sub-components (created-by, flagged-post, item, post, queued-post, topic-link, user, etc.) out of the refresh directory into the canonical reviewable/ namespace
  - Simplified reviewable/item.gjs — removed feature flag conditionals and legacy code paths
  - Cleaned up review/index.gjs and review/show.gjs templates — removed branching between old/new UI
  - Updated plugin components (chat, AI, post-voting) to import from reviewable/ instead of reviewable-refresh/
  - Removed acceptance tests (review-test.js) replaced by system tests
  - Renamed and updated integration tests from reviewable-refresh/* to reviewable/*

Plan for next PRs:
- Move plugins from Pages::RefreshedReview to Pages::Review 
- Move plugins to import from `reviewable/` and not `refreshed-reviewable/`
- Move reviewable-user.js import in plugin to use `reviewable/user.js`
- Remove unused settings like `reviewable_old_moderator_actions` from plugins
- Delete `Pages::RefreshedReview`
- Delete `reviewable-refresh/` directory
- Delete `reviewable-user.js` component
- Delete `reviewable_old_moderator_actions` site setting

Plugins PRs:
- https://github.com/discourse/discourse-akismet/pull/203
- https://github.com/discourse/discourse-antivirus/pull/98
- https://github.com/discourse/discourse-category-experts/pull/223
2026-02-23 10:45:36 +08:00

166 lines
5.8 KiB
Ruby

# frozen_string_literal: true
describe "Flagging post", type: :system do
fab!(:current_user, :admin)
fab!(:category)
fab!(:topic) { Fabricate(:topic, category: category) }
fab!(:first_post) { Fabricate(:post, topic: topic) }
fab!(:post_to_flag) { Fabricate(:post, topic: topic) }
let(:topic_page) { PageObjects::Pages::Topic.new }
let(:flag_modal) { PageObjects::Modals::Flag.new }
let(:silence_user_modal) { PageObjects::Modals::PenalizeUser.new("silence") }
let(:review_page) { PageObjects::Pages::Review.new }
describe "Using Take Action" do
before { sign_in(current_user) }
it "can select the default action to hide the post, agree with other flags, and reach the flag threshold" do
other_flag = Fabricate(:flag_post_action, post: post_to_flag, user: Fabricate(:moderator))
other_flag_reviewable =
Fabricate(:reviewable_flagged_post, target: post_to_flag, created_by: other_flag.user)
expect(other_flag.reload.agreed_at).to be_nil
topic_page.visit_topic(topic)
topic_page.expand_post_actions(post_to_flag)
topic_page.click_post_action_button(post_to_flag, :flag)
flag_modal.choose_type(:off_topic)
flag_modal.take_action(:agree_and_hide)
expect(
topic_page.post_by_number(post_to_flag).ancestor(".topic-post.post-hidden"),
).to be_present
visit "/review/#{other_flag_reviewable.id}"
expect(review_page).to have_reviewable_with_approved_status(other_flag_reviewable)
end
it "can choose to immediately silence the user" do
expect(Reviewable.count).to eq(0)
topic_page.visit_topic(topic)
topic_page.expand_post_actions(post_to_flag)
topic_page.click_post_action_button(post_to_flag, :flag)
flag_modal.choose_type(:off_topic)
flag_modal.take_action(:agree_and_silence)
silence_user_modal.fill_in_silence_reason("spamming")
silence_user_modal.set_future_date("tomorrow")
silence_user_modal.perform
expect(silence_user_modal).to be_closed
expect(
topic_page.post_by_number(post_to_flag).ancestor(".topic-post.post-hidden"),
).to be_present
visit "/review/#{Reviewable.sole.id}"
expect(review_page).to have_reviewable_with_approved_status(Reviewable.sole)
end
end
describe "As Illegal" do
before { sign_in(current_user) }
it do
topic_page.visit_topic(topic)
topic_page.expand_post_actions(post_to_flag)
topic_page.click_post_action_button(post_to_flag, :flag)
flag_modal.choose_type(:illegal)
expect(flag_modal).to have_css(".illegal .description")
expect(flag_modal).to have_css(".flag-confirmation")
flag_modal.fill_message("This looks totally illegal to me.")
flag_modal.check_confirmation
flag_modal.confirm_flag
expect(page).to have_content(I18n.t("js.post.actions.by_you.illegal"))
end
end
describe "As send a message to user" do
before do
SiteSetting.allow_user_locale = true
current_user.update!(locale: "en_GB")
sign_in(current_user)
end
it do
topic_page.visit_topic(topic)
topic_page.expand_post_actions(post_to_flag)
topic_page.click_post_action_button(post_to_flag, :flag)
flag_modal.choose_type(:notify_user)
flag_modal.fill_message("This looks totally illegal to me.")
flag_modal.confirm_flag
expect(page).to have_content(I18n.t("js.post.actions.by_you.notify_user"))
end
end
context "when tl0" do
fab!(:tl0_user) { Fabricate(:user, trust_level: TrustLevel[0]) }
before { sign_in(tl0_user) }
it "does not allow to mark posts as illegal" do
topic_page.visit_topic(topic)
expect(topic_page).to have_no_flag_button
end
it "allows to mark posts as illegal when allow_all_users_to_flag_illegal_content setting is enabled" do
SiteSetting.email_address_to_report_illegal_content = "illegal@example.com"
SiteSetting.allow_all_users_to_flag_illegal_content = true
topic_page.visit_topic(topic).open_flag_topic_modal
expect(flag_modal.body).to have_content(
ActionView::Base.full_sanitizer.sanitize(I18n.t("js.flagging.review_process_description")),
)
expect(flag_modal).to have_choices(I18n.t("js.flagging.formatted_name.illegal"))
end
end
context "when anonymous" do
let(:anonymous_flag_modal) { PageObjects::Modals::AnonymousFlag.new }
it "does not allow to mark posts as illegal" do
topic_page.visit_topic(topic)
expect(topic_page).to have_no_post_more_actions(post_to_flag)
end
it "allows to mark posts as illegal when allow_all_users_to_flag_illegal_content setting is enabled" do
SiteSetting.contact_email = "contact@example.com"
SiteSetting.allow_all_users_to_flag_illegal_content = true
topic_page.visit_topic(topic, post_number: post_to_flag.post_number)
topic_page.find_post_action_button(post_to_flag, :flag).click
expect(anonymous_flag_modal.body).to have_content(
ActionView::Base.full_sanitizer.sanitize(I18n.t("js.flagging.review_process_description")),
)
expect(anonymous_flag_modal.body).to have_content(
ActionView::Base.full_sanitizer.sanitize(
I18n.t(
"js.anonymous_flagging.description",
{ email: "contact@example.com", topic_title: topic.title, url: current_url },
),
),
)
SiteSetting.email_address_to_report_illegal_content = "illegal@example.com"
topic_page.visit_topic(topic)
topic_page.find_post_action_button(post_to_flag, :flag).click
expect(anonymous_flag_modal.body).to have_content(
ActionView::Base.full_sanitizer.sanitize(
I18n.t(
"js.anonymous_flagging.description",
{ email: "illegal@example.com", topic_title: topic.title, url: current_url },
),
),
)
end
end
end