dorsale 3.9.1 → 3.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/app/controllers/dorsale/customer_vault/people_controller.rb +1 -0
- data/app/models/dorsale/customer_vault/person.rb +38 -0
- data/app/views/dorsale/customer_vault/people/_context_general.html.slim +1 -0
- data/app/views/dorsale/customer_vault/people/_emails_errors.html.slim +5 -0
- data/app/views/dorsale/customer_vault/people/_form.html.slim +3 -0
- data/config/locales/customer_vault.en.yml +3 -0
- data/config/locales/customer_vault.fr.yml +3 -0
- data/db/migrate/20171115171425_dorsale_customer_vault_people_add_secondary_emails.rb +9 -0
- data/lib/dorsale/version.rb +1 -1
- data/spec/models/dorsale/customer_vault/person_spec.rb +47 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5358e48332086ea75f9a49b3578793b5d16967a4
|
4
|
+
data.tar.gz: 12a4d387aa03f2b70f1461b9961b1e8cc034800a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb146a34700533fc56964b13a83249d901233c4c3d746ca51454796e3c70bcd1c0013b513805ef47e622dc8732b001f5e2935fbfdadef1ed24d16dbb695bd34a
|
7
|
+
data.tar.gz: e8a441114f93b6074e80d298b29c1a362686e5c5fc07a78af43e05bc77f09abf83f7893e0c561c475fec365367b604909787d96273ce32faf51e4e9e5fb084eb
|
data/CHANGELOG.md
CHANGED
@@ -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
|
@@ -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
|
data/lib/dorsale/version.rb
CHANGED
@@ -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.
|
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-
|
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
|