[Git][noosfero/noosfero][master] 2 commits: Merge branch 'invalid_person' into 'master-1.x'

Rodrigo Souto gitlab at mg.gitlab.com
Wed Aug 1 08:43:11 BRT 2018


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
5c0978a6 by Rodrigo Souto at 2018-07-31T19:38:14Z
Merge branch 'invalid_person' into 'master-1.x'

Validate old phone fields and check person before send notifications

See merge request noosfero/noosfero!1578

(cherry picked from commit 55ccdd52a7d905563d3df928f4e648f7b328d472)

8dac00b5 Add migrate to validate phone fields
1afd6fbe Validate person before sending the emails
96056bb2 Remove recreation from job in PersonNotifier after failure
864c6343 Change test to validate if don't create a new job when failed
a1152bce Fix phone length
- - - - -
5d461725 by Rodrigo Souto at 2018-08-01T11:42:54Z
Merge branch 'cherry-pick-55ccdd52' into 'master'

Merge branch 'invalid_person' into 'master-1.x'

See merge request noosfero/noosfero!1583
- - - - -


3 changed files:

- app/models/person_notifier.rb
- + db/migrate/20180716142038_change_phone_fields_to_valid_format.rb
- test/unit/person_notifier_test.rb


Changes:

=====================================
app/models/person_notifier.rb
=====================================
@@ -34,8 +34,12 @@ class PersonNotifier
       notifications = @person.tracked_notifications.where("created_at > ?", notify_from)
       tasks = Task.to(@person).without_spam.pending.where("created_at > ?", notify_from).order_by('created_at', 'asc')
 
-      Noosfero.with_locale @person.environment.default_language do
-        Mailer::content_summary(@person, notifications, tasks).deliver unless notifications.empty? && tasks.empty?
+      if @person.valid?
+        Noosfero.with_locale @person.environment.default_language do
+          unless notifications.empty? && tasks.empty?
+            Mailer::content_summary(@person, notifications, tasks).deliver
+          end
+        end
       end
       @person.settings[:last_notification] = DateTime.now
       @person.save!
@@ -66,11 +70,6 @@ class PersonNotifier
       Person.find(person_id).notifier.notify
     end
 
-    def failure(job)
-      person = Person.find(person_id)
-      person.notifier.dispatch_notification_mail
-    end
-
   end
 
   class Mailer < ApplicationMailer


=====================================
db/migrate/20180716142038_change_phone_fields_to_valid_format.rb
=====================================
@@ -0,0 +1,20 @@
+class ChangePhoneFieldsToValidFormat < ActiveRecord::Migration
+  def change
+    Person.find_each do |person|
+      unless person.valid?
+        Person::PHONE_FIELDS.each do |field|
+          phone = person.send(field)
+          if phone.present? && phone !~ Person::PHONE_FORMAT
+            field = field.to_s + "="
+            phone = phone.gsub(/\D/, '')
+            phone = phone.rjust(5, '0') if phone.length < 5
+            phone = phone[0, 15] if phone.length > 15
+            person.send(field, phone)
+          end
+        end
+        p person.name
+        person.save(validate: false)
+      end
+    end
+  end
+end


=====================================
test/unit/person_notifier_test.rb
=====================================
@@ -246,15 +246,15 @@ class PersonNotifierTest < ActiveSupport::TestCase
     assert_equal 1, Delayed::Job.count
   end
 
-  should 'NotifyJob failed jobs create a new NotifyJob on failure' do
+  should 'don\'t create a new NotifyJob on failure' do
     Delayed::Worker.max_attempts = 1
     Delayed::Job.enqueue(PersonNotifier::NotifyJob.new(@member.id))
 
     PersonNotifier.any_instance.stubs(:notify).raises('error')
 
-    process_delayed_job_queue
-    jobs = PersonNotifier::NotifyJob.find(@member.id)
-    refute jobs.select {|j| !j.failed? && j.last_error.nil? }.empty?
+    assert_no_difference 'job_count(PersonNotifier::NotifyJob)' do
+      process_delayed_job_queue
+    end
   end
 
   should 'render image tags for both internal and external src' do



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/c246a96a2f32b6ac342872dd146d978ebe52a40b...5d46172576a582f01623cc91cce4176494838723

-- 
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/c246a96a2f32b6ac342872dd146d978ebe52a40b...5d46172576a582f01623cc91cce4176494838723
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20180801/e9b8e185/attachment-0001.html>


More information about the Noosfero-dev mailing list