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
PR fixes
Yegor Tovstikb503f579e08b
diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rbindex 29e801f11bc..98671b66bb9 100644--- a/app/mailers/user_mailer.rb+++ b/app/mailers/user_mailer.rb@@ -74,25 +74,11 @@ class UserMailer < BaseMailerendend- def work_package_watcher_added(work_package, user, watcher_setter)+ def work_package_watcher_changed(work_package, user, watcher_changer, action)User.execute_as user do@issue = work_package- @watcher_setter = watcher_setter-- set_work_package_headers(work_package)- message_id work_package, user- references work_package, user-- with_locale_for(user) do- mail to: user.mail, subject: subject_for_work_package(work_package)- end- end- end-- def work_package_watcher_removed(work_package, user, watcher_remover)- User.execute_as user do- @issue = work_package- @watcher_remover = watcher_remover+ @watcher_changer = watcher_changer+ @action = actionset_work_package_headers(work_package)message_id work_package, userdiff --git a/app/views/user_mailer/work_package_watcher_added.html.erb b/app/views/user_mailer/work_package_watcher_added.html.erbdeleted file mode 100644index bc3e9d594ae..00000000000--- a/app/views/user_mailer/work_package_watcher_added.html.erb+++ /dev/null@@ -1,37 +0,0 @@-<%#-- copyright-OpenProject is a project management system.-Copyright (C) 2012-2018 the OpenProject Foundation (OPF)--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-2017 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 docs/COPYRIGHT.rdoc for more details.--++#%>-<%= t(:text_work_package_watcher_added, id: "##{@issue.id}", watcher_setter: @watcher_setter) %>-<hr />-<%= render partial: 'issue_details', locals: { issue: @issue } %>-<p>- <%= format_text(t(:text_latest_note, note: last_issue_note(@issue)),- only_path: false,- object: @issue,- project: @issue.project) %>-</p>diff --git a/app/views/user_mailer/work_package_watcher_removed.html.erb b/app/views/user_mailer/work_package_watcher_changed.html.erbsimilarity index 93%rename from app/views/user_mailer/work_package_watcher_removed.html.erbrename to app/views/user_mailer/work_package_watcher_changed.html.erbindex 14a428323c4..b7041b3635d 100644--- a/app/views/user_mailer/work_package_watcher_removed.html.erb+++ b/app/views/user_mailer/work_package_watcher_changed.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.++#%>-<%= t(:text_work_package_watcher_removed, id: "##{@issue.id}", watcher_remover: @watcher_remover) %>+<%= t("text_work_package_watcher_#{@action}", id: "##{@issue.id}", watcher_changer: @watcher_changer) %><hr /><%= render partial: 'issue_details', locals: { issue: @issue } %><p>diff --git a/app/views/user_mailer/work_package_watcher_added.text.erb b/app/views/user_mailer/work_package_watcher_changed.text.erbsimilarity index 92%rename from app/views/user_mailer/work_package_watcher_added.text.erbrename to app/views/user_mailer/work_package_watcher_changed.text.erbindex e0be3dd88d8..da405e83b40 100644--- a/app/views/user_mailer/work_package_watcher_added.text.erb+++ b/app/views/user_mailer/work_package_watcher_changed.text.erb@@ -27,7 +27,7 @@ See docs/COPYRIGHT.rdoc for more details.++#%>-<%= t(:text_work_package_watcher_added, id: "##{@issue.id}", watcher_setter: @watcher_setter) %>+<%= t("text_work_package_watcher_#{@action}", id: "##{@issue.id}", watcher_changer: @watcher_changer) %>----------------------------------------<%= render partial: 'issue_details', locals: { issue: @issue } %>diff --git a/app/views/user_mailer/work_package_watcher_removed.text.erb b/app/views/user_mailer/work_package_watcher_removed.text.erbdeleted file mode 100644index e0be3dd88d8..00000000000--- a/app/views/user_mailer/work_package_watcher_removed.text.erb+++ /dev/null@@ -1,34 +0,0 @@-<%#-- copyright-OpenProject is a project management system.-Copyright (C) 2012-2018 the OpenProject Foundation (OPF)--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-2017 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 docs/COPYRIGHT.rdoc for more details.--++#%>--<%= t(:text_work_package_watcher_added, id: "##{@issue.id}", watcher_setter: @watcher_setter) %>-------------------------------------------<%= render partial: 'issue_details', locals: { issue: @issue } %>-<%= t(:text_latest_note, note: last_issue_note(@issue)) %>diff --git a/app/workers/deliver_watcher_added_notification_job.rb b/app/workers/deliver_watcher_added_notification_job.rbindex 0c4c7a57a58..14edacbac91 100644--- a/app/workers/deliver_watcher_added_notification_job.rb+++ b/app/workers/deliver_watcher_added_notification_job.rb@@ -32,6 +32,6 @@ class DeliverWatcherAddedNotificationJob < DeliverWatcherNotificationJobdef render_mail(recipient:, sender:)return unless watcher- UserMailer.work_package_watcher_added(watcher.watchable, recipient, sender)+ UserMailer.work_package_watcher_changed(watcher.watchable, recipient, sender, 'added')endenddiff --git a/app/workers/deliver_watcher_removed_notification_job.rb b/app/workers/deliver_watcher_removed_notification_job.rbindex a12f1d4ee44..3b6e8ca5a6e 100644--- a/app/workers/deliver_watcher_removed_notification_job.rb+++ b/app/workers/deliver_watcher_removed_notification_job.rb@@ -39,6 +39,6 @@ class DeliverWatcherRemovedNotificationJob < DeliverWatcherNotificationJobdef render_mail(recipient:, sender:)return unless watcher- UserMailer.work_package_watcher_removed(watcher.watchable, recipient, sender)+ UserMailer.work_package_watcher_changed(watcher.watchable, recipient, sender, 'removed')endenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 99b042b5188..aae41418d32 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2315,8 +2315,8 @@ en:text_work_package_category_destroy_question: "Some work packages (%{count}) are assigned to this category. What do you want to do?"text_work_package_category_reassign_to: "Reassign work packages to this category"text_work_package_updated: "Work package %{id} has been updated by %{author}."- text_work_package_watcher_added: "You have been added as a watcher to Work package %{id} by %{watcher_setter}."- text_work_package_watcher_removed: "You have been removed from watchers of Work package %{id} by %{watcher_remover}."+ text_work_package_watcher_added: "You have been added as a watcher to Work package %{id} by %{watcher_changer}."+ text_work_package_watcher_removed: "You have been removed from watchers of Work package %{id} by %{watcher_changer}."text_work_packages_destroy_confirmation: "Are you sure you want to delete the selected work package(s)?"text_work_packages_ref_in_commit_messages: "Referencing and fixing work packages in commit messages"text_journal_added: "%{label} %{value} added"diff --git a/lib/services/remove_watcher.rb b/lib/services/remove_watcher.rbindex e52dccce45f..546cc4e121e 100644--- a/lib/services/remove_watcher.rb+++ b/lib/services/remove_watcher.rb@@ -33,12 +33,13 @@ class Services::RemoveWatcherenddef run(success: -> {}, failure: -> {})- if @work_package.watcher_users.include?(@user)- @watcher = @work_package.watchers.find_by_user_id(@user.id)+ watcher = @work_package.watchers.find_by_user_id(@user.id)++ if watcher.present?@work_package.watcher_users.delete(@user)success.callOpenProject::Notifications.send('watcher_removed',- watcher: @watcher,+ watcher: watcher,watcher_remover: User.current)elsefailure.calldiff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rbindex 2023c07a733..4e99092c714 100644--- a/spec/mailers/user_mailer_spec.rb+++ b/spec/mailers/user_mailer_spec.rb@@ -53,8 +53,10 @@ describe UserMailer, type: :mailer doendshared_examples_for 'mail is sent' do+ let(:letters_sent_count) { 1 }+it 'actually sends a mail' do- expect(ActionMailer::Base.deliveries.size).to eql(1)+ expect(ActionMailer::Base.deliveries.size).to eql(letters_sent_count)endit 'is sent to the recipient' do@@ -66,6 +68,12 @@ describe UserMailer, type: :mailer doendend+ shared_examples_for 'multiple mails are sent' do |set_letters_sent_count|+ it_behaves_like 'mail is sent' do+ let(:letters_sent_count) { set_letters_sent_count }+ end+ end+shared_examples_for 'mail is not sent' doit 'sends no mail' doexpect(ActionMailer::Base.deliveries.size).to eql(0)@@ -130,26 +138,14 @@ describe UserMailer, type: :mailer doit_behaves_like 'does only send mails to author if permitted'end- describe '#work_package_watcher_added' do- let(:watcher_setter) { user }+ describe '#work_package_watcher_changed' do+ let(:watcher_changer) { user }before do- UserMailer.work_package_watcher_added(work_package, recipient, watcher_setter).deliver_now+ UserMailer.work_package_watcher_changed(work_package, recipient, watcher_changer, 'added').deliver_now+ UserMailer.work_package_watcher_changed(work_package, recipient, watcher_changer, 'removed').deliver_nowend- it_behaves_like 'mail is sent'-- it 'contains the WP subject in the mail subject' do- expect(ActionMailer::Base.deliveries.first.subject).to include(work_package.subject)- end- end-- describe '#work_package_watcher_removed' do- let(:watcher_remover) { user }- before do- UserMailer.work_package_watcher_removed(work_package, recipient, watcher_remover).deliver_now- end-- it_behaves_like 'mail is sent'+ include_examples 'multiple mails are sent', 2it 'contains the WP subject in the mail subject' doexpect(ActionMailer::Base.deliveries.first.subject).to include(work_package.subject)diff --git a/spec/workers/mail_notification_jobs/deliver_watcher_notification_job_spec.rb b/spec/workers/mail_notification_jobs/deliver_watcher_notification_job_spec.rbindex bdaccdd5b03..3928426bb2e 100644--- a/spec/workers/mail_notification_jobs/deliver_watcher_notification_job_spec.rb+++ b/spec/workers/mail_notification_jobs/deliver_watcher_notification_job_spec.rb@@ -29,8 +29,8 @@require 'spec_helper'-shared_examples "DeliverWatcherNotificationJob" do |mailer_method_name|- let(:mailer_method_name) { mailer_method_name }+shared_examples "DeliverWatcherNotificationJob" do |action|+ let(:action) { action }let(:project) { FactoryBot.create(:project) }let(:role) { FactoryBot.create(:role, permissions: [:view_work_packages]) }let(:watcher_changer) { FactoryBot.create(:user) }@@ -44,14 +44,15 @@ shared_examples "DeliverWatcherNotificationJob" do |mailer_method_name|before do# make sure no actual calls make it into the UserMailer- allow(UserMailer).to receive(mailer_method_name)+ allow(UserMailer).to receive(:work_package_watcher_changed).and_return(double('mail', deliver_now: nil))endit 'sends a mail' do- expect(UserMailer).to receive(mailer_method_name).with(work_package,- watcher_user,- watcher_changer)+ expect(UserMailer).to receive(:work_package_watcher_changed).with(work_package,+ watcher_user,+ watcher_changer,+ action)subjectend@@ -60,7 +61,7 @@ shared_examples "DeliverWatcherNotificationJob" do |mailer_method_name|before domail = double('mail')allow(mail).to receive(:deliver_now).and_raise(SocketError)- expect(UserMailer).to receive(mailer_method_name).and_return(mail)+ expect(UserMailer).to receive(:work_package_watcher_changed).and_return(mail)endit 'raises the error' do@@ -71,13 +72,13 @@ shared_examples "DeliverWatcherNotificationJob" do |mailer_method_name|enddescribe DeliverWatcherRemovedNotificationJob, type: :model do- include_examples "DeliverWatcherNotificationJob", :work_package_watcher_removed do+ include_examples "DeliverWatcherNotificationJob", 'removed' dolet(:watcher_parameter) { watcher.attributes }endenddescribe DeliverWatcherAddedNotificationJob, type: :model do- include_examples "DeliverWatcherNotificationJob", :work_package_watcher_added do+ include_examples "DeliverWatcherNotificationJob", 'added' dolet(:watcher_parameter) { watcher }endend