]> source.dussan.org Git - redmine.git/commitdiff
Adds an option to send email notification when an attachment is added (#40569).
authorMarius Balteanu <marius.balteanu@zitec.com>
Sun, 28 Apr 2024 06:40:12 +0000 (06:40 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Sun, 28 Apr 2024 06:40:12 +0000 (06:40 +0000)
Patch by  Mizuki ISHIKAWA (#ishikawa999).

git-svn-id: https://svn.redmine.org/redmine/trunk@22790 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/journal.rb
config/locales/en.yml
lib/redmine/notifiable.rb
test/unit/journal_observer_test.rb
test/unit/lib/redmine/notifiable_test.rb

index 5468c8629eb8a06269e5d6cf5457bfbb2bdf62fb..24c54544bd3e234626b633b7155e2d6ee3f4bbe7 100644 (file)
@@ -354,7 +354,8 @@ class Journal < ApplicationRecord
           (Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
           (Setting.notified_events.include?('issue_assigned_to_updated') && detail_for_attribute('assigned_to_id').present?) ||
           (Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?) ||
-          (Setting.notified_events.include?('issue_fixed_version_updated') && detail_for_attribute('fixed_version_id').present?)
+          (Setting.notified_events.include?('issue_fixed_version_updated') && detail_for_attribute('fixed_version_id').present?) ||
+          (Setting.notified_events.include?('issue_attachment_added') && details.any? {|d| d.property == 'attachment' && d.value })
         )
       Mailer.deliver_issue_edit(self)
     end
index 0fa3b02349f5349d7674a0fd668b2d8b1789ebc2..ecda509ecccacd933a28d7cdcab3b3a79354d39c 100644 (file)
@@ -629,6 +629,7 @@ en:
   label_issue_assigned_to_updated: Assignee updated
   label_issue_priority_updated: Priority updated
   label_issue_fixed_version_updated: Target version updated
+  label_issue_attachment_added: Attachment added
   label_document: Document
   label_document_new: New document
   label_document_plural: Documents
index 6fce9122d5cccce0b7c78de7f9c757de13711032..05400b7ad60e0e0160dfecf6ba3183142a7a673b 100644 (file)
@@ -34,6 +34,7 @@ module Redmine
       notifications << Notifiable.new('issue_assigned_to_updated', 'issue_updated')
       notifications << Notifiable.new('issue_priority_updated', 'issue_updated')
       notifications << Notifiable.new('issue_fixed_version_updated', 'issue_updated')
+      notifications << Notifiable.new('issue_attachment_added', 'issue_updated')
       notifications << Notifiable.new('news_added')
       notifications << Notifiable.new('news_comment_added')
       notifications << Notifiable.new('document_added')
index 0452d66c3cb220e5411e09b3f8b04d523fe8f3a5..ed6931893c3a01de40ba57e51c7bfefcfdca460c 100644 (file)
@@ -23,7 +23,7 @@ class JournalObserverTest < ActiveSupport::TestCase
   fixtures :issues, :issue_statuses, :journals, :journal_details, :projects,
            :projects_trackers, :trackers, :enabled_modules, :enumerations,
            :users, :user_preferences, :email_addresses, :roles, :members, :member_roles,
-           :versions, :issue_categories
+           :versions, :issue_categories, :attachments
 
   def setup
     User.current = nil
@@ -198,4 +198,34 @@ class JournalObserverTest < ActiveSupport::TestCase
       assert_equal 0, ActionMailer::Base.deliveries.size
     end
   end
+
+  def test_create_should_send_email_notification_with_issue_attachment_added
+    set_tmp_attachments_directory
+    with_settings :notified_events => %w(issue_attachment_added) do
+      user = User.find_by_login('jsmith')
+      issue = issues(:issues_001)
+      issue.init_journal(user)
+      issue.save_attachments(
+        { 'p0' => {'file' => mock_file_with_options(:original_filename => 'upload')} }
+      )
+
+      assert issue.save
+      assert_equal 2, ActionMailer::Base.deliveries.size
+    end
+  end
+
+  def test_create_should_not_send_email_notification_without_issue_attachment_added
+    set_tmp_attachments_directory
+    with_settings :notified_events => [] do
+      user = User.find_by_login('jsmith')
+      issue = issues(:issues_001)
+      issue.init_journal(user)
+      issue.save_attachments(
+        { 'p0' => {'file' => mock_file_with_options(:original_filename => 'upload')} }
+      )
+
+      assert issue.save
+      assert_equal 0, ActionMailer::Base.deliveries.size
+    end
+  end
 end
index 69acbe59627b0a720632f30c6a773a6e1e6b5771..ee424663e2564f50e29ffe62fbbc2e017ce0d45d 100644 (file)
@@ -25,7 +25,7 @@ class Redmine::NotifiableTest < ActiveSupport::TestCase
 
   def test_all
     %w(issue_added issue_updated issue_note_added issue_status_updated
-       issue_assigned_to_updated issue_priority_updated news_added
+       issue_assigned_to_updated issue_priority_updated issue_fixed_version_updated issue_attachment_added news_added
        news_comment_added document_added file_added
        message_posted
        wiki_content_added wiki_content_updated).each do |notifiable|