dorsale 3.9.1 → 3.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76ebbb416c39796db8712d68bb5952b6a9805904
4
- data.tar.gz: e2a2fa91cab07ed102a24bdb0fc9240e1a940a92
3
+ metadata.gz: 5358e48332086ea75f9a49b3578793b5d16967a4
4
+ data.tar.gz: 12a4d387aa03f2b70f1461b9961b1e8cc034800a
5
5
  SHA512:
6
- metadata.gz: bd88080f00eaa88ee7e464d60e6377359e88af977807e9f616679d620ec38b35ae0c7b4034dc64cafb93d8fe726e611c737bff2c085de7363e4774542a278c9b
7
- data.tar.gz: 416f512d565db0c0d0a7878006b822fee869acc2ea4b7aa9df05a377102eb86e4a6ccd1d3b2cb52d3b76adad3114a696753598442a6ec6ade2b733e247e05cf1
6
+ metadata.gz: eb146a34700533fc56964b13a83249d901233c4c3d746ca51454796e3c70bcd1c0013b513805ef47e622dc8732b001f5e2935fbfdadef1ed24d16dbb695bd34a
7
+ data.tar.gz: e8a441114f93b6074e80d298b29c1a362686e5c5fc07a78af43e05bc77f09abf83f7893e0c561c475fec365367b604909787d96273ce32faf51e4e9e5fb084eb
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Next version
4
4
 
5
+ ## 3.9.2
6
+
7
+ - CustomerVault : Add secondary emails + uniqueness validation
8
+
5
9
  ## 3.9.1
6
10
 
7
11
  - Add tags to tasks
@@ -137,6 +137,7 @@ class Dorsale::CustomerVault::PeopleController < ::Dorsale::CustomerVault::Appli
137
137
  :short_name,
138
138
  :avatar,
139
139
  :email,
140
+ :secondary_emails_str,
140
141
  :phone,
141
142
  :mobile,
142
143
  :fax,
@@ -46,9 +46,47 @@ class Dorsale::CustomerVault::Person < ::Dorsale::ApplicationRecord
46
46
  )
47
47
  }
48
48
 
49
+ scope :having_email, -> (email) { where("email = :e OR :e = ANY (secondary_emails)", e: email) }
50
+
49
51
  after_initialize :build_address, if: proc { new_record? && address.nil? }
50
52
  before_validation :build_address, if: proc { address.nil? }
51
53
 
54
+ def taken_emails
55
+ taken_emails = {}
56
+ ([email] + secondary_emails).select(&:present?).each do |e|
57
+ person = Dorsale::CustomerVault::Person.where.not(id: id).having_email(e).first
58
+ taken_emails[e] = person if person.present?
59
+ end
60
+ taken_emails
61
+ end
62
+
63
+ validate :validate_taken_emails
64
+
65
+ def validate_taken_emails
66
+ return if taken_emails.empty?
67
+
68
+ if taken_emails.keys.include?(email)
69
+ errors.add(:email, :taken)
70
+ end
71
+
72
+ if (taken_emails.keys & secondary_emails).any?
73
+ errors.add(:secondary_emails, :taken)
74
+ errors.add(:secondary_emails_str, :taken)
75
+ end
76
+ end
77
+
78
+ def email=(incoming_email)
79
+ super(incoming_email.to_s.strip.presence)
80
+ end
81
+
82
+ def secondary_emails_str
83
+ secondary_emails.join("\n")
84
+ end
85
+
86
+ def secondary_emails_str=(emails)
87
+ self.secondary_emails = emails.strip.split
88
+ end
89
+
52
90
  def person_type
53
91
  self.class.to_s.demodulize.downcase.to_sym
54
92
  end
@@ -8,6 +8,7 @@
8
8
  = info person, :title
9
9
 
10
10
  = info person, :email, helper: :email_link
11
+ = info person, :secondary_emails, person.secondary_emails.map { |e| email_link(e) }.join(tag(:br)).html_safe
11
12
  = info person, :phone, helper: :tel_link
12
13
  = info person, :mobile, helper: :tel_link
13
14
  = info person, :fax, helper: :tel_link
@@ -0,0 +1,5 @@
1
+ .row
2
+ .col-md-3
3
+ .col-md-9: ul
4
+ - person.taken_emails.each do |email, person|
5
+ li = t("messages.email_taken_by", email: email, person: link_to_object(person, target: "_blank")).html_safe
@@ -36,6 +36,9 @@
36
36
  .panel-heading: .panel-title = t("customer_vault.contact_informations")
37
37
  .panel-body
38
38
  = f.input :email
39
+ = f.input :secondary_emails_str, as: :text, input_html: {rows: 2}
40
+ - if @person.errors.key?(:email) || @person.errors.key?(:secondary_emails)
41
+ = render "emails_errors", person: @person
39
42
  = f.input :phone
40
43
  = f.input :mobile
41
44
  = f.input :fax
@@ -17,6 +17,7 @@ en:
17
17
  messages:
18
18
  no_people: "No people find."
19
19
  no_activity: "No recent activity."
20
+ email_taken_by: "%{email} is taken by %{person}"
20
21
 
21
22
  corporations:
22
23
  create_ok : "Corporation created."
@@ -98,6 +99,8 @@ en:
98
99
  individuals: "Individuals"
