ishapi 0.1.8.212 → 0.1.8.213
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/ishapi/application.js +2 -1
- data/app/controllers/ishapi/email_conversations_controller.rb +20 -0
- data/app/controllers/ishapi/email_messages_controller.rb +15 -2
- data/app/controllers/ishapi/leadsets_controller.rb +2 -0
- data/app/controllers/ishapi/users/sessions_controller.rb +1 -1
- data/app/jobs/ishapi/email_message_intake_job.rb +170 -0
- data/app/mailers/ishapi/application_mailer.rb +8 -1
- data/app/models/ishapi/ability.rb +10 -0
- data/app/views/ishapi/application_mailer/forwarder_notify.html.erb +2 -0
- data/config/routes.rb +3 -4
- metadata +5 -4
- data/app/assets/javascripts/ishapi/articles.js +0 -2
- data/app/controllers/ishapi/reports_controller.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91587210ea9c287d4684dbab6ea37348d4018fcb06bdbe3133c4ed89181cf819
|
4
|
+
data.tar.gz: '0218872a3deb68c24903cf5ee44a0cdd96f450f726f731ecfc99439f64525fe6'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e10d88fa36a03aa746bba7527acf1d2e76a905f48141020c7a93cbbfeefe945655865c04b3ebbabfe43137e3bfedf00ac7b0d85744791ea1014b9acbf1c1c432
|
7
|
+
data.tar.gz: fb168fe368ae381bf48190232f9e4a1f1b754785715b4a5f80ff16cb51553edbb2761ff59287d47744cb7860bc45c3d6a7a8c8e6d04a97d16ec0fed91d740c1a
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require_dependency "ishapi/application_controller"
|
3
|
+
|
4
|
+
# gem_dir = Gem::Specification.find_by_name("ish_models").gem_dir
|
5
|
+
# require "#{gem_dir}/lib/office/email_conversation"
|
6
|
+
|
7
|
+
module Ishapi
|
8
|
+
class EmailConversationsController < ApplicationController
|
9
|
+
|
10
|
+
before_action :check_jwt
|
11
|
+
|
12
|
+
def delete
|
13
|
+
puts! params, 'deleting email conversations'
|
14
|
+
authorize! :email_conversations_delete, ::Ishapi
|
15
|
+
convos = Office::EmailConversation.find params[:ids]
|
16
|
+
convos.map &:destroy
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -4,17 +4,30 @@ require_dependency "ishapi/application_controller"
|
|
4
4
|
module Ishapi
|
5
5
|
class EmailMessagesController < ApplicationController
|
6
6
|
|
7
|
+
before_action :check_jwt, only: [ :show ]
|
8
|
+
|
9
|
+
def show
|
10
|
+
|
11
|
+
m = Office::EmailMessage.find( params[:id] )
|
12
|
+
authorize! :email_messages_show, ::Ishapi
|
13
|
+
render json: {
|
14
|
+
item: m,
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
## From lambda, ses
|
7
19
|
def receive
|
8
20
|
if params[:secret] != AWS_SES_LAMBDA_SECRET
|
9
21
|
render status: 400, json: { status: 400 }
|
10
22
|
return
|
11
23
|
end
|
12
24
|
|
13
|
-
msg = Office::
|
25
|
+
msg = Office::EmailMessageStub.new({
|
14
26
|
object_path: params[:object_path],
|
15
|
-
object_key:
|
27
|
+
object_key: params[:object_key],
|
16
28
|
})
|
17
29
|
if msg.save
|
30
|
+
::Ishapi::EmailMessageIntakeJob.perform_later( msg.id )
|
18
31
|
render status: :ok, json: { status: :ok }
|
19
32
|
else
|
20
33
|
render status: 400, json: { status: 400 }
|
@@ -3,9 +3,11 @@ require_dependency "ishapi/application_controller"
|
|
3
3
|
module Ishapi
|
4
4
|
class LeadsetsController < ApplicationController
|
5
5
|
|
6
|
+
load_and_authorize_resource
|
6
7
|
|
7
8
|
def destroy
|
8
9
|
puts! params, 'params'
|
10
|
+
authorize! :leadsets_destroy, ::Ishapi
|
9
11
|
|
10
12
|
leadsets = Leadset.find( params[:leadset_ids] )
|
11
13
|
@results = []
|
@@ -7,7 +7,7 @@ class Ishapi::Users::SessionsController < Devise::SessionsController
|
|
7
7
|
set_flash_message!(:notice, :signed_in)
|
8
8
|
sign_in(resource_name, resource)
|
9
9
|
yield resource if block_given?
|
10
|
-
|
10
|
+
|
11
11
|
|
12
12
|
## Send the jwt to client
|
13
13
|
@current_user = resource
|
@@ -0,0 +1,170 @@
|
|
1
|
+
|
2
|
+
=begin
|
3
|
+
|
4
|
+
m_id_2 = "2021-07-12T19_17_26Fpedidos_jmc2_gmail_com"
|
5
|
+
stub = Stub.new( object_key: m_id_2 )
|
6
|
+
stub = Stub.find_by( object_key: m_id_2 )
|
7
|
+
stub.update_attribute(:state, 'state_pending')
|
8
|
+
Ishapi::EmailMessageIntakeJob.perform_now( stub.id.to_s )
|
9
|
+
|
10
|
+
|
11
|
+
=end
|
12
|
+
##
|
13
|
+
## 2023-02-26 _vp_ let's go
|
14
|
+
## 2023-03-02 _vp_ Continue
|
15
|
+
## 2023-03-07 _vp_ Continue
|
16
|
+
##
|
17
|
+
class Ishapi::EmailMessageIntakeJob < Ishapi::ApplicationJob
|
18
|
+
|
19
|
+
# include Sidekiq::Worker ## From: https://stackoverflow.com/questions/59114063/sidekiq-options-giving-sidekiqworker-cannot-be-included-in-an-activejob-for
|
20
|
+
|
21
|
+
queue_as :default
|
22
|
+
|
23
|
+
## For recursive parts of type `related`.
|
24
|
+
## Content Types:
|
25
|
+
# "text/html; charset=utf-8"
|
26
|
+
# "application/pdf; name=\"Securities Forward Agreement -- HaulHub Inc -- Victor Pudeyev -- 2021-10-26.docx.pdf\""
|
27
|
+
# "image/jpeg; name=TX_DL_2.jpg"
|
28
|
+
# "text/plain; charset=UTF-8"
|
29
|
+
def churn_subpart message, part
|
30
|
+
if part.content_type.include?("multipart/related")
|
31
|
+
|
32
|
+
part.parts.each do |subpart|
|
33
|
+
churn_subpart( message, subpart )
|
34
|
+
end
|
35
|
+
|
36
|
+
elsif part.content_type.include?('text/html')
|
37
|
+
message.part_html = part.decoded
|
38
|
+
|
39
|
+
elsif part.content_type.include?("text/plain")
|
40
|
+
message.part_txt = part.decoded
|
41
|
+
|
42
|
+
else
|
43
|
+
## @TODO: attachments !
|
44
|
+
puts! part.content_type, '444 No action for a part with this content_type'
|
45
|
+
end
|
46
|
+
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def perform id
|
51
|
+
stub = ::Office::EmailMessageStub.find id
|
52
|
+
puts "Performing EmailMessageIntakeJob for message_id #{stub.object_key}"
|
53
|
+
if stub.state != ::Office::EmailMessageStub::STATE_PENDING
|
54
|
+
raise "This stub has already been processed: #{stub.id.to_s}."
|
55
|
+
return
|
56
|
+
end
|
57
|
+
client = Aws::S3::Client.new({
|
58
|
+
region: ::S3_CREDENTIALS[:region],
|
59
|
+
access_key_id: ::S3_CREDENTIALS[:access_key_id],
|
60
|
+
secret_access_key: ::S3_CREDENTIALS[:secret_access_key] })
|
61
|
+
|
62
|
+
_mail = client.get_object( bucket: ::S3_CREDENTIALS[:bucket_ses], key: stub.object_key ).body.read
|
63
|
+
the_mail = Mail.new(_mail)
|
64
|
+
message_id = the_mail.header['message-id'].decoded ## == stub.object_key
|
65
|
+
in_reply_to_id = the_mail.header['in-reply-to']&.to_s
|
66
|
+
|
67
|
+
@message = ::Office::EmailMessage.where( message_id: message_id ).first
|
68
|
+
@message ||= ::Office::EmailMessage.new
|
69
|
+
@message.assign_attributes({
|
70
|
+
raw: _mail,
|
71
|
+
|
72
|
+
message_id: message_id,
|
73
|
+
in_reply_to_id: in_reply_to_id,
|
74
|
+
|
75
|
+
object_key: stub.object_key,
|
76
|
+
object_path: stub.object_path,
|
77
|
+
|
78
|
+
subject: the_mail.subject,
|
79
|
+
date: the_mail.date,
|
80
|
+
|
81
|
+
from: the_mail.from[0],
|
82
|
+
froms: the_mail.from,
|
83
|
+
|
84
|
+
to: the_mail.to[0],
|
85
|
+
tos: the_mail.to,
|
86
|
+
|
87
|
+
ccs: the_mail.cc,
|
88
|
+
bccs: the_mail.bcc,
|
89
|
+
})
|
90
|
+
|
91
|
+
the_mail.parts.each do |part|
|
92
|
+
churn_subpart( @message, part )
|
93
|
+
end
|
94
|
+
|
95
|
+
## Conversation
|
96
|
+
if in_reply_to_id
|
97
|
+
in_reply_to_msg = ::Office::EmailMessage.where({ message_id: in_reply_to_id }).first
|
98
|
+
if !in_reply_to_msg
|
99
|
+
conv = ::Office::EmailConversation.create!({
|
100
|
+
subject: the_mail.subject,
|
101
|
+
latest_at: the_mail.date,
|
102
|
+
})
|
103
|
+
in_reply_to_msg = ::Office::EmailMessage.create!({
|
104
|
+
message_id: in_reply_to_id,
|
105
|
+
email_conversation_id: conv.id,
|
106
|
+
})
|
107
|
+
end
|
108
|
+
conv = in_reply_to_msg.email_conversation
|
109
|
+
else
|
110
|
+
conv = ::Office::EmailConversation.create!({
|
111
|
+
subject: the_mail.subject,
|
112
|
+
latest_at: the_mail.date,
|
113
|
+
})
|
114
|
+
end
|
115
|
+
@message.email_conversation_id = conv.id
|
116
|
+
conv.update_attributes({
|
117
|
+
state: Conv::STATE_UNREAD,
|
118
|
+
latest_at: the_mail.date,
|
119
|
+
term_ids: (conv.term_ids + stub.term_ids).uniq,
|
120
|
+
})
|
121
|
+
|
122
|
+
## Leadset
|
123
|
+
domain = @message.from.split('@')[1]
|
124
|
+
leadset = Leadset.where( company_url: domain ).first
|
125
|
+
if !leadset
|
126
|
+
leadset = Leadset.create!( company_url: domain, name: domain )
|
127
|
+
end
|
128
|
+
|
129
|
+
## Lead
|
130
|
+
lead = Lead.where( email: @message.from ).first
|
131
|
+
if !lead
|
132
|
+
lead = Lead.new( email: @message.from )
|
133
|
+
lead.leadsets.push( leadset )
|
134
|
+
lead.save!
|
135
|
+
end
|
136
|
+
conv.lead_ids = conv.lead_ids.push( lead.id ).uniq
|
137
|
+
|
138
|
+
## Actions & Filters
|
139
|
+
inbox_tag = WpTag.email_inbox_tag
|
140
|
+
@message.add_tag( inbox_tag )
|
141
|
+
conv.add_tag( inbox_tag )
|
142
|
+
|
143
|
+
email_filters = Office::EmailFilter.active
|
144
|
+
email_filters.each do |filter|
|
145
|
+
if @message.from.match( filter.from_regex ) # || @message.part_html.match( filter.body_regex ) ) # || MiaTagger.analyze( @message.part_html, :is_spammy_recruite ).score > .5
|
146
|
+
|
147
|
+
@message.apply_filter( filter )
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
## Save to exit
|
152
|
+
flag = @message.save
|
153
|
+
if flag
|
154
|
+
puts! @message.message_id, 'Saved this message'
|
155
|
+
else
|
156
|
+
puts! @message.errors.full_messages.join(', '), 'Cannot save email_message'
|
157
|
+
end
|
158
|
+
conv.save
|
159
|
+
stub.update_attributes({ state: ::Office::EmailMessageStub::STATE_PROCESSED })
|
160
|
+
|
161
|
+
## Notification
|
162
|
+
if @message.wp_term_ids.include?( inbox_tag.id )
|
163
|
+
# @TODO: send android notification _vp_ 2023-03-01
|
164
|
+
::Ishapi::ApplicationMailer.forwarder_notify( @message.id.to_s ).deliver_later
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
EIJ = Ishapi::EmailMessageIntakeJob
|
@@ -1,6 +1,13 @@
|
|
1
1
|
|
2
2
|
class Ishapi::ApplicationMailer < ActionMailer::Base
|
3
|
-
default from: '
|
3
|
+
default from: 'no-reply@wasya.co'
|
4
4
|
layout 'mailer'
|
5
|
+
|
6
|
+
def forwarder_notify msg_id
|
7
|
+
@msg = ::Office::EmailMessage.find msg_id
|
8
|
+
mail( to: 'piousbox@gmail.com',
|
9
|
+
subject: "FWD_Notify: #{@msg.subject}" )
|
10
|
+
end
|
11
|
+
|
5
12
|
end
|
6
13
|
|
@@ -3,6 +3,7 @@ class Ishapi::Ability
|
|
3
3
|
include ::CanCan::Ability
|
4
4
|
|
5
5
|
def initialize user_profile
|
6
|
+
|
6
7
|
#
|
7
8
|
# signed in user_profile
|
8
9
|
#
|
@@ -28,6 +29,15 @@ class Ishapi::Ability
|
|
28
29
|
|
29
30
|
can [ :buy_stars ], ::Ish::UserProfile
|
30
31
|
|
32
|
+
#
|
33
|
+
# superuser
|
34
|
+
#
|
35
|
+
if %w| victor@wasya.co victor@piousbox.com piousbox@gmail.com |.include?( user_profile.email )
|
36
|
+
can [ :email_conversations_delete ], ::Ishapi
|
37
|
+
|
38
|
+
can [ :email_messages_show ], ::Ishapi
|
39
|
+
end
|
40
|
+
|
31
41
|
end
|
32
42
|
#
|
33
43
|
# anonymous user
|
data/config/routes.rb
CHANGED
@@ -24,7 +24,6 @@ Ishapi::Engine.routes.draw do
|
|
24
24
|
namespace :my do
|
25
25
|
get 'galleries', to: 'galleries#index'
|
26
26
|
get 'newsitems', to: 'newsitems#index'
|
27
|
-
get 'reports', to: 'reports#index'
|
28
27
|
get 'videos', to: 'videos#index'
|
29
28
|
post 'videos', to: 'videos#index'
|
30
29
|
end
|
@@ -33,6 +32,9 @@ Ishapi::Engine.routes.draw do
|
|
33
32
|
delete 'newsitems/:id', to: 'newsitems#destroy'
|
34
33
|
|
35
34
|
post 'email_messages', to: 'email_messages#receive'
|
35
|
+
get 'email_messages/:id', to: 'email_messages#show'
|
36
|
+
|
37
|
+
delete 'email_conversations', to: 'email_conversations#delete'
|
36
38
|
|
37
39
|
post 'do_purchase', to: 'gameui#do_purchase' # @TODO: rename to just purchase, or destroy endpoint
|
38
40
|
post 'payments', :to => 'payments#create'
|
@@ -44,9 +46,6 @@ Ishapi::Engine.routes.draw do
|
|
44
46
|
get 'photos/view/:id', to: 'photos#show'
|
45
47
|
get 'profiles/view/:username', :to => 'user_profiles#show'
|
46
48
|
|
47
|
-
get 'reports', :to => 'reports#index'
|
48
|
-
get 'reports/view/:slug', :to => 'reports#show'
|
49
|
-
|
50
49
|
post 'stars/buy', to: 'gameui#buy_stars'
|
51
50
|
|
52
51
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ishapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.8.
|
4
|
+
version: 0.1.8.213
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- piousbox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -204,12 +204,12 @@ files:
|
|
204
204
|
- Rakefile
|
205
205
|
- app/assets/config/ishapi_manifest.js
|
206
206
|
- app/assets/javascripts/ishapi/application.js
|
207
|
-
- app/assets/javascripts/ishapi/articles.js
|
208
207
|
- app/assets/stylesheets/ishapi/application.css
|
209
208
|
- app/assets/stylesheets/ishapi/articles.css
|
210
209
|
- app/assets/stylesheets/scaffold.css
|
211
210
|
- app/controllers/ishapi/addresses_controller.rb
|
212
211
|
- app/controllers/ishapi/application_controller.rb
|
212
|
+
- app/controllers/ishapi/email_conversations_controller.rb
|
213
213
|
- app/controllers/ishapi/email_messages_controller.rb
|
214
214
|
- app/controllers/ishapi/galleries_controller.rb
|
215
215
|
- app/controllers/ishapi/gameui_controller.rb
|
@@ -225,7 +225,6 @@ files:
|
|
225
225
|
- app/controllers/ishapi/orders_controller.rb
|
226
226
|
- app/controllers/ishapi/payments_controller.rb
|
227
227
|
- app/controllers/ishapi/photos_controller.rb
|
228
|
-
- app/controllers/ishapi/reports_controller.rb
|
229
228
|
- app/controllers/ishapi/stock_watches_controller.rb
|
230
229
|
- app/controllers/ishapi/user_profiles_controller.rb
|
231
230
|
- app/controllers/ishapi/users/registrations_controller.rb
|
@@ -234,12 +233,14 @@ files:
|
|
234
233
|
- app/controllers/ishapi/videos_controller.rb
|
235
234
|
- app/helpers/ishapi/application_helper.rb
|
236
235
|
- app/jobs/ishapi/application_job.rb
|
236
|
+
- app/jobs/ishapi/email_message_intake_job.rb
|
237
237
|
- app/mailers/ishapi/application_mailer.rb
|
238
238
|
- app/mailers/ishapi/confirmations_mailer.rb
|
239
239
|
- app/models/ishapi/ability.rb
|
240
240
|
- app/views/ishapi/addresses/_show.jbuilder
|
241
241
|
- app/views/ishapi/application/_meta.jbuilder
|
242
242
|
- app/views/ishapi/application/_pagination.jbuilder
|
243
|
+
- app/views/ishapi/application_mailer/forwarder_notify.html.erb
|
243
244
|
- app/views/ishapi/galleries/_index.jbuilder
|
244
245
|
- app/views/ishapi/galleries/_show.jbuilder
|
245
246
|
- app/views/ishapi/galleries/index.jbuilder
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require_dependency "ishapi/application_controller"
|
2
|
-
module Ishapi
|
3
|
-
class ReportsController < ApplicationController
|
4
|
-
|
5
|
-
def show
|
6
|
-
@report = Report.unscoped.find_by :slug => params[:slug]
|
7
|
-
authorize! :show, @report
|
8
|
-
end
|
9
|
-
|
10
|
-
def index
|
11
|
-
authorize! :index, Report
|
12
|
-
@reports = Report.all
|
13
|
-
if params[:cityname]
|
14
|
-
city = City.find_by :cityname => params[:cityname]
|
15
|
-
@reports = @reports.where( :city_id => city.id )
|
16
|
-
end
|
17
|
-
if params[:domain]
|
18
|
-
site = Site.find_by :domain => params[:domain], :lang => :en
|
19
|
-
@reports = @reports.where( :site_id => site.id )
|
20
|
-
end
|
21
|
-
|
22
|
-
if params[:tag]
|
23
|
-
tag = Tag.find_by(:name => params[:tag])
|
24
|
-
@reports = @reports.where(:tag_ids => tag)
|
25
|
-
end
|
26
|
-
|
27
|
-
@reports = @reports.page( params[:reports_page] ).per( 10 )
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|