From e7db336a847cc528ad87621870b941eafb2e18a4 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Tue, 7 Oct 2025 08:31:15 +0200 Subject: [PATCH] Use new method to fetch collection watchers --- app/helpers/accesses_helper.rb | 18 +++++++----------- app/models/collection/accessible.rb | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/helpers/accesses_helper.rb b/app/helpers/accesses_helper.rb index 0248e25af..9e265cb23 100644 --- a/app/helpers/accesses_helper.rb +++ b/app/helpers/accesses_helper.rb @@ -27,10 +27,7 @@ module AccessesHelper end def collection_watchers_list(collection) - watchers = collection.users - .without(User.system) - .where(accesses: { involvement: :watching }) - .distinct + watchers = collection.watchers displayed_watchers = watchers.limit(MAX_DISPLAYED_WATCHERS) overflow_count = watchers.count - MAX_DISPLAYED_WATCHERS @@ -50,13 +47,13 @@ module AccessesHelper collection_involvement_path(collection), method: :put, aria: { labelledby: involvement_label_id }, - class: class_names("btn", { "btn--reversed": access.involvement == "watching" && icon_only }), + class: class_names("btn", { "btn--reversed": access.watching? && icon_only }), params: { show_watchers: show_watchers, involvement: next_involvement(access.involvement), icon_only: icon_only } ) do safe_join([ icon_tag("notification-bell-#{icon_only ? 'reverse-' : nil}#{access.involvement.dasherize}"), tag.span( - involvement_access_label(collection, access.involvement), + involvement_access_label(access), class: class_names("txt-nowrap txt-uppercase", "for-screen-reader": icon_only), id: involvement_label_id ) @@ -70,12 +67,11 @@ module AccessesHelper order[(order.index(involvement.to_s) + 1) % order.size] end - def involvement_access_label(collection, involvement) - case involvement - when "access_only" + def involvement_access_label(access) + if access.access_only? "Watch this" - when "watching" - "Stop Watching" + else + "Stop watching" end end end diff --git a/app/models/collection/accessible.rb b/app/models/collection/accessible.rb index b6d1dbbc2..42fb45692 100644 --- a/app/models/collection/accessible.rb +++ b/app/models/collection/accessible.rb @@ -48,7 +48,7 @@ module Collection::Accessible end def watchers - users.where(accesses: { involvement: :watching }) + users.without(User.system).where(accesses: { involvement: :watching }) end private