[#45401] Remove redmine:send_reminders rake task
With the date alerts being implemented, the redmine:send_reminders rake task became superfluous.pull/11868/head
parent
556f2d57da
commit
69f3e9a761
@ -1,35 +0,0 @@ |
|||||||
<%#-- copyright |
|
||||||
OpenProject is an open source project management software. |
|
||||||
Copyright (C) 2012-2023 the OpenProject GmbH |
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or |
|
||||||
modify it under the terms of the GNU General Public License version 3. |
|
||||||
|
|
||||||
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
|
||||||
Copyright (C) 2006-2013 Jean-Philippe Lang |
|
||||||
Copyright (C) 2010-2013 the ChiliProject Team |
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or |
|
||||||
modify it under the terms of the GNU General Public License |
|
||||||
as published by the Free Software Foundation; either version 2 |
|
||||||
of the License, or (at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program; if not, write to the Free Software |
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
||||||
|
|
||||||
See COPYRIGHT and LICENSE files for more details. |
|
||||||
|
|
||||||
++#%> |
|
||||||
<p><%= @group.nil? ? t(:mail_body_reminder, count: @issues.size, days: @days) : t(:mail_body_group_reminder, count: @issues.size, days: @days, group: @group.name) %></p> |
|
||||||
<ul> |
|
||||||
<% @issues.each do |issue| -%> |
|
||||||
<li><%= issue.project %> - <%= link_to "#{issue.type} ##{issue.id}", work_package_url(issue) %>: <%= issue.subject %></li> |
|
||||||
<% end -%> |
|
||||||
</ul> |
|
||||||
<p><%= link_to t(:label_work_package_view_all), @assigned_issues_url %></p> |
|
@ -1,33 +0,0 @@ |
|||||||
<%#-- copyright |
|
||||||
OpenProject is an open source project management software. |
|
||||||
Copyright (C) 2012-2023 the OpenProject GmbH |
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or |
|
||||||
modify it under the terms of the GNU General Public License version 3. |
|
||||||
|
|
||||||
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
|
||||||
Copyright (C) 2006-2013 Jean-Philippe Lang |
|
||||||
Copyright (C) 2010-2013 the ChiliProject Team |
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or |
|
||||||
modify it under the terms of the GNU General Public License |
|
||||||
as published by the Free Software Foundation; either version 2 |
|
||||||
of the License, or (at your option) any later version. |
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, |
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
GNU General Public License for more details. |
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License |
|
||||||
along with this program; if not, write to the Free Software |
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
||||||
|
|
||||||
See COPYRIGHT and LICENSE files for more details. |
|
||||||
|
|
||||||
++#%> |
|
||||||
<%= t(:mail_body_reminder, count: @issues.size, days: @days) %> |
|
||||||
<% @issues.each do |issue| -%> |
|
||||||
* <%= "#{issue.project} - #{issue.type} ##{issue.id}: #{issue.subject}" %> |
|
||||||
<% end -%> |
|
||||||
<%= @assigned_issues_url %> |
|
@ -1,67 +0,0 @@ |
|||||||
module OpenProject |
|
||||||
module Reminders |
|
||||||
class DueIssuesReminder |
|
||||||
attr_reader :due_date_in_days, :due_date, :project, :type, :user_ids, :notify_count |
|
||||||
|
|
||||||
def initialize(days: 7, project_id: nil, type_id: nil, user_ids: []) |
|
||||||
@due_date_in_days = days.to_i |
|
||||||
@due_date = due_date_in_days.days.from_now.to_date |
|
||||||
@project = Project.find_by(id: project_id.to_i) if project_id |
|
||||||
@type = ::Type.find_by(id: type_id.to_i) if type_id |
|
||||||
@user_ids = Array(user_ids).map(&:to_i).reject(&:zero?) |
|
||||||
@notify_count = 0 |
|
||||||
end |
|
||||||
|
|
||||||
## |
|
||||||
# Send reminder mails for the given instantiation |
|
||||||
def remind_users |
|
||||||
assigned_principals.each do |principal, issues| |
|
||||||
case principal |
|
||||||
when Group |
|
||||||
principal.users.each { |user| send_reminder_mail!(user, issues, principal) } |
|
||||||
when User |
|
||||||
send_reminder_mail!(principal, issues) |
|
||||||
else |
|
||||||
Rails.logger.info { "Skipping reminder mail for undeliverable principal #{principal.class.name} #{principal.id} " } |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
## |
|
||||||
# Deliver the reminder mail now for the given user |
|
||||||
# assuming it is active |
|
||||||
def send_reminder_mail!(user, issues, group = nil) |
|
||||||
if user&.active? |
|
||||||
UserMailer.reminder_mail(user, issues, due_date_in_days, group).deliver_now |
|
||||||
@notify_count += 1 |
|
||||||
end |
|
||||||
rescue StandardError => e |
|
||||||
Rails.logger.error { "Failed to deliver reminder_mail to user##{user.id}: #{e.message}" } |
|
||||||
end |
|
||||||
|
|
||||||
def assigned_principals |
|
||||||
scope = WorkPackage |
|
||||||
.includes(:status, :assigned_to, :project, :type) |
|
||||||
.where("#{Status.table_name}.is_closed = false AND #{WorkPackage.table_name}.due_date <= ?", due_date) |
|
||||||
.where("#{WorkPackage.table_name}.assigned_to_id IS NOT NULL") |
|
||||||
.where("#{Project.table_name}.active = #{true}") |
|
||||||
|
|
||||||
if user_ids.any? |
|
||||||
scope = scope.where("#{WorkPackage.table_name}.assigned_to_id IN (?)", user_ids) |
|
||||||
end |
|
||||||
|
|
||||||
if project |
|
||||||
scope = scope.where("#{WorkPackage.table_name}.project_id = #{project.id}") |
|
||||||
end |
|
||||||
|
|
||||||
if type |
|
||||||
scope = scope.where("#{WorkPackage.table_name}.type_id = #{type.id}") |
|
||||||
end |
|
||||||
|
|
||||||
scope |
|
||||||
.references(:projects, :statuses, :work_packages) |
|
||||||
.group_by(&:assigned_to) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,48 +0,0 @@ |
|||||||
#-- copyright |
|
||||||
# OpenProject is an open source project management software. |
|
||||||
# Copyright (C) 2012-2023 the OpenProject GmbH |
|
||||||
# |
|
||||||
# This program is free software; you can redistribute it and/or |
|
||||||
# modify it under the terms of the GNU General Public License version 3. |
|
||||||
# |
|
||||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
|
||||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
|
||||||
# Copyright (C) 2010-2013 the ChiliProject Team |
|
||||||
# |
|
||||||
# This program is free software; you can redistribute it and/or |
|
||||||
# modify it under the terms of the GNU General Public License |
|
||||||
# as published by the Free Software Foundation; either version 2 |
|
||||||
# of the License, or (at your option) any later version. |
|
||||||
# |
|
||||||
# This program is distributed in the hope that it will be useful, |
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
# GNU General Public License for more details. |
|
||||||
# |
|
||||||
# You should have received a copy of the GNU General Public License |
|
||||||
# along with this program; if not, write to the Free Software |
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
||||||
# |
|
||||||
# See COPYRIGHT and LICENSE files for more details. |
|
||||||
#++ |
|
||||||
|
|
||||||
desc <<~END_DESC |
|
||||||
Send reminders about issues due in the next days. |
|
||||||
#{' '} |
|
||||||
Available options: |
|
||||||
* days => number of days to remind about (defaults to 7) |
|
||||||
* type => id of type (defaults to all type) |
|
||||||
* project => id or identifier of project (defaults to all projects) |
|
||||||
* users => comma separated list of user ids who should be reminded |
|
||||||
#{' '} |
|
||||||
Example: |
|
||||||
rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production" |
|
||||||
END_DESC |
|
||||||
|
|
||||||
namespace :redmine do |
|
||||||
task send_reminders: :environment do |
|
||||||
reminder = OpenProject::Reminders::DueIssuesReminder.new(days: ENV.fetch('days', nil), project_id: ENV.fetch('project', nil), |
|
||||||
type_id: ENV.fetch('type', nil), user_ids: ENV['users'].to_s.split(',').map(&:to_i)) |
|
||||||
reminder.remind_users |
|
||||||
end |
|
||||||
end |
|
@ -1,114 +0,0 @@ |
|||||||
#-- copyright |
|
||||||
# OpenProject is an open source project management software. |
|
||||||
# Copyright (C) 2012-2023 the OpenProject GmbH |
|
||||||
# |
|
||||||
# This program is free software; you can redistribute it and/or |
|
||||||
# modify it under the terms of the GNU General Public License version 3. |
|
||||||
# |
|
||||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
|
||||||
# Copyright (C) 2006-2013 Jean-Philippe Lang |
|
||||||
# Copyright (C) 2010-2013 the ChiliProject Team |
|
||||||
# |
|
||||||
# This program is free software; you can redistribute it and/or |
|
||||||
# modify it under the terms of the GNU General Public License |
|
||||||
# as published by the Free Software Foundation; either version 2 |
|
||||||
# of the License, or (at your option) any later version. |
|
||||||
# |
|
||||||
# This program is distributed in the hope that it will be useful, |
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||||
# GNU General Public License for more details. |
|
||||||
# |
|
||||||
# You should have received a copy of the GNU General Public License |
|
||||||
# along with this program; if not, write to the Free Software |
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
||||||
# |
|
||||||
# See COPYRIGHT and LICENSE files for more details. |
|
||||||
#++ |
|
||||||
|
|
||||||
require 'spec_helper' |
|
||||||
|
|
||||||
describe OpenProject::Reminders::DueIssuesReminder do |
|
||||||
subject do |
|
||||||
described_class.new(days:, user_ids:).tap do |instance| |
|
||||||
instance.remind_users |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context 'with days set to 42' do |
|
||||||
let(:days) { 42 } |
|
||||||
|
|
||||||
context 'with user_ids unset' do |
|
||||||
let(:user_ids) { nil } |
|
||||||
|
|
||||||
let!(:user) { create(:user, mail: 'foo@bar.de') } |
|
||||||
let!(:wp) { create(:work_package, due_date: Date.tomorrow, assigned_to: user, subject: 'some issue') } |
|
||||||
|
|
||||||
it 'does notify the user' do |
|
||||||
expect(subject.notify_count).to be >= 1 |
|
||||||
expect(ActionMailer::Base.deliveries.count).to be >= 1 |
|
||||||
|
|
||||||
mail = ActionMailer::Base.deliveries.detect { |m| m.to.include? user.mail } |
|
||||||
expect(mail).to be_present |
|
||||||
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) { create(:group, lastname: "Managers", members: user) } |
|
||||||
let!(:group_wp) do |
|
||||||
create(:work_package, due_date: Date.tomorrow, assigned_to: group, subject: 'some group issue') |
|
||||||
end |
|
||||||
|
|
||||||
it 'notifies the user once for WPs assigned 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 |
|
||||||
let!(:user) { create(:user, mail: 'foo@bar.de') } |
|
||||||
let!(:user2) { create(:user, mail: 'foo@example.de') } |
|
||||||
let!(:wp) { create(:work_package, due_date: Date.tomorrow, assigned_to: user, subject: 'some issue') } |
|
||||||
|
|
||||||
context 'to an unassigned user' do |
|
||||||
let(:user_ids) { [user2.id] } |
|
||||||
|
|
||||||
it 'does not notify' do |
|
||||||
expect(subject.notify_count).to eq 0 |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context 'to an assigned user' do |
|
||||||
let(:user_ids) { [user.id] } |
|
||||||
|
|
||||||
it 'does notify' do |
|
||||||
expect(subject.notify_count).to eq 1 |
|
||||||
expect(ActionMailer::Base.deliveries.count).to eq 1 |
|
||||||
|
|
||||||
mail = ActionMailer::Base.deliveries.last |
|
||||||
expect(mail).to be_present |
|
||||||
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 |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
Loading…
Reference in new issue