Skip to content

A platform for community discussion. Free, open, simple.

UX: Hide activity log link for nested view unless there is a post to see (#39850)

Mark VanLandingham567c0692049d
diff --git a/frontend/discourse/app/components/nested.gjs b/frontend/discourse/app/components/nested.gjs
index 3b668a22f2d..b26f65432cd 100644
--- a/frontend/discourse/app/components/nested.gjs
+++ b/frontend/discourse/app/components/nested.gjs
@@ -96,11 +96,13 @@ export default class Nested extends Component {
<div class="nested-view__controls">
<NestedSortSelector @current={{@sort}} @onChange={{@changeSort}} />
<div class="nested-view__controls-right">
- <DButton
- class="btn-flat nested-view__activity-link"
- @action={{@showActivityLog}}
- @label="nested_replies.activity_log.link"
- />
+ {{#if @topic.has_activity_log}}
+ <DButton
+ class="btn-flat nested-view__activity-link"
+ @action={{@showActivityLog}}
+ @label="nested_replies.activity_log.link"
+ />
+ {{/if}}
{{#if this.currentUser.can_toggle_nested_mode}}
<DButton
class="btn-flat nested-view__flat-link"
diff --git a/frontend/discourse/app/components/nested/context-view.gjs b/frontend/discourse/app/components/nested/context-view.gjs
index 45a2b49808e..b739cb54060 100644
--- a/frontend/discourse/app/components/nested/context-view.gjs
+++ b/frontend/discourse/app/components/nested/context-view.gjs
@@ -125,11 +125,13 @@ export default class NestedContextView extends Component {
<div class="nested-view__controls">
<NestedSortSelector @current={{@sort}} @onChange={{@changeSort}} />
<div class="nested-view__controls-right">
- <DButton
- class="btn-flat nested-view__activity-link"
- @action={{@showActivityLog}}
- @label="nested_replies.activity_log.link"
- />
+ {{#if @topic.has_activity_log}}
+ <DButton
+ class="btn-flat nested-view__activity-link"
+ @action={{@showActivityLog}}
+ @label="nested_replies.activity_log.link"
+ />
+ {{/if}}
{{#if this.currentUser.can_toggle_nested_mode}}
<DButton
class="btn-flat nested-view__flat-link"
diff --git a/lib/nested_replies/post_tree_serializer.rb b/lib/nested_replies/post_tree_serializer.rb
index 5bf06a985c5..6a243d870cd 100644
--- a/lib/nested_replies/post_tree_serializer.rb
+++ b/lib/nested_replies/post_tree_serializer.rb
@@ -19,6 +19,7 @@ module NestedReplies
def serialize_topic
serializer = TopicViewSerializer.new(@topic_view, scope: @guardian, root: false)
json = serializer.as_json
+ json[:has_activity_log] = activity_log_present?
json.except(:post_stream, :timeline_lookup, :user_badges, *SUGGESTED_AND_RELATED_KEYS)
end
@@ -79,5 +80,27 @@ module NestedReplies
end
node
end
+
+ private
+
+ # Filters mirror Guardian#can_see_post? so the boolean does not leak
+ # the existence of small_actions/whispers the user cannot see.
+ def activity_log_present?
+ post_types = [Post.types[:small_action]]
+ post_types << Post.types[:whisper] if @guardian.user&.whisperer?
+
+ scope = @topic.posts.where(post_type: post_types).where.not(action_code: [nil, ""])
+ scope = scope.where(hidden: false) unless can_see_hidden_posts?
+ scope.exists?
+ end
+
+ def can_see_hidden_posts?
+ return true if @guardian.is_staff?
+ if SiteSetting.hidden_post_visible_groups_map.include?(Group::AUTO_GROUPS[:everyone])
+ return true
+ end
+ return false if @guardian.anonymous?
+ @guardian.user.in_any_groups?(SiteSetting.hidden_post_visible_groups_map)
+ end
end
end
diff --git a/spec/requests/nested_topics_controller_spec.rb b/spec/requests/nested_topics_controller_spec.rb
index 8e007f98a67..94079fa39b1 100644
--- a/spec/requests/nested_topics_controller_spec.rb
+++ b/spec/requests/nested_topics_controller_spec.rb
@@ -182,6 +182,92 @@ RSpec.describe NestedTopicsController, type: :request do
expect(json["page"]).to eq(1)
end
+ describe "topic.has_activity_log" do
+ it "is false when the topic has no small actions or whispers with action codes" do
+ sign_in(user)
+ get show_url(topic, page: 0)
+
+ expect(response.parsed_body["topic"]["has_activity_log"]).to eq(false)
+ end
+
+ it "is true when the topic has a visible small_action post" do
+ topic.add_small_action(admin, "closed.enabled")
+
+ sign_in(user)
+ get show_url(topic, page: 0)
+
+ expect(response.parsed_body["topic"]["has_activity_log"]).to eq(true)
+ end
+
+ it "ignores whisper action-code posts for non-whisperers" do
+ SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}"
+ topic.add_moderator_post(
+ admin,
+ nil,
+ post_type: Post.types[:whisper],
+ action_code: "assigned",
+ custom_fields: {
+ "action_code_who" => user.username,
+ },
+ )
+
+ sign_in(user)
+ get show_url(topic, page: 0)
+
+ expect(response.parsed_body["topic"]["has_activity_log"]).to eq(false)
+ end
+
+ it "is true when whisperers have a whisper action-code post" do
+ SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}"
+ topic.add_moderator_post(
+ admin,
+ nil,
+ post_type: Post.types[:whisper],
+ action_code: "assigned",
+ custom_fields: {
+ "action_code_who" => user.username,
+ },
+ )
+
+ sign_in(admin)
+ get show_url(topic, page: 0)
+
+ expect(response.parsed_body["topic"]["has_activity_log"]).to eq(true)
+ end
+
+ it "does not leak the existence of hidden small_actions to non-staff" do
+ Fabricate(
+ :small_action,
+ topic: topic,
+ user: admin,
+ action_code: "closed.enabled",
+ hidden: true,
+ hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached],
+ )
+
+ sign_in(user)
+ get show_url(topic, page: 0)
+
+ expect(response.parsed_body["topic"]["has_activity_log"]).to eq(false)
+ end
+
+ it "is true for staff when the only small_action is hidden" do
+ Fabricate(
+ :small_action,
+ topic: topic,
+ user: admin,
+ action_code: "closed.enabled",
+ hidden: true,
+ hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached],
+ )
+
+ sign_in(admin)
+ get show_url(topic, page: 0)
+
+ expect(response.parsed_body["topic"]["has_activity_log"]).to eq(true)
+ end
+ end
+
it "paginates with has_more_roots" do
NestedReplies::TreeLoader::ROOTS_PER_PAGE.times do
Fabricate(:post, topic: topic, user: user, reply_to_post_number: nil)
diff --git a/spec/system/nested_activity_log_spec.rb b/spec/system/nested_activity_log_spec.rb
index c6b07002615..5313fa08f46 100644
--- a/spec/system/nested_activity_log_spec.rb
+++ b/spec/system/nested_activity_log_spec.rb
@@ -19,4 +19,11 @@ RSpec.describe "Nested activity log" do
expect(page).to have_css(".nested-activity-log-modal")
expect(page).to have_css(".nested-activity-log-modal__item", count: 2)
end
+
+ it "hides the activity log link on a topic with no small actions" do
+ page.visit("/n/#{topic.slug}/#{topic.id}")
+
+ expect(page).to have_css(".nested-view__controls")
+ expect(page).to have_no_css(".nested-view__activity-link")
+ end
end