FIX: Better tracking of topic visibility changes (#26709)

This commit introduces a few changes as a result of
customer issues with finding why a topic was relisted.
In one case, if a user edited the OP of a topic that was
unlisted and hidden because of too many flags, the topic
would get relisted by directly changing topic.visible,
instead of going via TopicStatusUpdater.

To improve tracking we:

* Introduce a visibility_reason_id to topic which functions
  in a similar way to hidden_reason_id on post, this column is
  set from the various places we change topic visibility
* Fix Post#unhide! which was directly modifying topic.visible,
  instead we use TopicStatusUpdater which sets visibility_reason_id
  and also makes a small action post
* Show the reason topic visibility changed when hovering the
  unlisted icon in topic status on topic titles
This commit is contained in:
Martin Brennan
2024-04-29 10:34:46 +10:00
committed by GitHub
parent acc5b01e21
commit edec941a87
20 changed files with 229 additions and 19 deletions

View File

@@ -1540,6 +1540,25 @@ RSpec.describe Post do
expect(post.hidden).to eq(false)
expect(hidden_topic.visible).to eq(true)
expect(hidden_topic.visibility_reason_id).to eq(Topic.visibility_reasons[:op_unhidden])
end
it "will not unhide the topic if the topic visibility_reason_id is not op_flag_threshold_reached" do
hidden_topic =
Fabricate(
:topic,
visible: false,
visibility_reason_id: Topic.visibility_reasons[:manually_unlisted],
)
post = create_post(topic: hidden_topic)
post.update_columns(hidden: true, hidden_at: Time.now, hidden_reason_id: 1)
post.reload
expect(post.hidden).to eq(true)
post.unhide!
hidden_topic.reload
expect(hidden_topic.visible).to eq(false)
end
it "should increase user_stat topic_count for first post" do