Commit 789dc2c90bd887241b9ee9a24011c9d594ba25ac
Committed by
Rodrigo Souto
1 parent
753770b3
Exists in
web_steps_improvements
and in
9 other branches
Adds profile admin task email notification option
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com> Signed-off-by: Gustavo Jaruga <darkshades@gmail.com>
Showing
5 changed files
with
55 additions
and
2 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -5,7 +5,7 @@ class Profile < ActiveRecord::Base |
5 | 5 | |
6 | 6 | 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, |
7 | 7 | :redirection_after_login, :custom_url_redirection, |
8 | - :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret | |
8 | + :email_suggestions, :allow_members_to_invite, :invite_friends_only, :secret, :profile_admin_mail_notification | |
9 | 9 | |
10 | 10 | # use for internationalizable human type names in search facets |
11 | 11 | # reimplement on subclasses |
... | ... | @@ -245,6 +245,7 @@ class Profile < ActiveRecord::Base |
245 | 245 | settings_items :description |
246 | 246 | settings_items :fields_privacy, :type => :hash, :default => {} |
247 | 247 | settings_items :email_suggestions, :type => :boolean, :default => false |
248 | + settings_items :profile_admin_mail_notification, :type => :boolean, :default => true | |
248 | 249 | |
249 | 250 | validates_length_of :description, :maximum => 550, :allow_nil => true |
250 | 251 | ... | ... |
app/models/task.rb
... | ... | @@ -67,7 +67,9 @@ class Task < ActiveRecord::Base |
67 | 67 | begin |
68 | 68 | target_msg = task.target_notification_message |
69 | 69 | if target_msg && task.target && !task.target.notification_emails.empty? |
70 | - TaskMailer.target_notification(task, target_msg).deliver | |
70 | + if target_profile_accepts_notification?(task) | |
71 | + TaskMailer.target_notification(task, target_msg).deliver | |
72 | + end | |
71 | 73 | end |
72 | 74 | rescue NotImplementedError => ex |
73 | 75 | Rails.logger.info ex.to_s |
... | ... | @@ -75,6 +77,14 @@ class Task < ActiveRecord::Base |
75 | 77 | end |
76 | 78 | end |
77 | 79 | |
80 | + def target_profile_accepts_notification?(task) | |
81 | + if task.target.kind_of? Organization | |
82 | + return task.target.profile_admin_mail_notification | |
83 | + else | |
84 | + true | |
85 | + end | |
86 | + end | |
87 | + | |
78 | 88 | # this method finished the task. It calls #perform, which must be overriden |
79 | 89 | # by subclasses. At the end a message (as returned by #finish_message) is |
80 | 90 | # sent to the requestor with #notify_requestor. | ... | ... |
app/views/profile_editor/_moderation.html.erb
1 | 1 | <h2><%= _('Moderation options') %></h2> |
2 | 2 | <% if profile.community? %> |
3 | 3 | <div style='margin-bottom: 1em'> |
4 | + <h4><%= _('Email Configuration:')%></h4> | |
5 | + </div> | |
6 | + <div style='margin-bottom: 0.5em'> | |
7 | + <%= check_box(:profile_data, :profile_admin_mail_notification, :style => 'float: left') %> | |
8 | + <div style='margin-left: 30px'> | |
9 | + <%= _('Send administrator Email for every task') %> | |
10 | + </div> | |
11 | + </div> | |
12 | + | |
13 | + <div style='margin-bottom: 1em'> | |
4 | 14 | <h4><%= _('Invitation moderation:')%></h4> |
5 | 15 | </div> |
6 | 16 | <div style='margin-bottom: 0.5em'> | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -1213,4 +1213,11 @@ class ProfileEditorControllerTest < ActionController::TestCase |
1213 | 1213 | assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/profile_roles" } |
1214 | 1214 | end |
1215 | 1215 | |
1216 | + should 'save profile admin option to receive email for every task' do | |
1217 | + comm = fast_create(Community) | |
1218 | + assert comm.profile_admin_mail_notification | |
1219 | + post :edit, :profile => comm.identifier, :profile_data => { :profile_admin_mail_notification => '0' } | |
1220 | + refute comm.reload.profile_admin_mail_notification | |
1221 | + end | |
1222 | + | |
1216 | 1223 | end | ... | ... |
test/unit/task_test.rb
... | ... | @@ -182,6 +182,31 @@ class TaskTest < ActiveSupport::TestCase |
182 | 182 | task.save! |
183 | 183 | end |
184 | 184 | |
185 | + should 'not send notification to target if notification is disabled in profile' do | |
186 | + task = Task.new | |
187 | + target = fast_create(Organization) | |
188 | + target.stubs(:notification_emails).returns(['adm@example.com']) | |
189 | + target.stubs(:profile_admin_mail_notification).returns(false) | |
190 | + task.target = target | |
191 | + task.stubs(:target_notification_message).returns('some non nil message to be sent to target') | |
192 | + TaskMailer.expects(:target_notification).never | |
193 | + task.save! | |
194 | + end | |
195 | + | |
196 | + should 'send notification to target if notification is enabled in profile' do | |
197 | + task = Task.new | |
198 | + target = fast_create(Organization) | |
199 | + target.stubs(:notification_emails).returns(['adm@example.com']) | |
200 | + target.stubs(:profile_admin_mail_notification).returns(true) | |
201 | + task.target = target | |
202 | + task.stubs(:target_notification_message).returns('some non nil message to be sent to target') | |
203 | + | |
204 | + mailer = mock | |
205 | + mailer.expects(:deliver).once | |
206 | + TaskMailer.expects(:target_notification).returns(mailer).once | |
207 | + task.save! | |
208 | + end | |
209 | + | |
185 | 210 | should 'be able to list pending tasks' do |
186 | 211 | Task.delete_all |
187 | 212 | t1 = Task.create! | ... | ... |