diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 051f8910..55c42a60 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -132,6 +132,7 @@ class IssuesController < ApplicationController def create call_hook(:controller_issues_new_before_save, { :params => params, :issue => @issue }) + IssueObserver.instance.send_notification = params[:send_notification] == '0' ? false : true if @issue.save attachments = Attachment.attach_files(@issue, params[:attachments]) render_attachment_warning_if_needed(@issue) @@ -166,7 +167,7 @@ class IssuesController < ApplicationController def update update_issue_from_params - + JournalObserver.instance.send_notification = params[:send_notification] == '0' ? false : true if @issue.save_issue_with_child_records(params, @time_entry) render_attachment_warning_if_needed(@issue) flash[:notice] = l(:notice_successful_update) unless @issue.current_journal.new_record? @@ -206,6 +207,7 @@ class IssuesController < ApplicationController journal = issue.init_journal(User.current, params[:notes]) issue.safe_attributes = attributes call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) + JournalObserver.instance.send_notification = params[:send_notification] == '0' ? false : true unless issue.save # Keep unsaved issue ids to display them in flash error unsaved_issue_ids << issue.id diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index ce23668e..6faadf2a 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -260,4 +260,14 @@ module IssuesHelper end export end + + def send_notification_option + content_tag(:p, + content_tag(:label, + l(:label_notify_member_plural)) + + hidden_field_tag('send_notification', '0') + + check_box_tag('send_notification', '1', true)) + + + end end diff --git a/app/models/issue_observer.rb b/app/models/issue_observer.rb index bdb5c1d4..2a563a5a 100644 --- a/app/models/issue_observer.rb +++ b/app/models/issue_observer.rb @@ -16,7 +16,25 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class IssueObserver < ActiveRecord::Observer + attr_accessor :send_notification + def after_create(issue) - Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added') + if self.send_notification + Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added') + end + clear_notification + end + + # Wrap send_notification so it defaults to true, when it's nil + def send_notification + return true if @send_notification.nil? + return @send_notification + end + + private + + # Need to clear the notification setting after each usage otherwise it might be cached + def clear_notification + @send_notification = true end end diff --git a/app/models/journal_observer.rb b/app/models/journal_observer.rb index db7115cd..b006ad64 100644 --- a/app/models/journal_observer.rb +++ b/app/models/journal_observer.rb @@ -16,12 +16,28 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class JournalObserver < ActiveRecord::Observer + attr_accessor :send_notification + def after_create(journal) if Setting.notified_events.include?('issue_updated') || (Setting.notified_events.include?('issue_note_added') && journal.notes.present?) || (Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) || (Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?) - Mailer.deliver_issue_edit(journal) + Mailer.deliver_issue_edit(journal) if self.send_notification end + clear_notification + end + + # Wrap send_notification so it defaults to true, when it's nil + def send_notification + return true if @send_notification.nil? + return @send_notification + end + + private + + # Need to clear the notification setting after each usage otherwise it might be cached + def clear_notification + @send_notification = true end end diff --git a/app/views/issues/_edit.rhtml b/app/views/issues/_edit.rhtml index 6d74751f..6c9bc3d7 100644 --- a/app/views/issues/_edit.rhtml +++ b/app/views/issues/_edit.rhtml @@ -43,6 +43,8 @@ <%= render :partial => 'attachments/form' %> + + <%= send_notification_option %> <%= f.hidden_field :lock_version %> diff --git a/app/views/issues/bulk_edit.rhtml b/app/views/issues/bulk_edit.rhtml index b26e47c8..d7621e05 100644 --- a/app/views/issues/bulk_edit.rhtml +++ b/app/views/issues/bulk_edit.rhtml @@ -76,6 +76,7 @@
diff --git a/app/views/issues/new.rhtml b/app/views/issues/new.rhtml index 867590fa..b9d6f414 100644 --- a/app/views/issues/new.rhtml +++ b/app/views/issues/new.rhtml @@ -5,6 +5,7 @@ <%= error_messages_for 'issue' %>