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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#45401] Remove redmine:send_reminders rake task
Christophe Bliard69f3e9a7613b
diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rbindex b03921c2c62..6831361b123 100644--- a/app/mailers/user_mailer.rb+++ b/app/mailers/user_mailer.rb@@ -187,32 +187,6 @@ class UserMailer < ApplicationMailert(:mail_subject_account_activation_request, value: Setting.app_title))end- def reminder_mail(user, issues, days, group = nil)- @issues = issues- @days = days- @group = group-- 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'-- subject = if @group- t(:mail_subject_group_reminder, count: @issues.size, days: @days, group: @group.name)- else- t(:mail_subject_reminder, count: @issues.size, days: @days)- end-- send_mail(user, subject)- end-### E-Mail to inform admin about a failed account activation due to the user limit.#diff --git a/app/views/user_mailer/reminder_mail.html.erb b/app/views/user_mailer/reminder_mail.html.erbdeleted file mode 100644index 6c2c4821feb..00000000000--- a/app/views/user_mailer/reminder_mail.html.erb+++ /dev/null@@ -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>diff --git a/app/views/user_mailer/reminder_mail.text.erb b/app/views/user_mailer/reminder_mail.text.erbdeleted file mode 100644index cc54d5b9f89..00000000000--- a/app/views/user_mailer/reminder_mail.text.erb+++ /dev/null@@ -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 %>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex bad58e38673..dd98447abbb 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2166,8 +2166,6 @@ en:mail_subject_incoming_email_error: "An email you sent to OpenProject could not be processed"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.rbdeleted file mode 100644index 38a26f52c80..00000000000--- a/lib/open_project/reminders/due_issues_reminder.rb+++ /dev/null@@ -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-enddiff --git a/lib/tasks/reminder.rake b/lib/tasks/reminder.rakedeleted file mode 100644index 2b05e5db31e..00000000000--- a/lib/tasks/reminder.rake+++ /dev/null@@ -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-enddiff --git a/spec/lib/reminders/due_issues_reminder_spec.rb b/spec/lib/reminders/due_issues_reminder_spec.rbdeleted file mode 100644index beb6b5d162d..00000000000--- a/spec/lib/reminders/due_issues_reminder_spec.rb+++ /dev/null@@ -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: '[email protected]') }- 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: '[email protected]') }- let!(:user2) { create(:user, mail: '[email protected]') }- 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