Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix sending reminders to groups

Wieland Lindenthalf3a6ece63761
diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb
index 536369c2951..f90bc0ddb1e 100644
--- a/app/mailers/user_mailer.rb
+++ b/app/mailers/user_mailer.rb
@@ -280,20 +280,29 @@ class UserMailer < BaseMailer
end
end
- def reminder_mail(user, issues, days)
+ def reminder_mail(user, issues, days, group = nil)
@issues = issues
@days = days
+ @group = group
- @assigned_issues_url = url_for(controller: :work_packages,
- action: :index,
- set_filter: 1,
- assigned_to_id: user.id,
- sort: 'due_date:asc')
+ assigned_to_id = if group
+ group.id
+ else
+ user.id
+ end
+
+ @assigned_issues_url = url_for(controller: :work_packages,
+ action: :index,
+ query_props: '{"t":"dueDate:asc","f":[{"n":"status","o":"o","v":[]},{"n":"assignee","o":"=","v":["' + assigned_to_id.to_s + '"]},{"n":"dueDate","o":"<t+","v":["2"]}]}')
open_project_headers 'Type' => 'Issue'
with_locale_for(user) do
- subject = t(:mail_subject_reminder, count: @issues.size, days: @days)
+ subject = if @group
+ t(:mail_subject_group_reminder, count: @issues.size, days: @days, group: @group.groupname)
+ else
+ t(:mail_subject_reminder, count: @issues.size, days: @days)
+ end
mail to: user.mail, subject: subject
end
end
diff --git a/app/views/user_mailer/reminder_mail.html.erb b/app/views/user_mailer/reminder_mail.html.erb
index 7b601af6e96..472a5cf4efe 100644
--- a/app/views/user_mailer/reminder_mail.html.erb
+++ b/app/views/user_mailer/reminder_mail.html.erb
@@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See docs/COPYRIGHT.rdoc for more details.
++#%>
-<p><%= t(:mail_body_reminder, count: @issues.size, days: @days) %></p>
+<p><%= @group.nil? ? t(:mail_body_reminder, count: @issues.size, days: @days) : t(:mail_body_group_reminder, count: @issues.size, days: @days, group: @group.groupname) %></p>
<ul>
<% @issues.each do |issue| -%>
<li><%= issue.project %> - <%= link_to "#{issue.type} ##{issue.id}", work_package_url(issue) %>: <%= issue.subject %></li>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 38c3cec40c7..8587999db57 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1738,12 +1738,14 @@ en:
mail_body_lost_password: "To change your password, click on the following link:"
mail_body_register: "To activate your account, click on the following link:"
mail_body_reminder: "%{count} work package(s) that are assigned to you are due in the next %{days} days:"
+ mail_body_group_reminder: "%{count} work package(s) that are assigned to group \"%{group}\" are due in the next %{days} days:"
mail_body_wiki_content_added: "The '%{id}' wiki page has been added by %{author}."
mail_body_wiki_content_updated: "The '%{id}' wiki page has been updated by %{author}."
mail_subject_account_activation_request: "%{value} account activation request"
mail_subject_lost_password: "Your %{value} password"
mail_subject_register: "Your %{value} account activation"
mail_subject_reminder: "%{count} work package(s) due in the next %{days} days"
+ mail_subject_group_reminder: "For group \"%{group}\" %{count} work package(s) due in the next %{days} days"
mail_subject_wiki_content_added: "'%{id}' wiki page has been added"
mail_subject_wiki_content_updated: "'%{id}' wiki page has been updated"
diff --git a/lib/open_project/reminders/due_issues_reminder.rb b/lib/open_project/reminders/due_issues_reminder.rb
index ccf92f9a8a8..41873bb6642 100644
--- a/lib/open_project/reminders/due_issues_reminder.rb
+++ b/lib/open_project/reminders/due_issues_reminder.rb
@@ -18,7 +18,7 @@ module OpenProject
assigned_principals.each do |principal, issues|
case principal
when Group
- group.users.each { |u| send_reminder_mail!(u, issues) }
+ principal.users.each { |user| send_reminder_mail!(user, issues, principal) }
when User
send_reminder_mail!(principal, issues)
else
@@ -30,9 +30,9 @@ module OpenProject
##
# Deliver the reminder mail now for the given user
# assuming it is active
- def send_reminder_mail!(user, issues)
+ def send_reminder_mail!(user, issues, group = nil)
if user&.active?
- UserMailer.reminder_mail(user, issues, due_date_in_days).deliver_now
+ UserMailer.reminder_mail(user, issues, due_date_in_days, group).deliver_now
@notify_count += 1
end
rescue StandardError => e
diff --git a/spec/lib/reminders/due_issues_reminder_spec.rb b/spec/lib/reminders/due_issues_reminder_spec.rb
index 1c4b70bf33f..737a730c372 100644
--- a/spec/lib/reminders/due_issues_reminder_spec.rb
+++ b/spec/lib/reminders/due_issues_reminder_spec.rb
@@ -53,6 +53,34 @@ describe OpenProject::Reminders::DueIssuesReminder do
expect(mail.body.encoded).to include("#{wp.project.name} - #{wp.type.name} ##{wp.id}: some issue")
expect(mail.subject).to eq '1 work package(s) due in the next 42 days'
end
+
+ context 'with work package assigned to group' do
+ let!(:group) { FactoryBot.create(:group, lastname: "Managers", users: [user]) }
+ let!(:group_wp) do
+ FactoryBot.create(:work_package, due_date: Date.tomorrow, assigned_to: group, subject: 'some group issue')
+ end
+
+ it 'notifies the user once for WPs assigend to him and another for those assigned to the group' do
+ expect(subject.notify_count).to be >= 2
+ expect(ActionMailer::Base.deliveries.count).to be >= 2
+
+ mails = ActionMailer::Base.deliveries.select { |m| m.to.include? user.mail }
+
+ expect(mails.size).to eq 2
+
+ user_mail = mails.detect { |mail| mail.subject == '1 work package(s) due in the next 42 days' }
+ group_mail = mails.detect { |mail| mail.subject == 'For group "Managers" 1 work package(s) due in the next 42 days' }
+
+ expect(user_mail).to be_present
+ expect(group_mail).to be_present
+ expect(user_mail.body.encoded).to(
+ include("#{wp.project.name} - #{wp.type.name} ##{wp.id}: some issue")
+ )
+ expect(group_mail.body.encoded).to(
+ include("#{group_wp.project.name} - #{group_wp.type.name} ##{group_wp.id}: some group issue")
+ )
+ end
+ end
end
context 'with user_ids set' do