diff --git a/app/models/profile.rb b/app/models/profile.rb index 23ec42d..3ea1cd2 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -5,7 +5,7 @@ class Profile < ActiveRecord::Base attr_accessible :name, :identifier, :public_profile, :nickname, :custom_footer, :custom_header, :address, :zip_code, :contact_phone, :image_builder, :description, :closed, :template_id, :environment, :lat, :lng, :is_template, :fields_privacy, :preferred_domain_id, :category_ids, :country, :city, :state, :national_region_code, :email, :contact_email, :redirect_l10n, :notification_time, :redirection_after_login, :custom_url_redirection, - :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret + :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, :profile_admin_mail_notification # use for internationalizable human type names in search facets # reimplement on subclasses @@ -245,6 +245,7 @@ class Profile < ActiveRecord::Base settings_items :description settings_items :fields_privacy, :type => :hash, :default => {} settings_items :email_suggestions, :type => :boolean, :default => false + settings_items :profile_admin_mail_notification, :type => :boolean, :default => true validates_length_of :description, :maximum => 550, :allow_nil => true diff --git a/app/models/task.rb b/app/models/task.rb index eceee59..6e1c2e4 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -67,7 +67,9 @@ class Task < ActiveRecord::Base begin target_msg = task.target_notification_message if target_msg && task.target && !task.target.notification_emails.empty? - TaskMailer.target_notification(task, target_msg).deliver + if target_profile_accepts_notification?(task) + TaskMailer.target_notification(task, target_msg).deliver + end end rescue NotImplementedError => ex Rails.logger.info ex.to_s @@ -75,6 +77,14 @@ class Task < ActiveRecord::Base end end + def target_profile_accepts_notification?(task) + if task.target.kind_of? Organization + return task.target.profile_admin_mail_notification + else + true + end + end + # this method finished the task. It calls #perform, which must be overriden # by subclasses. At the end a message (as returned by #finish_message) is # sent to the requestor with #notify_requestor. diff --git a/app/views/profile_editor/_moderation.html.erb b/app/views/profile_editor/_moderation.html.erb index 749c653..0d3cb54 100644 --- a/app/views/profile_editor/_moderation.html.erb +++ b/app/views/profile_editor/_moderation.html.erb @@ -1,6 +1,16 @@

<%= _('Moderation options') %>

<% if profile.community? %>
+

<%= _('Email Configuration:')%>

+
+
+ <%= check_box(:profile_data, :profile_admin_mail_notification, :style => 'float: left') %> +
+ <%= _('Send administrator Email for every task') %> +
+
+ +

<%= _('Invitation moderation:')%>

diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index b48fa5b..d931ee3 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -1213,4 +1213,11 @@ class ProfileEditorControllerTest < ActionController::TestCase assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/profile_roles" } end + should 'save profile admin option to receive email for every task' do + comm = fast_create(Community) + assert comm.profile_admin_mail_notification + post :edit, :profile => comm.identifier, :profile_data => { :profile_admin_mail_notification => '0' } + refute comm.reload.profile_admin_mail_notification + end + end diff --git a/test/unit/task_test.rb b/test/unit/task_test.rb index 4956983..2c570ee 100644 --- a/test/unit/task_test.rb +++ b/test/unit/task_test.rb @@ -182,6 +182,31 @@ class TaskTest < ActiveSupport::TestCase task.save! end + should 'not send notification to target if notification is disabled in profile' do + task = Task.new + target = fast_create(Organization) + target.stubs(:notification_emails).returns(['adm@example.com']) + target.stubs(:profile_admin_mail_notification).returns(false) + task.target = target + task.stubs(:target_notification_message).returns('some non nil message to be sent to target') + TaskMailer.expects(:target_notification).never + task.save! + end + + should 'send notification to target if notification is enabled in profile' do + task = Task.new + target = fast_create(Organization) + target.stubs(:notification_emails).returns(['adm@example.com']) + target.stubs(:profile_admin_mail_notification).returns(true) + task.target = target + task.stubs(:target_notification_message).returns('some non nil message to be sent to target') + + mailer = mock + mailer.expects(:deliver).once + TaskMailer.expects(:target_notification).returns(mailer).once + task.save! + end + should 'be able to list pending tasks' do Task.delete_all t1 = Task.create! -- libgit2 0.21.2