wco_models 3.1.0.304 → 3.1.0.306
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 +4 -4
- data/app/controllers/wco/api/leads_controller.rb +1 -1
- data/app/models/wco/lead.rb +5 -15
- data/app/models/wco/photo.rb +1 -0
- data/app/models/wco_email/context.rb +1 -1
- data/app/models/wco_email/email_filter_condition.rb +34 -19
- data/app/models/wco_email/message.rb +2 -1
- data/app/models/wco_email/message_stub.rb +6 -12
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a8f5b0a2dee427291f2f6e91778c749bad1d27000cfaec5248c0d753575ab897
|
|
4
|
+
data.tar.gz: 115c8df45585c59d17889e95fbb4122c8fa9da60f58c0cbb32a6b021fb62c5a8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ab1f1a65f9e3109e5ad25ad1a930dcda540421e8bb90870ee1d35d9c564364f5915f1cfc091a69255bb3e6e511052b9ddb794e62071b2bb62af661add155e230
|
|
7
|
+
data.tar.gz: '0589b0ea20dc4c9a912e02f88576c19ccda762ccc3e0a96c5888491c4a70a2f5acd9f77cb62377da32767ef22521a18186e647212e9d952c34fe61cb33ca654e'
|
|
@@ -5,7 +5,7 @@ class Wco::Api::LeadsController < Wco::ApiController
|
|
|
5
5
|
before_action :check_credentials, only: [ :by_email ]
|
|
6
6
|
|
|
7
7
|
def by_email
|
|
8
|
-
@lead = Wco::Lead.
|
|
8
|
+
@lead = Wco::Lead.find_or_create_by_email( params[:email] )
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
## select2-leads-ajax
|
data/app/models/wco/lead.rb
CHANGED
|
@@ -32,12 +32,7 @@ class Wco::Lead
|
|
|
32
32
|
belongs_to :leadset, class_name: 'Wco::Leadset'
|
|
33
33
|
before_validation :normalize_email, on: :create
|
|
34
34
|
def normalize_email
|
|
35
|
-
self[:email] = email
|
|
36
|
-
if email.index('+')
|
|
37
|
-
a = email
|
|
38
|
-
a.slice!( a[a.index('+')...a.index('@')] )
|
|
39
|
-
self[:email] = a
|
|
40
|
-
end
|
|
35
|
+
self[:email] = Wco::Lead.normalize_email email
|
|
41
36
|
end
|
|
42
37
|
def self.normalize_email a
|
|
43
38
|
a = a.downcase
|
|
@@ -49,19 +44,14 @@ class Wco::Lead
|
|
|
49
44
|
before_validation :set_leadset, on: :create
|
|
50
45
|
def set_leadset
|
|
51
46
|
domain = email.split('@')[1]
|
|
52
|
-
|
|
47
|
+
root_domain = PublicSuffix.domain(domain)
|
|
48
|
+
self.leadset ||= Wco::Leadset.find_or_create_by({ company_url: root_domain })
|
|
53
49
|
end
|
|
54
50
|
|
|
55
51
|
def self.find_or_create_by_email email
|
|
56
52
|
email = self.normalize_email email
|
|
57
|
-
out
|
|
58
|
-
|
|
59
|
-
domain = email.split('@')[1]
|
|
60
|
-
leadset = Wco::Leadset.where( company_url: domain ).first
|
|
61
|
-
leadset ||= Wco::Leadset.create( company_url: domain, email: email )
|
|
62
|
-
out = create!( email: email, leadset: leadset )
|
|
63
|
-
end
|
|
64
|
-
return out
|
|
53
|
+
out = where( email: email ).first
|
|
54
|
+
out ||= create!( email: email )
|
|
65
55
|
end
|
|
66
56
|
|
|
67
57
|
|
data/app/models/wco/photo.rb
CHANGED
|
@@ -11,17 +11,17 @@ class WcoEmail::EmailFilterCondition
|
|
|
11
11
|
FIELD_BODY_PLAIN = 'body-plain'
|
|
12
12
|
FIELD_FROM = 'from'
|
|
13
13
|
FIELD_LEADSET = 'from-leadset'
|
|
14
|
-
FIELD_NOT_TAGGED = 'leadset-not-tagged'
|
|
15
14
|
FIELD_SUBJECT = 'subject'
|
|
16
|
-
FIELD_TAGGED = 'leadset-tagged'
|
|
15
|
+
FIELD_TAGGED = 'leadset-tagged' ## either lead or leadset, actually
|
|
16
|
+
FIELD_NOT_TAGGED = 'leadset-not-tagged' ## either lead or leadset, actually
|
|
17
17
|
FIELD_TO_OR_CC = 'to-or-cc'
|
|
18
18
|
FIELD_OPTS = [
|
|
19
19
|
FIELD_BODY, FIELD_BODY_PLAIN,
|
|
20
20
|
FIELD_FROM,
|
|
21
21
|
FIELD_LEADSET,
|
|
22
|
-
FIELD_NOT_TAGGED,
|
|
23
22
|
FIELD_SUBJECT,
|
|
24
23
|
FIELD_TAGGED,
|
|
24
|
+
FIELD_NOT_TAGGED,
|
|
25
25
|
FIELD_TO_OR_CC,
|
|
26
26
|
];
|
|
27
27
|
field :field
|
|
@@ -49,10 +49,11 @@ class WcoEmail::EmailFilterCondition
|
|
|
49
49
|
|
|
50
50
|
index({ email_filter_id: 1, field: 1, operator: 1, value: 1 }, unique: true )
|
|
51
51
|
|
|
52
|
-
def apply
|
|
52
|
+
def apply lead:, message:
|
|
53
53
|
cond = self
|
|
54
54
|
reason = nil
|
|
55
55
|
case cond.field
|
|
56
|
+
|
|
56
57
|
## from match-i <value>
|
|
57
58
|
when WcoEmail::EmailFilterCondition::FIELD_FROM
|
|
58
59
|
if cond.operator == WcoEmail::EmailFilterCondition::OPERATOR_MATCH
|
|
@@ -60,21 +61,35 @@ class WcoEmail::EmailFilterCondition
|
|
|
60
61
|
reason = "#{email_skip_filter ? 'skip_' : ''}condition from match-i `#{value}`"
|
|
61
62
|
end
|
|
62
63
|
end
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
64
|
+
|
|
65
|
+
when WcoEmail::EmailFilterCondition::FIELD_TAGGED
|
|
66
|
+
## cond.operator should eql OPERATOR__ID but I don't check b/c if its slug, it should work also.
|
|
67
|
+
tag = Wco::Tag.find( cond.value ) rescue nil
|
|
68
|
+
tag ||= Wco::Tag.where( slug: cond.value ).first
|
|
69
|
+
if tag
|
|
70
|
+
if lead.leadset.tags.include?( tag ) ||
|
|
71
|
+
lead.tags.include?( tag )
|
|
72
|
+
|
|
73
|
+
reason = "#{email_skip_filter ? 'skip_' : ''}condition TAGGED `#{tag.slug}`"
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
when WcoEmail::EmailFilterCondition::FIELD_NOT_TAGGED
|
|
79
|
+
## cond.operator should eql OPERATOR__ID but I don't check b/c if its slug, it should work also.
|
|
80
|
+
tag = Wco::Tag.find( cond.value ) rescue nil
|
|
81
|
+
tag ||= Wco::Tag.where( slug: cond.value ).first
|
|
82
|
+
if tag
|
|
83
|
+
if !lead.leadset.tags.include?( tag ) &&
|
|
84
|
+
!lead.tags.include?( tag )
|
|
85
|
+
|
|
86
|
+
reason = "#{email_skip_filter ? 'skip_' : ''}condition NOT_TAGGED `#{tag.slug}`"
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end ## end case
|
|
92
|
+
|
|
78
93
|
return reason
|
|
79
94
|
end
|
|
80
95
|
|
|
@@ -72,14 +72,12 @@ class WcoEmail::MessageStub
|
|
|
72
72
|
})
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
##
|
|
76
|
-
# from = json['mail_from'] || "nobody@unknown-doma.in"
|
|
75
|
+
## Lead, Leadset
|
|
77
76
|
from = json['from'][/<([^>]+)>/, 1].downcase rescue json['mail_from']
|
|
78
77
|
mail_from = json['mail_from']
|
|
79
78
|
@lead = Wco::Lead.find_or_create_by_email( from )
|
|
80
79
|
@conv.leads.push @lead
|
|
81
|
-
@
|
|
82
|
-
@conv.leadsets.push @leadset
|
|
80
|
+
@conv.leadsets.push @lead.leadset
|
|
83
81
|
|
|
84
82
|
## message
|
|
85
83
|
old_message = WcoEmail::Message.unscoped.where( message_id: message_id ).first
|
|
@@ -111,11 +109,6 @@ class WcoEmail::MessageStub
|
|
|
111
109
|
@message.save_attachment_postal( att )
|
|
112
110
|
end
|
|
113
111
|
|
|
114
|
-
## _TODO
|
|
115
|
-
# the_mail.cc&.each do |cc|
|
|
116
|
-
# Wco::Lead.find_or_create_by_email( cc )
|
|
117
|
-
# end
|
|
118
|
-
|
|
119
112
|
@conv.update_attributes({
|
|
120
113
|
status: WcoEmail::Conversation::STATUS_UNREAD,
|
|
121
114
|
latest_at: json['date'].to_time.to_s || Time.now.to_datetime,
|
|
@@ -135,7 +128,7 @@ class WcoEmail::MessageStub
|
|
|
135
128
|
reason = nil
|
|
136
129
|
|
|
137
130
|
filter.conditions.each do |cond|
|
|
138
|
-
reason ||= cond.apply(
|
|
131
|
+
reason ||= cond.apply(lead: @lead, message: @message )
|
|
139
132
|
end
|
|
140
133
|
|
|
141
134
|
if reason
|
|
@@ -145,13 +138,14 @@ class WcoEmail::MessageStub
|
|
|
145
138
|
skip_reason = nil
|
|
146
139
|
|
|
147
140
|
filter.skip_conditions.each do |scond|
|
|
148
|
-
skip_reason ||= scond.apply(
|
|
141
|
+
skip_reason ||= scond.apply(lead: @lead, message: @message )
|
|
149
142
|
end
|
|
150
143
|
|
|
151
144
|
if skip_reason
|
|
152
145
|
puts! "NOT Applying2 filter #{filter} to conv #{@message.conversation} for matching #{skip_reason}" if DEBUG
|
|
153
146
|
else
|
|
154
|
-
@conv.filters << filter
|
|
147
|
+
@conv.filters << filter
|
|
148
|
+
@conv.save
|
|
155
149
|
filter.actions.each do |action|
|
|
156
150
|
@message.apply_filter_action( action )
|
|
157
151
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wco_models
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.1.0.
|
|
4
|
+
version: 3.1.0.306
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Victor Pudeyev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-08-
|
|
11
|
+
date: 2026-08-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: aws-sdk-s3
|
|
@@ -290,6 +290,20 @@ dependencies:
|
|
|
290
290
|
- - ">="
|
|
291
291
|
- !ruby/object:Gem::Version
|
|
292
292
|
version: '0'
|
|
293
|
+
- !ruby/object:Gem::Dependency
|
|
294
|
+
name: public_suffix
|
|
295
|
+
requirement: !ruby/object:Gem::Requirement
|
|
296
|
+
requirements:
|
|
297
|
+
- - ">="
|
|
298
|
+
- !ruby/object:Gem::Version
|
|
299
|
+
version: '0'
|
|
300
|
+
type: :runtime
|
|
301
|
+
prerelease: false
|
|
302
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
303
|
+
requirements:
|
|
304
|
+
- - ">="
|
|
305
|
+
- !ruby/object:Gem::Version
|
|
306
|
+
version: '0'
|
|
293
307
|
- !ruby/object:Gem::Dependency
|
|
294
308
|
name: rails
|
|
295
309
|
requirement: !ruby/object:Gem::Requirement
|