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
@@ -6,7 +6,6 @@ module Auth::Concerns::Work::GoodConcern
|
|
6
6
|
|
7
7
|
included do
|
8
8
|
embeds_many :parameters, :class_name => "Auth::Work::Parameter"
|
9
|
-
embeds_many :instructions, :class_name => "Auth::Work::Instruction"
|
10
9
|
embeds_many :actors, :class_name => "Auth::Work::Actor"
|
11
10
|
embeds_many :variables, :class_name => "Auth::Work::Variable"
|
12
11
|
|
@@ -1,13 +1,5 @@
|
|
1
1
|
class Auth::Work::Communication
|
2
2
|
include Auth::Concerns::ChiefModelConcern
|
3
|
-
|
4
|
-
## 1. it has been embedded, now let me create the ui to edit the communication, for email fields, and then we proceed to email, for this we will need routes and forms.
|
5
|
-
## so i need to see how the communications were made.
|
6
|
-
## 2. finish the surveys
|
7
|
-
## 3. finish two tradegenie tests
|
8
|
-
## 4. finish booking cycle.
|
9
|
-
|
10
|
-
|
11
3
|
###################################################################
|
12
4
|
##
|
13
5
|
##
|
@@ -16,9 +8,18 @@ class Auth::Work::Communication
|
|
16
8
|
##
|
17
9
|
###################################################################
|
18
10
|
|
19
|
-
|
20
|
-
attr_accessor :
|
11
|
+
## since we already find the cart item, instruction, cycle or product at the beginning, will store these as attr accessors, not naming as instruction/cycle/cart_item/product because i don't want to interfere with mongoid, which ideally should be setting these , but is not.
|
12
|
+
attr_accessor :_instruction
|
13
|
+
attr_accessor :_instruction_index
|
14
|
+
attr_accessor :_cart_item
|
21
15
|
|
16
|
+
## the communications own index in the instruction, or whatever is its parent.
|
17
|
+
attr_accessor :_index
|
18
|
+
attr_accessor :_product
|
19
|
+
attr_accessor :_cycle
|
20
|
+
attr_accessor :_cycle_index
|
21
|
+
|
22
|
+
|
22
23
|
###################################################################
|
23
24
|
##
|
24
25
|
##
|
@@ -28,11 +29,31 @@ class Auth::Work::Communication
|
|
28
29
|
###################################################################
|
29
30
|
|
30
31
|
## now give the view to show this
|
31
|
-
embedded_in :
|
32
|
+
embedded_in :cycle, :class_name => "Auth::Work::Cycle", :polymorphic => true
|
32
33
|
|
33
34
|
## add embedded in products.
|
34
|
-
embedded_in :
|
35
|
+
embedded_in :instruction, :class_name => "Auth::Work::Instruction", :polymorphic => true
|
35
36
|
|
37
|
+
###################################################################
|
38
|
+
##
|
39
|
+
##
|
40
|
+
## METHODS FOR DEFER JOB.
|
41
|
+
##
|
42
|
+
##
|
43
|
+
###################################################################
|
44
|
+
|
45
|
+
field :method_to_determine_defer_job, type: String
|
46
|
+
|
47
|
+
###################################################################
|
48
|
+
##
|
49
|
+
##
|
50
|
+
## BASIC DESCRIPTION
|
51
|
+
##
|
52
|
+
##
|
53
|
+
###################################################################
|
54
|
+
field :name, type: String
|
55
|
+
|
56
|
+
field :description, type: String
|
36
57
|
###################################################################
|
37
58
|
##
|
38
59
|
##
|
@@ -41,7 +62,7 @@ class Auth::Work::Communication
|
|
41
62
|
##
|
42
63
|
###################################################################
|
43
64
|
|
44
|
-
field :send_email, type:
|
65
|
+
field :send_email, type: String
|
45
66
|
|
46
67
|
field :email_template_path, type: String
|
47
68
|
|
@@ -60,6 +81,13 @@ class Auth::Work::Communication
|
|
60
81
|
|
61
82
|
## this is got by calling the above method.
|
62
83
|
## this is not a permitted parameter.
|
84
|
+
## so this consists of what exactly ?
|
85
|
+
## the hash is checked for the existence of two keys.
|
86
|
+
##
|
87
|
+
## how to configure notification repeats ?
|
88
|
+
## for eg someone books a 3 times a year diabetes plan.
|
89
|
+
## when should the notifications be set ?
|
90
|
+
## how to configure that ?
|
63
91
|
field :recipients, type: Hash
|
64
92
|
|
65
93
|
###################################################################
|
@@ -74,7 +102,7 @@ class Auth::Work::Communication
|
|
74
102
|
field :repeat, type: String
|
75
103
|
|
76
104
|
## how many times to repeat it.
|
77
|
-
field :repeat_times, type: Integer
|
105
|
+
field :repeat_times, type: Integer, default: 1
|
78
106
|
|
79
107
|
## this is called to determine when to send this communication.
|
80
108
|
field :method_to_determine_communication_timing, type: String
|
@@ -83,12 +111,38 @@ class Auth::Work::Communication
|
|
83
111
|
## this is not a permitted parameters.
|
84
112
|
field :enqueue_at_time, type: Time
|
85
113
|
|
114
|
+
## how many times was this notification repeated till now?
|
115
|
+
field :repeated_times, type: Integer, default: 0
|
116
|
+
|
86
117
|
def set_recipients
|
87
|
-
self.recipients =
|
118
|
+
self.recipients = {:users => [],:topics => []}
|
119
|
+
if self.method_to_determine_recipients.nil?
|
120
|
+
puts "no method to determine recipients."
|
121
|
+
if self._instruction
|
122
|
+
if self._cart_item
|
123
|
+
resource_id = self._cart_item.resource_id
|
124
|
+
resource_class = self._cart_item.resource_class
|
125
|
+
self.recipients[:users] << resource_class.constantize.find(resource_id)
|
126
|
+
elsif self.product_id
|
127
|
+
resource_id = self._product.resource_id
|
128
|
+
resource_class = self._product.resource_class
|
129
|
+
self.recipients[:users] << resource_class.constantize.find(resource_id)
|
130
|
+
end
|
131
|
+
else
|
132
|
+
puts "no instruction found."
|
133
|
+
end
|
134
|
+
else
|
135
|
+
self.recipients = self.send("#{self.method_to_determine_recipients}",self.id.to_s)
|
136
|
+
end
|
88
137
|
end
|
89
138
|
|
90
|
-
def
|
91
|
-
|
139
|
+
def set_enqueue_at
|
140
|
+
if self.method_to_determine_communication_timing.nil?
|
141
|
+
self.enqueue_at_time = Time.now
|
142
|
+
else
|
143
|
+
self.enqueue_at_time = self.send("#{self.method_to_determine_communication_timing}",self.id.to_s)
|
144
|
+
end
|
145
|
+
self.enqueue_at_time
|
92
146
|
end
|
93
147
|
|
94
148
|
def repeat_options
|
@@ -106,4 +160,224 @@ class Auth::Work::Communication
|
|
106
160
|
]
|
107
161
|
end
|
108
162
|
|
109
|
-
|
163
|
+
def decrement_repeated_times
|
164
|
+
|
165
|
+
if self._product
|
166
|
+
Auth.configuration.product_class.constantize.where({
|
167
|
+
"instructions.#{self._instruction_index}.communications.#{self._index}._id" => BSON::ObjectId(self.id.to_s)
|
168
|
+
}).find_one_and_update(
|
169
|
+
{
|
170
|
+
"$inc" => {
|
171
|
+
"instructions.#{self._instruction_index}.communications.#{self._index}.repeated_times" => 1
|
172
|
+
}
|
173
|
+
},
|
174
|
+
{
|
175
|
+
:return_document => :after
|
176
|
+
}
|
177
|
+
)
|
178
|
+
elsif self._cart_item
|
179
|
+
Auth.configuration.cart_item_class.constantize.where({
|
180
|
+
"instructions.#{self._instruction_index}.communications.#{self._index}._id" => BSON::ObjectId(self.id.to_s)
|
181
|
+
}).find_one_and_update(
|
182
|
+
{
|
183
|
+
"$inc" => {
|
184
|
+
"instructions.#{self._instruction_index}.communications.#{self._index}.repeated_times" => 1
|
185
|
+
}
|
186
|
+
},
|
187
|
+
{
|
188
|
+
:return_document => :after
|
189
|
+
}
|
190
|
+
)
|
191
|
+
elsif self._cycle
|
192
|
+
#coll = Auth.configuration.cycle_class.constantize.collection
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
def enqueue_repeat
|
198
|
+
if self.repeated_times < self.repeat_times
|
199
|
+
if self.repeat
|
200
|
+
if self.decrement_repeated_times
|
201
|
+
puts "repeated times"
|
202
|
+
puts self.repeated_times
|
203
|
+
puts "repeat times."
|
204
|
+
puts self.repeat_times
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
enqueue_repeat_at = nil
|
209
|
+
|
210
|
+
case self.repeat
|
211
|
+
when "Daily"
|
212
|
+
enqueue_repeat_at = Time.now + 1.day
|
213
|
+
when "Weekly"
|
214
|
+
enqueue_repeat_at = Time.now + 1.week
|
215
|
+
when "Monthly"
|
216
|
+
enqueue_repeat_at = Time.now + 1.month
|
217
|
+
when "Yearly"
|
218
|
+
enqueue_repeat_at = Time.now + 1.year
|
219
|
+
when "Half-Monthly"
|
220
|
+
enqueue_repeat_at = Time.now + 6.months
|
221
|
+
end
|
222
|
+
|
223
|
+
args = {}
|
224
|
+
args[:instruction_id] = self._instruction.id.to_s if self._instruction
|
225
|
+
args[:communication_id] = self.id.to_s
|
226
|
+
args[:cart_item_id] = self._cart_item.id.to_s if self._cart_item
|
227
|
+
args[:product_id] = self._product.id.to_s if self._product
|
228
|
+
args[:cycle_id] = self._cycle.id.to_s if self._cycle
|
229
|
+
|
230
|
+
CommunicationJob.set(wait_until: enqueue_repeat_at).perform_later(args)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
|
237
|
+
## @return[Boolean] : will return false if there is no method defined which can help to determine if the job should be done or deferred. Will otherwise call that method, and return its result.
|
238
|
+
## that method is expected to return a Time object that will be used by the communicationJob to requeue itself.
|
239
|
+
def defer_job
|
240
|
+
return false if self.method_to_determine_defer_job.nil?
|
241
|
+
self.send("#{self.method_to_determine_defer_job}",self.id.to_s)
|
242
|
+
end
|
243
|
+
|
244
|
+
## @return[Time] : returns a time object at which this job should be reenqueud. If it does not return a time object, then the job is not to be reenqueud, and basically was done immediately.
|
245
|
+
def deliver_all
|
246
|
+
defer_job_result = defer_job
|
247
|
+
unless defer_job_result == false
|
248
|
+
return defer_job_result
|
249
|
+
end
|
250
|
+
set_recipients
|
251
|
+
deliver_email
|
252
|
+
deliver_sms
|
253
|
+
deliver_mobile_notification
|
254
|
+
enqueue_repeat
|
255
|
+
return nil
|
256
|
+
end
|
257
|
+
|
258
|
+
def get_parent_object
|
259
|
+
self._instruction || self._cycle
|
260
|
+
end
|
261
|
+
|
262
|
+
def deliver_email
|
263
|
+
return unless self.send_email == "on"
|
264
|
+
self.recipients[:users].each do |recipient|
|
265
|
+
puts "checking email recipient."
|
266
|
+
puts recipient.email.to_s
|
267
|
+
puts recipient.confirmed_at.to_s
|
268
|
+
if recipient.email && recipient.confirmed_at
|
269
|
+
puts "sending email."
|
270
|
+
Auth::SendMail.send_email({to: recipient.email, subject: get_parent_object.get_email_subject, content: get_parent_object.get_email_content, link: get_parent_object.get_link}).deliver
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def deliver_sms
|
276
|
+
self.recipients[:users].each do |recipient|
|
277
|
+
if recipient.additional_login_param
|
278
|
+
###################################################
|
279
|
+
## SET NUMBER
|
280
|
+
###################################################
|
281
|
+
to_number = recipient.additional_login_param
|
282
|
+
|
283
|
+
###################################################
|
284
|
+
## SET TEMPLATE NAME
|
285
|
+
###################################################
|
286
|
+
template_name = Auth.configuration.two_factor_otp_transactional_sms_template_name
|
287
|
+
|
288
|
+
###################################################
|
289
|
+
##
|
290
|
+
##
|
291
|
+
## SET VAR HASH
|
292
|
+
##
|
293
|
+
##
|
294
|
+
###################################################
|
295
|
+
var_hash = {:var2 => get_parent_object.get_link, :var1 => get_parent_object.get_sms_content}
|
296
|
+
|
297
|
+
########################################################
|
298
|
+
## SET TEMPLATE SENDER ID
|
299
|
+
#######################################################
|
300
|
+
template_sender_id = Auth.configuration.two_factor_otp_transactional_sms_template_sender_id
|
301
|
+
|
302
|
+
########################################################
|
303
|
+
## ONLY SEND THE SMS IF THE VAR HASH CONTAINS DATA.
|
304
|
+
|
305
|
+
url = "https://2factor.in/API/R1/?module=TRANS_SMS"
|
306
|
+
|
307
|
+
params = {
|
308
|
+
apikey: Auth.configuration.third_party_api_keys[:two_factor_sms_api_key],
|
309
|
+
to: to_number,
|
310
|
+
from: template_sender_id,
|
311
|
+
templatename: template_name,
|
312
|
+
}.merge(var_hash)
|
313
|
+
|
314
|
+
request = Typhoeus::Request.new(
|
315
|
+
url,
|
316
|
+
params: params,
|
317
|
+
timeout: 10
|
318
|
+
)
|
319
|
+
|
320
|
+
response = request.run
|
321
|
+
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
def deliver_mobile_notification
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
#####################################################################
|
336
|
+
##
|
337
|
+
##
|
338
|
+
## CLASS METHODS.
|
339
|
+
##
|
340
|
+
##
|
341
|
+
#####################################################################
|
342
|
+
def self.find_communication(arguments)
|
343
|
+
communication_id = arguments[:communication_id]
|
344
|
+
instruction_id = arguments[:instruction_id]
|
345
|
+
cart_item_id = arguments[:cart_item_id]
|
346
|
+
if communication_id && instruction_id && cart_item_id
|
347
|
+
if cart_item = Auth.configuration.cart_item_class.constantize.find(cart_item_id)
|
348
|
+
instruction = nil
|
349
|
+
instruction_index = nil
|
350
|
+
communication = nil
|
351
|
+
communication_index = nil
|
352
|
+
|
353
|
+
cart_item.instructions.each_with_index{|value,key|
|
354
|
+
if value.id.to_s == instruction_id
|
355
|
+
instruction = value
|
356
|
+
instruction_index = key
|
357
|
+
end
|
358
|
+
}
|
359
|
+
|
360
|
+
instruction.communications.each_with_index{|value,key|
|
361
|
+
|
362
|
+
if value.id.to_s == communication_id
|
363
|
+
communication = value
|
364
|
+
communication_index = key
|
365
|
+
end
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
instruction.cart_item_id = cart_item_id
|
370
|
+
communication._instruction = instruction
|
371
|
+
communication._cart_item = cart_item
|
372
|
+
communication._instruction_index = instruction_index
|
373
|
+
communication._index = communication_index
|
374
|
+
|
375
|
+
return communication
|
376
|
+
end
|
377
|
+
elsif communication_id && instruction_id && product_id
|
378
|
+
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
|
383
|
+
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
class Auth::Work::Instruction
|
2
2
|
include Mongoid::Document
|
3
3
|
include Auth::Concerns::ChiefModelConcern
|
4
|
-
|
4
|
+
include Auth::Concerns::Work::CommunicationFieldsConcern
|
5
|
+
|
5
6
|
attr_accessor :product_id
|
7
|
+
attr_accessor :cart_item_id
|
6
8
|
|
7
9
|
INSTRUCTION_TYPES = ["Before The Test","After The Test","During The Test","Who This Test is For","Who Should Not Take This Test"]
|
8
10
|
|
9
|
-
embedded_in :
|
11
|
+
embedded_in :cart_item, :class_name => Auth.configuration.cart_item_class, :polymorphic => true
|
12
|
+
|
13
|
+
embedded_in :product, :class_name => Auth.configuration.product_class, :polymorphic => true
|
10
14
|
|
11
15
|
field :summary_icon_class, type: String
|
12
16
|
|
@@ -24,4 +28,22 @@ class Auth::Work::Instruction
|
|
24
28
|
embeds_many :bullets, :class_name => "Auth::Work::Bullet"
|
25
29
|
embeds_many :communications, :class_name => "Auth::Work::Communication", :as => :instruction_communications
|
26
30
|
|
31
|
+
########################################################################
|
32
|
+
##
|
33
|
+
##
|
34
|
+
## Overridden methods from communication_fields_concern.rb
|
35
|
+
##
|
36
|
+
##
|
37
|
+
########################################################################
|
38
|
+
def get_link(args={})
|
39
|
+
if self.product_id
|
40
|
+
Rails.application.routes.url_helpers.instruction_url({:product_id => self.product_id, :id => self.id.to_s})
|
41
|
+
elsif self.cart_item_id
|
42
|
+
Rails.application.routes.url_helpers.instruction_url({:cart_item_id => self.cart_item_id, :id => self.id.to_s})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
## okay let me test upto this point.
|
47
|
+
## create a
|
48
|
+
|
27
49
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<div class="row">
|
2
2
|
<div class="input-field col l6 m6 s12 offset-l3 offset-m3">
|
3
|
-
<input placeholder="Search" id="
|
4
|
-
<label for="
|
3
|
+
<input placeholder="Search" id="place_search" type="text" class="validate fs-22 center">
|
4
|
+
<label for="place_search"></label>
|
5
5
|
</div>
|
6
6
|
</div>
|
@@ -1,14 +1,26 @@
|
|
1
1
|
<%= form_for(@auth_work_communication, as: "communication", url: @auth_work_communication.new_record? ? communications_path : communication_path(:id => @auth_work_communication.id.to_s), method: @auth_work_communication.new_record? ? :post : :put) do |f| %>
|
2
2
|
<div class="form_fields">
|
3
|
+
<div id="basic_options">
|
4
|
+
|
5
|
+
<%= f.text_field :name %>
|
6
|
+
<%= f.label :name %>
|
7
|
+
|
8
|
+
<%= f.text_field :description %>
|
9
|
+
<%= f.label :description %>
|
10
|
+
|
11
|
+
</div>
|
3
12
|
<div id="email_options">
|
4
13
|
<h5>E-Mail Options</h5>
|
5
|
-
|
6
|
-
|
14
|
+
<label>
|
15
|
+
<input type="checkbox" id="communication_send_email" name="communication[send_email]"/>
|
16
|
+
<span>Send Email</span>
|
17
|
+
</label>
|
18
|
+
|
7
19
|
|
8
20
|
<%= f.text_field :email_template_path %>
|
9
21
|
<%= f.label :email_template_path %>
|
10
22
|
</div>
|
11
|
-
|
23
|
+
<!-- give the option to create the instruction -->
|
12
24
|
<div class="divider"> </div>
|
13
25
|
|
14
26
|
<div id="repeat_options">
|
@@ -33,13 +45,25 @@
|
|
33
45
|
|
34
46
|
<% if @auth_work_communication.cycle_id %>
|
35
47
|
<%=
|
36
|
-
|
48
|
+
f.hidden_field :cycle_id, value: @auth_work_communication.cycle_id.to_s
|
37
49
|
%>
|
38
50
|
<% end %>
|
39
51
|
|
40
52
|
<% if @auth_work_communication.instruction_id %>
|
41
53
|
<%=
|
42
|
-
|
54
|
+
f.hidden_field :instruction_id, value: @auth_work_communication.instruction_id.to_s
|
55
|
+
%>
|
56
|
+
<% end %>
|
57
|
+
|
58
|
+
<% if @auth_work_communication.product_id %>
|
59
|
+
<%=
|
60
|
+
f.hidden_field :product_id, value: @auth_work_communication.product_id.to_s
|
61
|
+
%>
|
62
|
+
<% end %>
|
63
|
+
|
64
|
+
<% if @auth_work_communication.cart_item_id %>
|
65
|
+
<%=
|
66
|
+
f.hidden_field :cart_item_id, value: @auth_work_communication.cart_item_id.to_s
|
43
67
|
%>
|
44
68
|
<% end %>
|
45
69
|
|