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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87541daeb7455882c94e744cf11f35ac8a491c2a7367e59bb666cb8230473613
4
- data.tar.gz: 1a421dd9461abd591b248c6b9d1eeaadb6f05e3146a9e8420f35c35504d278c4
3
+ metadata.gz: a8f5b0a2dee427291f2f6e91778c749bad1d27000cfaec5248c0d753575ab897
4
+ data.tar.gz: 115c8df45585c59d17889e95fbb4122c8fa9da60f58c0cbb32a6b021fb62c5a8
5
5
  SHA512:
6
- metadata.gz: 03f99e4c551e579c2cdc8ec4436ffb0ec66b4af7c812424bc7ed027d950b40b7fde8efbdf174bd64b9f7084bf4cefb8b97266da6bdb535ae3ef26972cdf9496f
7
- data.tar.gz: df84c4aaa5f7f63c6fa5fa589cb7a4e596e70cceb661881c1900517e3ef6ca276524ea56c8d6f0f4cfe4d598534e57800ad800660b280330c0673272d495ae38
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.where( email: params[:email] ).first
8
+ @lead = Wco::Lead.find_or_create_by_email( params[:email] )
9
9
  end
10
10
 
11
11
  ## select2-leads-ajax
@@ -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.downcase
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
- self.leadset ||= Wco::Leadset.find_or_create_by({ company_url: domain })
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 = where( email: email ).first
58
- if !out
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
 
@@ -6,6 +6,7 @@ class Wco::Photo
6
6
  include Mongoid::Document
7
7
  include Mongoid::Timestamps
8
8
  include Mongoid::Paperclip
9
+ include Mongoid::Paranoia
9
10
  include Wco::Utils
10
11
  store_in collection: 'photos'
11
12
 
@@ -51,7 +51,7 @@ class WcoEmail::Context
51
51
  elsif tmpl&.from_email
52
52
  return tmpl.from_email
53
53
  else
54
- return DEFAULT_FROM_EMAIL
54
+ return 'no-reply@wasya.co' ## DEFAULT_FROM_EMAIL
55
55
  end
56
56
  end
57
57
  index({ from_email: -1 })
@@ -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 leadset:, message:
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
- end
64
- # when WcoEmail::FIELD_LEADSET
65
- # if cond.operator == WcoEmail::OPERATOR_NOT_HAS_TAG
66
- # this_tag = Wco::Tag.find cond.value
67
- # if leadset.tags.include?( this_tag )
68
- # ;
69
- # else
70
- # reason = "#{email_skip_filter ? 'skip_' : ''}condition leadset not-has-tag #{this_tag} NOT met"
71
- # end
72
- # end
73
- # when WcoEmail::FIELD_TO
74
- # if message.to == cond.value
75
- # reason = "{email_skip_filter ? 'skip_' : ''}condition to = #{cond.value}"
76
- # end
77
- # end
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
 
@@ -88,7 +88,8 @@ class WcoEmail::Message
88
88
 
89
89
  def apply_filter_action action
90
90
  message = self
91
- aject = action.aject
91
+ aject = action.aject
92
+
92
93
  case action.kind
93
94
  when WcoEmail::EmailFilterAction::KIND_ADD_TAG
94
95
  conv.tags.push aject
@@ -72,14 +72,12 @@ class WcoEmail::MessageStub
72
72
  })
73
73
  end
74
74
 
75
- ## Leadset, Lead
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
- @leadset = Wco::Leadset.from_email from
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(leadset: @leadset, message: @message )
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(leadset: @leadset, message: @message )
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; @conv.save
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.304
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-05 00:00:00.000000000 Z
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