wordjelly-auth 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/auth/concerns/shopping/personality_controller_concern.rb +1 -1
- data/app/controllers/auth/concerns/shopping/place_controller_concern.rb +1 -2
- data/app/controllers/auth/concerns/work/communication_controller_concern.rb +68 -26
- data/app/controllers/auth/concerns/work/instruction_controller_concern.rb +5 -2
- data/app/controllers/auth/work/communications_controller.rb +0 -2
- data/app/jobs/communication_job.rb +19 -0
- data/app/mailers/auth/send_mail.rb +1 -4
- data/app/models/auth/concerns/shopping/cart_item_concern.rb +34 -12
- data/app/models/auth/concerns/shopping/place_concern.rb +2 -1
- data/app/models/auth/concerns/shopping/product_concern.rb +2 -1
- data/app/models/auth/concerns/work/communication_fields_concern.rb +82 -0
- data/app/models/auth/concerns/work/good_concern.rb +0 -1
- data/app/models/auth/shopping/cart_item.rb +0 -3
- data/app/models/auth/work/communication.rb +292 -18
- data/app/models/auth/work/cycle.rb +2 -1
- data/app/models/auth/work/instruction.rb +24 -2
- data/app/views/auth/shopping/places/_search.html.erb +2 -2
- data/app/views/auth/work/communications/_form.html.erb +29 -5
- data/app/views/auth/work/communications/_show.html.erb +12 -0
- data/app/views/auth/work/communications/edit.html.erb +1 -0
- data/app/views/auth/work/communications/new.html.erb +1 -0
- data/app/views/auth/work/communications/show.html.erb +1 -0
- data/app/views/auth/work/instructions/_show.html.erb +19 -6
- data/lib/auth/engine.rb +20 -0
- data/lib/auth/rails/routes.rb +1 -1
- data/lib/auth/two_factor_otp.rb +2 -0
- data/lib/auth/version.rb +1 -1
- data/spec/dummy/app/assets/time_hashes.json +1 -1
- data/spec/dummy/app/controllers/shopping/personalities_controller.rb +2 -0
- data/spec/dummy/app/controllers/shopping/places_controller.rb +2 -0
- data/spec/dummy/app/models/noti.rb +1 -0
- data/spec/dummy/app/models/shopping/personality.rb +2 -0
- data/spec/dummy/app/models/shopping/place.rb +2 -0
- data/spec/dummy/config/environments/test.rb +1 -0
- data/spec/models/auth/shopping/cart_item_spec.rb +105 -0
- data/spec/models/auth/shopping/product.json +17 -0
- data/spec/support/work_support.rb +0 -1
- metadata +20 -5
- data/app/jobs/notification_job.rb +0 -17
- data/app/models/auth/concerns/work/inform_concern.rb +0 -31
- data/app/models/auth/work/VICTORY SPEECH: +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df0e9694a8b5ecf0415a1bd0987b1d064ac45421
|
4
|
+
data.tar.gz: 70c80d7e46de4f06d1f0220a81526f4b094fb20a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea1ac1f358a6e54a19f3f3aa74903a66e19d1c9fe9780e9bffb8ccfac5fe935f30c82cfee624ff7f95085de62137b18a1486b57b0befb7b1cf27cb5ee6a93af
|
7
|
+
data.tar.gz: f5d48381525347e16f82c3e9ae7689b04d4ed448aa371d9bb922d7f67758e9a4998f9f30c3e2b7493bb2d54cf7090a0311aabd0421b81ade6fd3b497f5fadb2d
|
@@ -69,7 +69,7 @@ module Auth::Concerns::Shopping::PersonalityControllerConcern
|
|
69
69
|
respond_to do |format|
|
70
70
|
## with js.
|
71
71
|
format.js do
|
72
|
-
render :partial => "
|
72
|
+
render :partial => "search", locals: {search_results: @search_results, suggestions: []}
|
73
73
|
end
|
74
74
|
format.json do
|
75
75
|
render json: @search_results.to_json
|
@@ -74,9 +74,8 @@ module Auth::Concerns::Shopping::PlaceControllerConcern
|
|
74
74
|
query_clause = Auth::Search::Main.es_six_finalize_search_query_clause(args)
|
75
75
|
@search_results = Auth.configuration.place_class.constantize.es.search(query_clause,{:wrapper => :load}).results
|
76
76
|
respond_to do |format|
|
77
|
-
## with js.
|
78
77
|
format.js do
|
79
|
-
render :partial => "
|
78
|
+
render :partial => "search", locals: {search_results: @search_results, suggestions: []}
|
80
79
|
end
|
81
80
|
format.json do
|
82
81
|
render json: @search_results.to_json
|
@@ -2,29 +2,42 @@ module Auth::Concerns::Work::CommunicationControllerConcern
|
|
2
2
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
def set_instruction
|
6
|
+
if product_id = @auth_work_communication_params[:product_id]
|
7
|
+
if instruction_id = @auth_work_communication_params[:instruction_id]
|
8
|
+
if @auth_shopping_product = Auth.configuration.product_class.constantize.find(product_id)
|
9
|
+
@auth_work_instruction = nil
|
10
|
+
@instruction_index = 0
|
11
|
+
@auth_shopping_product.instructions.each do |inst|
|
12
|
+
if inst.id.to_s == instruction_id
|
13
|
+
@auth_work_instruction = inst
|
14
|
+
break
|
15
|
+
end
|
16
|
+
@instruction_index+=1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
elsif cart_item_id = @auth_work_communication_params[:cart_item_id]
|
21
|
+
if instruction_id = @auth_work_communication_params[:instruction_id]
|
22
|
+
if @auth_shopping_cart_item = Auth.configuration.cart_item_class.constantize.find(cart_item_id)
|
23
|
+
@auth_work_instruction = nil
|
24
|
+
@instruction_index = 0
|
25
|
+
@auth_shopping_cart_item.instructions.each do |inst|
|
26
|
+
if inst.id.to_s == instruction_id
|
27
|
+
@auth_work_instruction = inst
|
28
|
+
break
|
29
|
+
end
|
30
|
+
@instruction_index+=1
|
31
|
+
end
|
32
|
+
end
|
19
33
|
end
|
20
|
-
rescue Mongoid::Errors::DocumentNotFound
|
21
|
-
parent_object = parent_object_class.constantize.new
|
22
|
-
@auth_work_communication = Auth::Work::Communication.new(@auth_work_communication_params)
|
23
34
|
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_cycle
|
24
38
|
|
25
|
-
|
39
|
+
end
|
26
40
|
|
27
|
-
end
|
28
41
|
|
29
42
|
def initialize_vars
|
30
43
|
|
@@ -37,22 +50,51 @@ module Auth::Concerns::Work::CommunicationControllerConcern
|
|
37
50
|
@auth_work_instruction = nil
|
38
51
|
|
39
52
|
if @auth_work_communication_params[:cycle_id]
|
40
|
-
|
53
|
+
set_cycle
|
41
54
|
elsif @auth_work_communication_params[:instruction_id]
|
42
|
-
|
55
|
+
set_instruction
|
43
56
|
else
|
44
57
|
not_found("please provide a cycle id or an instruction id")
|
45
58
|
end
|
46
59
|
|
60
|
+
not_found("instruction not found") unless @auth_work_instruction
|
61
|
+
|
62
|
+
## if the communication id is found, otherwise instantiate a new communication from the params.
|
63
|
+
if params[:id]
|
64
|
+
begin
|
65
|
+
@auth_work_communication = @auth_work_communication_class.find(params[:id])
|
66
|
+
rescue Mongoid::Errors::DocumentNotFound
|
67
|
+
@auth_work_communication = @auth_work_communication_class.new(@auth_work_communication_params)
|
68
|
+
end
|
69
|
+
else
|
70
|
+
@auth_work_communication = @auth_work_communication_class.new(@auth_work_communication_params)
|
71
|
+
end
|
72
|
+
|
73
|
+
|
47
74
|
end
|
48
75
|
|
49
76
|
def create
|
50
|
-
|
77
|
+
if @auth_shopping_product
|
78
|
+
@auth_work_instruction.communications << @auth_work_communication
|
79
|
+
@auth_shopping_product.instructions[@instruction_index] = @auth_work_instruction
|
80
|
+
@auth_shopping_product.save
|
81
|
+
end
|
82
|
+
respond_to do |format|
|
83
|
+
format.html do
|
84
|
+
render "show"
|
85
|
+
end
|
86
|
+
format.json do
|
87
|
+
render :json => @auth_work_communication.to_json
|
88
|
+
end
|
89
|
+
end
|
51
90
|
end
|
52
91
|
|
53
92
|
def new
|
54
|
-
|
55
|
-
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
def edit
|
97
|
+
|
56
98
|
end
|
57
99
|
|
58
100
|
def index
|
@@ -60,7 +102,7 @@ module Auth::Concerns::Work::CommunicationControllerConcern
|
|
60
102
|
end
|
61
103
|
|
62
104
|
def update
|
63
|
-
|
105
|
+
## now this still needs to be coded but will come to that later.
|
64
106
|
end
|
65
107
|
|
66
108
|
def show
|
@@ -72,7 +114,7 @@ module Auth::Concerns::Work::CommunicationControllerConcern
|
|
72
114
|
end
|
73
115
|
|
74
116
|
def permitted_params
|
75
|
-
pr = params.permit({:communication => [:send_email,:email_template_path,:method_to_determine_recipients,:repeat,:repeat_times,:method_to_determine_communication_timing,:enqueue_at_time]}, :id
|
117
|
+
pr = params.permit({:communication => [:send_email,:email_template_path,:method_to_determine_recipients,:repeat,:repeat_times,:method_to_determine_communication_timing,:enqueue_at_time,:instruction_id,:cycle_id,:cart_item_id, :product_id, :name, :description]}, :id)
|
76
118
|
end
|
77
119
|
|
78
120
|
end
|
@@ -23,6 +23,9 @@ module Auth::Concerns::Work::InstructionControllerConcern
|
|
23
23
|
else
|
24
24
|
@auth_work_instruction = @auth_work_instruction_class.new(@auth_work_instruction_params)
|
25
25
|
end
|
26
|
+
else
|
27
|
+
|
28
|
+
puts "product not found."
|
26
29
|
end
|
27
30
|
rescue Mongoid::Errors::DocumentNotFound
|
28
31
|
@auth_shopping_product = @auth_shopping_product_class.new
|
@@ -50,7 +53,7 @@ module Auth::Concerns::Work::InstructionControllerConcern
|
|
50
53
|
render json: @auth_work_instruction.to_json
|
51
54
|
end
|
52
55
|
format.html do
|
53
|
-
render
|
56
|
+
render "show"
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
@@ -89,7 +92,7 @@ module Auth::Concerns::Work::InstructionControllerConcern
|
|
89
92
|
end
|
90
93
|
|
91
94
|
def new
|
92
|
-
|
95
|
+
puts "the product is: #{@auth_shopping_product.to_s}"
|
93
96
|
end
|
94
97
|
|
95
98
|
def edit
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CommunicationJob < ActiveJob::Base
|
2
|
+
queue_as :default
|
3
|
+
self.queue_adapter = :delayed_job
|
4
|
+
|
5
|
+
##we currently log all exceptions to redis.
|
6
|
+
rescue_from(StandardError) do |exception|
|
7
|
+
puts exception.message
|
8
|
+
puts exception.backtrace.join("\n")
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform(arguments)
|
12
|
+
if communication = Auth.configuration.communication_class.constantize.find_communication(arguments)
|
13
|
+
if time = communication.deliver_all
|
14
|
+
CommunicationJob.set(wait_until: time).perform_later(arguments)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -4,12 +4,9 @@ class Auth::SendMail < ActionMailer::Base
|
|
4
4
|
@options = opts || {}
|
5
5
|
raise "no recipient address" unless @options[:to]
|
6
6
|
raise "no subject" unless @options[:to]
|
7
|
+
|
7
8
|
mail(to: @options[:to], subject: @options[:subject]) do |format|
|
8
9
|
format.html { render @options[:template] || "send" }
|
9
10
|
end
|
10
11
|
end
|
11
|
-
## okay so for this, we will pass it to otp job only.
|
12
|
-
## with some arguments.
|
13
|
-
## why not use whatever emailer i was using before ?
|
14
|
-
## okay so the next step is to send this whole notification into a delayed job.
|
15
12
|
end
|
@@ -12,6 +12,10 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
12
12
|
|
13
13
|
included do
|
14
14
|
|
15
|
+
embeds_many :instructions, :class_name => "Auth::Work::Instruction", :as => :cart_item_instructions
|
16
|
+
|
17
|
+
|
18
|
+
|
15
19
|
INDEX_DEFINITION = {
|
16
20
|
index_options: {
|
17
21
|
settings: {
|
@@ -80,9 +84,7 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
80
84
|
}
|
81
85
|
}
|
82
86
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
87
|
+
|
86
88
|
|
87
89
|
##PERMITTED
|
88
90
|
##the id of the product to which this cart item refers.
|
@@ -169,6 +171,25 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
169
171
|
document.public = "no"
|
170
172
|
end
|
171
173
|
|
174
|
+
## first of all how are the instructions copied over from the product to the cart item.
|
175
|
+
## that's it, now all the communication instructions are enqueued.
|
176
|
+
## next step, get a simple notification to be sent by email, and also by sms -> as soon as the time comes for it to be done.
|
177
|
+
after_save do |document|
|
178
|
+
puts "came to after_save document #{document.accepted_changed?}"
|
179
|
+
puts "is it true :#{document.accepted == true}"
|
180
|
+
if document.accepted_changed? && document.accepted == true
|
181
|
+
puts "accepted changed."
|
182
|
+
document.instructions.each do |instruction|
|
183
|
+
puts "doing instruction: #{instruction.id.to_s}"
|
184
|
+
instruction.communications.each do |communication|
|
185
|
+
## Test seperately?
|
186
|
+
## => fuck that.
|
187
|
+
puts "doing communication: #{communication.id.to_s}"
|
188
|
+
CommunicationJob.set(wait_until: communication.set_enqueue_at).perform_later({:cart_item_id => document.id.to_s, :instruction_id => instruction.id.to_s, :communication_id => communication.id.to_s})
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
172
193
|
end
|
173
194
|
|
174
195
|
|
@@ -190,7 +211,7 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
190
211
|
### this is an internal method, cannot be set by admin or anyone, it is done after validation, since it is not necessary for someone to be admin, even the user can call refresh on the record to get the new state of the acceptence.
|
191
212
|
## just checks if the accepted by payment id exists, and if yes, then doesnt do anything, otherwise will update the cart item status as false.
|
192
213
|
def refresh_accepted
|
193
|
-
puts "CALLED REFRESH accepted-----------------------"
|
214
|
+
#puts "CALLED REFRESH accepted-----------------------"
|
194
215
|
if self.accepted_by_payment_id
|
195
216
|
|
196
217
|
begin
|
@@ -199,7 +220,7 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
199
220
|
## if the payment status is approved, then dont do anything to the cart item.(we don't retro check payment to cart item.)
|
200
221
|
## if the payment status is not approved, then make the cart item accepted as false.
|
201
222
|
if (payment.payment_status.nil? || payment.payment_status == 0)
|
202
|
-
puts "FOUND THE PAYMENT STATUS TO BE NIL or 0"
|
223
|
+
#puts "FOUND THE PAYMENT STATUS TO BE NIL or 0"
|
203
224
|
self.accepted = false
|
204
225
|
end
|
205
226
|
rescue Mongoid::Errors::DocumentNotFound
|
@@ -292,8 +313,8 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
292
313
|
}
|
293
314
|
)
|
294
315
|
|
295
|
-
puts "the doc after update is:"
|
296
|
-
puts doc_after_update.attributes.to_s
|
316
|
+
#puts "the doc after update is:"
|
317
|
+
#puts doc_after_update.attributes.to_s
|
297
318
|
|
298
319
|
return false unless doc_after_update
|
299
320
|
return false if doc_after_update.accepted != self.accepted
|
@@ -307,9 +328,9 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
307
328
|
## the #debit function returns the current cart credit.
|
308
329
|
## return true or false depending on whether , after debiting there is any credit left in the cart or not.
|
309
330
|
def cart_has_sufficient_credit_for_item?(cart)
|
310
|
-
puts "cart credit is: #{cart.cart_credit}"
|
331
|
+
#puts "cart credit is: #{cart.cart_credit}"
|
311
332
|
cart_has_credit = cart.debit((self.accept_order_at_percentage_of_price*self.price)) >= 0
|
312
|
-
puts "cart has credit is: #{cart_has_credit.to_s}"
|
333
|
+
#puts "cart has credit is: #{cart_has_credit.to_s}"
|
313
334
|
cart_has_credit
|
314
335
|
end
|
315
336
|
|
@@ -405,10 +426,11 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
405
426
|
if self.product_id
|
406
427
|
if product = Auth.configuration.product_class.constantize.find(product_id)
|
407
428
|
product_attributes_to_assign.each do |attr|
|
408
|
-
## only if the present attribute is nil, then we assign it from the product.
|
409
429
|
if self.respond_to? attr.to_sym
|
410
430
|
if self.send("#{attr}").nil?
|
411
431
|
self.send("#{attr}=",product.send("#{attr}"))
|
432
|
+
elsif (self.send("#{attr}").respond_to? :embedded_in) && (self.send("#{attr}").empty?)
|
433
|
+
self.send("#{attr}=",product.send("#{attr}"))
|
412
434
|
end
|
413
435
|
end
|
414
436
|
end
|
@@ -416,11 +438,11 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
416
438
|
end
|
417
439
|
rescue
|
418
440
|
|
419
|
-
end
|
441
|
+
end
|
420
442
|
end
|
421
443
|
|
422
444
|
def product_attributes_to_assign
|
423
|
-
["name","price","
|
445
|
+
["name","price","bundle_name","instructions"]
|
424
446
|
end
|
425
447
|
|
426
448
|
## this is got by multiplying the price of the cart item by the minimum_acceptable at field.
|
@@ -10,10 +10,11 @@ module Auth::Concerns::Shopping::ProductConcern
|
|
10
10
|
|
11
11
|
included do
|
12
12
|
|
13
|
-
|
13
|
+
|
14
14
|
|
15
15
|
embeds_many :cycles, :class_name => "Auth::Work::Cycle", :as => :product_cycles
|
16
16
|
|
17
|
+
embeds_many :instructions, :class_name => "Auth::Work::Instruction", :as => :product_instructions
|
17
18
|
|
18
19
|
INDEX_DEFINITION = {
|
19
20
|
index_options: {
|
@@ -0,0 +1,82 @@
|
|
1
|
+
## this should be added to any class that embeds communication.rb
|
2
|
+
module Auth::Concerns::Work::CommunicationFieldsConcern
|
3
|
+
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
|
8
|
+
####################################################################
|
9
|
+
##
|
10
|
+
##
|
11
|
+
## COMMON FIELDS
|
12
|
+
##
|
13
|
+
## defaults to the home page.
|
14
|
+
##
|
15
|
+
####################################################################
|
16
|
+
field :link, type: String, default: Auth.configuration.host_name
|
17
|
+
|
18
|
+
####################################################################
|
19
|
+
##
|
20
|
+
##
|
21
|
+
## EMAIL RELATED FIELDS.
|
22
|
+
##
|
23
|
+
##
|
24
|
+
####################################################################
|
25
|
+
field :email_subject, type: String, default: "Attention : #{Auth.configuration.brand_name}"
|
26
|
+
field :email_content, type: String, default: "Hi this email is from #{Auth.configuration.brand_name}"
|
27
|
+
|
28
|
+
####################################################################
|
29
|
+
##
|
30
|
+
##
|
31
|
+
## SMS RELATED FIELDS.
|
32
|
+
##
|
33
|
+
##
|
34
|
+
####################################################################
|
35
|
+
field :sms_content, type: String, default: "Hi this message is from #{Auth.configuration.brand_name}"
|
36
|
+
|
37
|
+
####################################################################
|
38
|
+
##
|
39
|
+
##
|
40
|
+
## MOBILE NOTIFICATIONS.
|
41
|
+
##
|
42
|
+
##
|
43
|
+
####################################################################
|
44
|
+
field :notification_badge, type: String, default: "default"
|
45
|
+
field :notification_content, type: String, default: "Hi this message is from #{Auth.configuration.brand_name}"
|
46
|
+
|
47
|
+
########################################################################
|
48
|
+
##
|
49
|
+
##
|
50
|
+
## It is expected that form fields will be added to the implementing object, for all the fields above. At the same time, the implementing object can override the methods below to provided customization for the fields. In the end, communication.rb, will call these methods on the parent object(eg instruction/cycle), and use the returned values, while sending the notifications.
|
51
|
+
## so for instructions what would you like to have ?
|
52
|
+
##
|
53
|
+
##
|
54
|
+
########################################################################
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_link(args={})
|
59
|
+
self.link
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_email_subject(args={})
|
63
|
+
self.email_subject
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_email_content(args={})
|
67
|
+
self.email_content
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_sms_content(args={})
|
71
|
+
self.sms_content
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_notification_badge(args={})
|
75
|
+
self.notification_badge
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_notification_content(args={})
|
79
|
+
self.notification_content
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|