[Git][noosfero/noosfero][master] Adds profile admin task email notification option
Rodrigo Souto
gitlab at mg.gitlab.com
Tue Mar 15 14:18:13 BRT 2016
Rodrigo Souto pushed to branch master at Noosfero / noosfero
Commits:
789dc2c9 by Carlos Purificacao at 2016-03-15T14:17:38-03:00
Adds profile admin task email notification option
Signed-off-by: Marcos Ronaldo <marcos.rpj2 at gmail.com>
Signed-off-by: Gustavo Jaruga <darkshades at gmail.com>
- - - - -
5 changed files:
- app/models/profile.rb
- app/models/task.rb
- app/views/profile_editor/_moderation.html.erb
- test/functional/profile_editor_controller_test.rb
- test/unit/task_test.rb
Changes:
=====================================
app/models/profile.rb
=====================================
--- 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
=====================================
app/models/task.rb
=====================================
--- 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.
=====================================
app/views/profile_editor/_moderation.html.erb
=====================================
--- a/app/views/profile_editor/_moderation.html.erb
+++ b/app/views/profile_editor/_moderation.html.erb
@@ -1,6 +1,16 @@
<h2><%= _('Moderation options') %></h2>
<% if profile.community? %>
<div style='margin-bottom: 1em'>
+ <h4><%= _('Email Configuration:')%></h4>
+ </div>
+ <div style='margin-bottom: 0.5em'>
+ <%= check_box(:profile_data, :profile_admin_mail_notification, :style => 'float: left') %>
+ <div style='margin-left: 30px'>
+ <%= _('Send administrator Email for every task') %>
+ </div>
+ </div>
+
+ <div style='margin-bottom: 1em'>
<h4><%= _('Invitation moderation:')%></h4>
</div>
<div style='margin-bottom: 0.5em'>
=====================================
test/functional/profile_editor_controller_test.rb
=====================================
--- 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
=====================================
test/unit/task_test.rb
=====================================
--- 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 at 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 at 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!
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/789dc2c90bd887241b9ee9a24011c9d594ba25ac
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160315/176c6754/attachment.html>
More information about the Noosfero-dev
mailing list