From 7c9c0f82bf45590c2f5c6475eb3e1ddf29357df2 Mon Sep 17 00:00:00 2001 From: Antti Hukkanen Date: Tue, 10 Dec 2024 09:52:42 +0200 Subject: [PATCH] Do not include blocked users in the newsletter recipients --- .../privacy/admin_newsletter_recipients_extensions.rb | 1 + spec/queries/decidim/admin/newsletter_recipients_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/app/queries/concerns/decidim/privacy/admin_newsletter_recipients_extensions.rb b/app/queries/concerns/decidim/privacy/admin_newsletter_recipients_extensions.rb index b42f464..6d5794a 100644 --- a/app/queries/concerns/decidim/privacy/admin_newsletter_recipients_extensions.rb +++ b/app/queries/concerns/decidim/privacy/admin_newsletter_recipients_extensions.rb @@ -27,6 +27,7 @@ def query def recipients_base_query Decidim::User .entire_collection + .available .where(organization: @form.current_organization) .where.not(newsletter_notifications_at: nil) .where.not(email: nil) diff --git a/spec/queries/decidim/admin/newsletter_recipients_spec.rb b/spec/queries/decidim/admin/newsletter_recipients_spec.rb index ad1c9b5..8732b67 100644 --- a/spec/queries/decidim/admin/newsletter_recipients_spec.rb +++ b/spec/queries/decidim/admin/newsletter_recipients_spec.rb @@ -48,6 +48,15 @@ expect(recipients.count).to eq 5 end end + + context "with blocked accounts" do + let!(:blocked_recipients) { create_list(:user, 5, :confirmed, :blocked, newsletter_notifications_at: Time.current, organization:) } + + it "returns all not blocked users" do + expect(subject.query).to match_array recipients + expect(recipients.count).to eq 5 + end + end end context "when sending to followers" do