99
100
  origin: "Origin"
100
101
  activity_type: "Activity type"
102
+ secondary_emails: "Secondary e-mails"
103
+ secondary_emails_str: "Secondary e-mails"
101
104
 
102
105
  dorsale/customer_vault/individual:
103
106
  <<: *customer_vault_person_attributes
@@ -17,6 +17,7 @@ fr:
17
17
  messages:
18
18
  no_people: "Aucune personne trouvée."
19
19
  no_activity: "Aucune activité récente."
20
+ email_taken_by: "%{email} est déjà pris par %{person}"
20
21
 
21
22
  corporations:
22
23
  create_ok : "La personne a été créée."
@@ -97,6 +98,8 @@ fr:
97
98
  individuals: "Individus"
98
99
  origin: "Origine"
99
100
  activity_type: "Type d'activité"
101
+ secondary_emails: "E-mails secondaires"
102
+ secondary_emails_str: "E-mails secondaires"
100
103
 
101
104
  dorsale/customer_vault/individual:
102
105
  <<: *customer_vault_person_attributes
@@ -0,0 +1,9 @@
1
+ class DorsaleCustomerVaultPeopleAddSecondaryEmails < ActiveRecord::Migration[5.0]
2
+ def change
3
+ change_table :dorsale_customer_vault_people do |t|
4
+ t.string :secondary_emails, array: true, default: [], null: false
5
+ end
6
+
7
+ add_index :dorsale_customer_vault_people, :secondary_emails, using: "gin"
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Dorsale
2
- VERSION = "3.9.1"
2
+ VERSION = "3.9.2"
3
3
  end
@@ -62,4 +62,51 @@ RSpec.describe ::Dorsale::CustomerVault::Person, type: :model do
62
62
  expect(corporation.address).to be_present
63
63
  end
64
64
  end # describe "address"
65
+
66
+ describe "emails" do
67
+ it "should strip email" do
68
+ individual = create(:customer_vault_individual, email: " myemail@example.org ")
69
+ expect(individual.email).to eq "myemail@example.org"
70
+ end
71
+
72
+ it "should create an array of strings without blank characters" do
73
+ test_individual = create(:customer_vault_individual, email: "primary@example.org")
74
+ test_individual.secondary_emails_str = " first@example.org \n second@example.org "
75
+ expect(test_individual.secondary_emails).to eq ["first@example.org", "second@example.org"]
76
+ end
77
+
78
+ it "should return one object in the scope" do
79
+ individual = create(:customer_vault_individual,
80
+ :email => "primary@example.org",
81
+ :secondary_emails => ["first@example.org"],
82
+ )
83
+
84
+ individual2 = Dorsale::CustomerVault::Person.having_email("primary@example.org")
85
+ expect(individual2).to eq [individual]
86
+
87
+ individual3 = Dorsale::CustomerVault::Person.having_email("first@example.org")
88
+ expect(individual3).to eq [individual]
89
+ end
90
+
91
+ it "should check whether a new email address already is in the database" do
92
+ individual = create(:customer_vault_individual,
93
+ :email => "primary@example.org",
94
+ :secondary_emails => ["first@example.org", "second@example.org"],
95
+ )
96
+
97
+ individual2 = create(:customer_vault_individual)
98
+ individual2.email = "primary@example.org"
99
+ expect(individual2).to be_invalid
100
+ expect(individual2.errors).to have_key :email
101
+ expect(individual2.errors).to_not have_key :secondary_emails
102
+ expect(individual2.errors).to_not have_key :secondary_emails_str
103
+
104
+ individual3 = create(:customer_vault_individual)
105
+ individual3.secondary_emails << "first@example.org"
106
+ expect(individual3).to be_invalid
107
+ expect(individual3.errors).to have_key :secondary_emails
108
+ expect(individual3.errors).to have_key :secondary_emails_str
109
+ expect(individual3.errors).to_not have_key :email
110
+ end
111
+ end # describe "emails"
65
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorsale
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.9.1
4
+ version: 3.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - agilidée
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-20 00:00:00.000000000 Z
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -734,6 +734,7 @@ files:
734
734
  - app/views/dorsale/customer_vault/people/_context_related_people.slim
735
735
  - app/views/dorsale/customer_vault/people/_context_social.html.slim
736
736
  - app/views/dorsale/customer_vault/people/_data_context.html.slim
737
+ - app/views/dorsale/customer_vault/people/_emails_errors.html.slim
737
738
  - app/views/dorsale/customer_vault/people/_filters.html.slim
738
739
  - app/views/dorsale/customer_vault/people/_form.html.slim
739
740
  - app/views/dorsale/customer_vault/people/_index_actions.html.slim
@@ -858,6 +859,7 @@ files:
858
859
  - db/migrate/20171023080507_migrate_people_comments_to_events.rb
859
860
  - db/migrate/20171023133219_customer_vault_events_add_contact_type.rb
860
861
  - db/migrate/20171024075514_customer_vault_contact_type_default_value.rb
862
+ - db/migrate/20171115171425_dorsale_customer_vault_people_add_secondary_emails.rb
861
863
  - features/access.feature
862
864
  - features/billing_machine_invoices.feature
863
865
  - features/billing_machine_multiple_vat.feature