Skip to content

Commit

Permalink
Fix organization multitenant issue with meeting's reminders (decidim#…
Browse files Browse the repository at this point in the history
…12927)

Co-authored-by: Alexandru Emil Lupu <[email protected]>
  • Loading branch information
andreslucena and alecslupu authored Jun 3, 2024
1 parent 012ea05 commit 8af2c82
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ def finder_query(component_id, interval)

def send_reminders(component)
intervals = Array(reminder_manifest.settings.attributes[:reminder_times].default)
space_admins = Decidim::ParticipatoryProcessUserRole.where(decidim_participatory_process_id: component.participatory_space_id, role: "admin").collect(&:user)
space_admins = (global_admins + space_admins).uniq
intervals.each do |interval|
finder_query(component.id, interval).find_each do |meeting|
authors = meeting.official? ? space_admins : [meeting.author]
authors = meeting.official? ? space_admins(component) : [meeting.author]
authors.each do |author|
send_notif = author.notification_settings.fetch("close_meeting_reminder", "1")
next unless send_notif == "1"
Expand All @@ -60,8 +58,16 @@ def send_reminders(component)
end
end

def global_admins
@global_admins ||= Decidim::User.where(admin: true).all
def space_admins(component)
@space_admins ||= begin
space_admins = if component.participatory_space.respond_to?(:user_roles)
component.participatory_space.user_roles(:admin).collect(&:user)
else
[]
end
global_admins = component.organization.admins
(global_admins + space_admins).uniq
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ module Decidim::Meetings
end
let(:intervals) { [3.days, 7.days] }
let(:organization) { create(:organization) }
let(:participatory_process) { create(:participatory_process, organization: organization) }
let!(:component) { create(:component, :published, manifest_name: "meetings", participatory_space: participatory_process) }
let(:participatory_space) { create(:participatory_process, organization: organization) }
let!(:component) { create(:component, :published, manifest_name: "meetings", participatory_space: participatory_space) }
let(:user) { create(:user, :admin, organization: organization, email: "[email protected]") }
let!(:meeting) { create(:meeting, :published, component: component, author: user, start_time: start_time, end_time: end_time, closed_at: closed_at) }

let(:closed_at) { nil }

before do
Expand All @@ -42,12 +43,49 @@ module Decidim::Meetings
end
end

context "and the meeting is not closed" do
context "and the user meeting is not closed" do
it "sends reminder" do
expect(Decidim::Meetings::SendCloseMeetingReminderJob).to receive(:perform_later)

expect { subject.generate }.to change(Decidim::Reminder, :count).by(1)
end
end

context "and the official meeting is not closed" do
let(:other_organization) { create(:organization) }
let!(:user) { create(:user, :admin, organization: organization, email: "[email protected]") }
let!(:other_admin) { create(:user, :admin, organization: other_organization, email: "[email protected]") }
let!(:meeting) { create(:meeting, :published, :official, component: component, start_time: start_time, end_time: end_time, closed_at: closed_at) }

it "sends reminder" do
expect(Decidim::Meetings::SendCloseMeetingReminderJob).to receive(:perform_later)

expect { subject.generate }.to change(Decidim::Reminder, :count).by(1)
end

context "and there are space admins" do
context "and space admin is Participatory Process" do
let(:participatory_space) { create(:participatory_process, organization: organization) }
let!(:process_admin) { create(:process_admin, participatory_process: participatory_space) }

it "sends reminder" do
expect(Decidim::Meetings::SendCloseMeetingReminderJob).to receive(:perform_later).twice

expect { subject.generate }.to change(Decidim::Reminder, :count).by(2)
end
end

context "and space admin is Assembly" do
let(:participatory_space) { create(:assembly, organization: organization) }
let!(:process_admin) { create(:assembly_admin, assembly: participatory_space) }

it "sends reminder" do
expect(Decidim::Meetings::SendCloseMeetingReminderJob).to receive(:perform_later).twice

expect { subject.generate }.to change(Decidim::Reminder, :count).by(2)
end
end
end
end
end

Expand Down

0 comments on commit 8af2c82

Please sign in to comment.