ishapi 0.1.8.212 → 0.1.8.214

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: 1c3500f2e50223b7bc089de1bf280c53b6cd968102cb61ea0bcedd2bf0f648a6
4
- data.tar.gz: 75add24a2036cc8914de62d640de0138078cfb8f7915fdbc41d5b2fa446f2af5
3
+ metadata.gz: 58df7355b06e137c32c5c076108df226222315a82816ee0ffa2db20014eb93af
4
+ data.tar.gz: 5d901f1a635f0756cdc49e8113faa20c84374f5d6d2d4e545979e7f99fb53399
5
5
  SHA512:
6
- metadata.gz: b33e86d8941cedb14780cfe3ae24f15b7648f0f7a5750789e4d2dcd3fa903b553f1d49bd7cf0bf79243ebbed5f3eedfcb1dd200835a2ad1db2419409f93e42d9
7
- data.tar.gz: 3c085cd337ecd508f64e7633eb2eb878386889f90cef51415f3fef68d2c81fa910d6b4a5d5fa81b248054a66751b5a331f500bd007d9b437a45e7035139ab3e7
6
+ metadata.gz: 64f74a5d1fa78d4a6581fa023dfc8a9918423870659a2ffdbd1e8978c5346a0a2f78ac525ecd023f0bc9e6776cda06eefecaf042d6810f6c07f1dbbc786aefb1
7
+ data.tar.gz: f4201ad33e8703999bc6bf96e8b5f31cf16c6d2993065b1287d73075a5e56100f98715ef220e2dc06c0ff115414bc8e5613081b3203c0544fd0b3bb711024f3a
@@ -10,4 +10,5 @@
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require_tree .
13
+ // require_tree . // nothing
14
+ //
@@ -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,29 @@ 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
+ msg = Office::EmailMessage.find( params[:id] )
11
+ authorize! :email_messages_show, ::Ishapi
12
+ render json: {
13
+ item: msg,
14
+ }
15
+ end
16
+
17
+ ## From lambda, ses
7
18
  def receive
8
19
  if params[:secret] != AWS_SES_LAMBDA_SECRET
9
20
  render status: 400, json: { status: 400 }
10
21
  return
11
22
  end
12
23
 
13
- msg = Office::EmailMessage.new({
24
+ msg = Office::EmailMessageStub.new({
14
25
  object_path: params[:object_path],
15
- object_key: params[:object_key],
26
+ object_key: params[:object_key],
16
27
  })
17
28
  if msg.save
29
+ ::Ishapi::EmailMessageIntakeJob.perform_later( msg.id.to_s )
18
30
  render status: :ok, json: { status: :ok }
19
31
  else
20
32
  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
- # respond_with resource, location: after_sign_in_path_for(resource)
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: '314658@gmail.com'
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
@@ -0,0 +1,2 @@
1
+
2
+ FWD_Notify: No content
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.212
4
+ version: 0.1.8.214
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
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,2 +0,0 @@
1
- // Place all the behaviors and hooks related to the matching controller here.
2
- // All this logic will automatically be available in application.js.
@@ -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