[Git][noosfero/noosfero][master] 2 commits: Adds integration between moderation email to accept new users and custom fields

Tallys Martins gitlab at mg.gitlab.com
Thu Mar 2 23:59:11 BRT 2017


Tallys Martins pushed to branch master at Noosfero / noosfero


Commits:
f402771c by Victor Navarro at 2017-03-02T10:34:00-03:00
Adds integration between moderation email to accept new users and custom fields

Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>
Signed-off-by: Sabryna Sousa <sabryna.sousa1323 at gmail.com>
Signed-off-by: Victor Navarro <victor.matias.navarro at gmail.com>

- - - - -
51598216 by Tallys Martins at 2017-03-02T23:58:37-03:00
Merge branch 'custom_fields_email'

- - - - -


3 changed files:

- app/models/moderate_user_registration.rb
- test/functional/tasks_controller_test.rb
- test/unit/moderate_user_registration_test.rb


Changes:

=====================================
app/models/moderate_user_registration.rb
=====================================
--- a/app/models/moderate_user_registration.rb
+++ b/app/models/moderate_user_registration.rb
@@ -59,7 +59,21 @@ class ModerateUserRegistration < Task
   end
 
   def target_notification_message
-    _("User \"%{user}\" just requested to register. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.name }
+    _("User \"%{user}\" just requested to register. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.name } + target_custom_fields
+  end
+
+  def target_custom_fields
+    header = ""
+    reason = ""
+    if requestor.present?
+      requestor.custom_field_values.includes(:custom_field).each do |custom_value|
+          if custom_value.custom_field.moderation_task
+            header = _("\nModerated Fields\n")
+            reason += "#{custom_value.custom_field.name}: #{custom_value.value}\n"
+          end
+      end
+    end
+    header + reason
   end
 
 end


=====================================
test/functional/tasks_controller_test.rb
=====================================
--- a/test/functional/tasks_controller_test.rb
+++ b/test/functional/tasks_controller_test.rb
@@ -719,6 +719,35 @@ class TasksControllerTest < ActionController::TestCase
     assert_tag :tag=> 'div', :attributes => { :class => 'field-name' }, :content => /great_field: new_value!/
   end
 
+  should 'list custom fields in moderation email if moderation tasks if true' do
+    person_custom_field = CustomField.create(:name => "registration_reason", :format=>"string", :default_value => "because i want to", :customized_type=>"Person", :active => true, :environment => Environment.default, :moderation_task => true, :required => true)
+    p1 = create_user("great_person").person
+    p1.custom_values = {"registration_reason" => "I want to send my TCC"}
+    p1.save!
+    p1.reload
+    admin = create_user("admin").person
+    Environment.default.add_admin(admin)
+
+    task = ModerateUserRegistration.create!(:requestor => p1, :name => "great_person", :email => "alo at alo.alo", :target => Environment.default)
+    email = ActionMailer::Base.deliveries.last
+    assert_match /#{task.target_custom_fields}/, email.body.to_s
+  end
+
+  should 'not list custom fields in moderation email if moderation tasks is false' do
+    person_custom_field = CustomField.create(:name => "registration_reason", :format=>"string", :default_value => "because i want to", :customized_type=>"Person", :active => true, :environment => Environment.default, :moderation_task => false, :required => true)
+    p1 = create_user("great_person").person
+    p1.custom_values = {"registration_reason" => "I want to send my TCC"}
+    p1.save!
+    p1.reload
+    admin = create_user("admin").person
+    Environment.default.add_admin(admin)
+
+    task = ModerateUserRegistration.create!(:requestor => p1, :name => "great_person", :email => "alo at alo.alo", :target => Environment.default)
+    email = ActionMailer::Base.deliveries.last
+    assert_no_match /#{person_custom_field.name}/, email.body.to_s
+  end
+
+
   should 'list custom field details in moderation of community creation tasks when moderation_tasks is true' do
     community_custom_field = CustomField.create(:name => "great_field", :format=>"string", :default_value => "value for community", :customized_type=>"Community", :active => true, :environment => Environment.default, :moderation_task => true, :required => true)
     p1 = create_user("great_person").person


=====================================
test/unit/moderate_user_registration_test.rb
=====================================
--- a/test/unit/moderate_user_registration_test.rb
+++ b/test/unit/moderate_user_registration_test.rb
@@ -19,4 +19,19 @@ class ModerateUserRegistrationTest < ActiveSupport::TestCase
     t.perform
     assert environment.users.find_by(id: user.id).activated?
   end
+
+  should 'return the names of the custom fields' do
+    person_custom_field = CustomField.create(:name => "registration_reason", :format=>"string", :default_value => "because i want to", :customized_type=>"Person", :active => true, :environment => Environment.default, :moderation_task => true, :required => true)
+    user = User.new(:login => 'lalala', :email => 'lalala at example.com', :password => 'test', :password_confirmation => 'test')
+    user.save!
+    p1 = user.person
+    p1.custom_values = {"registration_reason" => "I want to send my TCC"}
+    p1.save!
+    p1.reload
+    task = ModerateUserRegistration.create!(:requestor => p1, :name => "great_person", :email => "alo at alo.alo", :target => Environment.default)
+    task.save
+
+    assert_match /registration_reason/, task.target_custom_fields
+    assert_match /I want to send my TCC/, task.target_custom_fields
+  end
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/31420253e6c14420627735e5811dec7322e71cb7...515982161c7f8b331ae75aa4045c2a586668035c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170303/749c8c87/attachment-0001.html>


More information about the Noosfero-dev mailing list