wordjelly-auth 1.2.5 → 1.2.6
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/auth/auth_modals_and_navbar.js +1 -0
- data/app/controllers/auth/concerns/token_concern.rb +9 -10
- data/app/controllers/auth/search_controller.rb +25 -23
- data/app/models/auth/concerns/chief_model_concern.rb +4 -15
- data/app/models/auth/concerns/es_concern.rb +137 -0
- data/app/models/auth/concerns/image_load_concern.rb +21 -0
- data/app/models/auth/concerns/search/autocompleted_concern.rb +139 -0
- data/app/models/auth/concerns/shopping/bar_code_concern.rb +29 -0
- data/app/models/auth/concerns/shopping/cart_concern.rb +20 -6
- data/app/models/auth/concerns/shopping/cart_item_concern.rb +54 -82
- data/app/models/auth/concerns/shopping/personality_concern.rb +75 -55
- data/app/models/auth/concerns/shopping/place_concern.rb +1 -3
- data/app/models/auth/concerns/shopping/product_concern.rb +71 -174
- data/app/models/auth/concerns/user_concern.rb +7 -66
- data/app/models/auth/shopping/bar_code.rb +71 -0
- data/app/models/auth/shopping/personality.rb +9 -0
- data/app/models/auth/work/bullet.rb +3 -1
- data/app/models/auth/work/communication.rb +3 -1
- data/app/models/auth/work/instruction.rb +2 -1
- data/app/models/auth/work/link.rb +3 -1
- data/app/views/auth/search/_search_bar.html.erb +12 -7
- data/app/views/auth/search/_search_result.html.erb +21 -7
- data/app/views/auth/search/authenticated_user_search.js.erb +8 -15
- data/app/views/auth/search/authenticated_user_search.json +1 -1
- data/app/views/layouts/auth/application.html.erb +1 -1
- data/app/views/layouts/auth/navbar/_navbar.html.erb +5 -5
- data/config/initializers/omniauth.rb +0 -3
- data/lib/assets/javascripts/bar_code.js +97 -0
- data/lib/assets/javascripts/search.js +32 -12
- data/lib/assets/javascripts/spinner.js +5 -3
- data/lib/auth/engine.rb +40 -0
- data/lib/auth/rails/routes.rb +2 -0
- data/lib/auth/search/main.rb +28 -13
- data/lib/auth/version.rb +1 -1
- data/lib/wordjelly-auth.rb +2 -1
- data/spec/dummy/app/assets/time_hashes.json +1 -1
- data/spec/dummy/app/models/shopping/cart.rb +1 -1
- data/spec/dummy/app/models/shopping/cart_item.rb +11 -1
- data/spec/dummy/app/models/shopping/personality.rb +1 -0
- data/spec/dummy/app/models/shopping/place.rb +1 -0
- data/spec/dummy/app/models/shopping/product.rb +8 -10
- data/spec/dummy/app/models/user.rb +8 -17
- data/spec/dummy/config/initializers/preinitializer.rb +0 -1
- data/spec/factories/client_factory.rb +2 -0
- data/spec/requests/search/search_request_spec.rb +50 -50
- data/spec/support/sign_in_support.rb +40 -0
- metadata +35 -3
- data/app/views/auth/search/_search_results.html.erb +0 -4
@@ -0,0 +1,29 @@
|
|
1
|
+
module Auth::Concerns::Shopping::BarCodeConcern
|
2
|
+
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
field :bar_code_tag, type: String
|
7
|
+
attr_accessor :remove_bar_code
|
8
|
+
|
9
|
+
## do this before validation so that it provides a way to prevent the document from being saved, in case the bar code collection cannot be updated successfully.
|
10
|
+
before_validation do |document|
|
11
|
+
if document.bar_code_tag_changed? && document.bar_code_tag.nil?
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
## do this after_save, so that at the minimum this bar_code_tag cannot be used again in this collection.
|
19
|
+
after_save do |document|
|
20
|
+
if document.bar_code_tag_changed? && document.bar_code_tag_was.nil?
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
## how will all this finish.?
|
@@ -5,6 +5,8 @@ module Auth::Concerns::Shopping::CartConcern
|
|
5
5
|
|
6
6
|
include Auth::Concerns::ChiefModelConcern
|
7
7
|
include Auth::Concerns::OwnerConcern
|
8
|
+
include Auth::Concerns::EsConcern
|
9
|
+
|
8
10
|
|
9
11
|
included do
|
10
12
|
field :name, type: String
|
@@ -14,7 +16,7 @@ module Auth::Concerns::Shopping::CartConcern
|
|
14
16
|
field :place_id, type: String
|
15
17
|
## name, age, sex of the user for this cart.
|
16
18
|
field :personality_id, type: String
|
17
|
-
|
19
|
+
attr_accessor :personality
|
18
20
|
|
19
21
|
## debit is calculated live, by first getting all the items already dispatched and their value, and then getting the total payments made and their value, so it infact becomes something at the validation level of the cart item.
|
20
22
|
|
@@ -71,8 +73,19 @@ module Auth::Concerns::Shopping::CartConcern
|
|
71
73
|
validate :add_or_remove_validation
|
72
74
|
|
73
75
|
|
74
|
-
##
|
75
|
-
|
76
|
+
## INDEX DEFINITION
|
77
|
+
|
78
|
+
INDEX_DEFINITION = {
|
79
|
+
index_options: {
|
80
|
+
settings: {
|
81
|
+
index: Auth::Concerns::EsConcern::AUTOCOMPLETE_INDEX_SETTINGS
|
82
|
+
},
|
83
|
+
mappings: {
|
84
|
+
Auth::OmniAuth::Path.pathify(Auth.configuration.cart_class) => Auth::Concerns::EsConcern::AUTOCOMPLETE_INDEX_MAPPINGS
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
76
89
|
|
77
90
|
end
|
78
91
|
|
@@ -107,7 +120,7 @@ module Auth::Concerns::Shopping::CartConcern
|
|
107
120
|
|
108
121
|
## set the cart items, [Array] of cart items.
|
109
122
|
def find_cart_items
|
110
|
-
puts "find cart items."
|
123
|
+
#puts "find cart items."
|
111
124
|
conditions = {:resource_id => get_resource.id.to_s, :parent_id => self.id.to_s}
|
112
125
|
self.cart_items = Auth.configuration.cart_item_class.constantize.where(conditions).order(:created_at => 'asc')
|
113
126
|
|
@@ -301,11 +314,12 @@ module Auth::Concerns::Shopping::CartConcern
|
|
301
314
|
|
302
315
|
cart_item.signed_in_resource = self.signed_in_resource
|
303
316
|
|
304
|
-
puts "Add or remove is: #{add_or_remove}"
|
317
|
+
#puts "Add or remove is: #{add_or_remove}"
|
305
318
|
|
319
|
+
## and personality also has to be set here.
|
306
320
|
resp = (add_or_remove == 1) ? cart_item.set_cart_and_resource(self) : cart_item.unset_cart
|
307
321
|
|
308
|
-
puts "unset cart is:#{resp.to_s}"
|
322
|
+
#puts "unset cart is:#{resp.to_s}"
|
309
323
|
|
310
324
|
|
311
325
|
resp
|
@@ -6,85 +6,27 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
include Auth::Concerns::Shopping::ProductConcern
|
9
|
-
include Auth::Concerns::OwnerConcern
|
10
|
-
include Auth::Concerns::EsConcern
|
11
9
|
|
10
|
+
|
12
11
|
|
13
12
|
included do
|
14
13
|
|
15
|
-
embeds_many :instructions, :class_name => "Auth::Work::Instruction", :as => :cart_item_instructions
|
14
|
+
embeds_many :instructions, :class_name => "Auth::Work::Instruction", :as => :cart_item_instructions, :cascade_callbacks => true
|
16
15
|
|
17
16
|
|
18
17
|
|
19
18
|
INDEX_DEFINITION = {
|
20
19
|
index_options: {
|
21
20
|
settings: {
|
22
|
-
index:
|
23
|
-
analysis: {
|
24
|
-
filter: {
|
25
|
-
nGram_filter: {
|
26
|
-
type: "nGram",
|
27
|
-
min_gram: 2,
|
28
|
-
max_gram: 20,
|
29
|
-
token_chars: [
|
30
|
-
"letter",
|
31
|
-
"digit",
|
32
|
-
"punctuation",
|
33
|
-
"symbol"
|
34
|
-
]
|
35
|
-
}
|
36
|
-
},
|
37
|
-
analyzer: {
|
38
|
-
nGram_analyzer: {
|
39
|
-
type: "custom",
|
40
|
-
tokenizer: "whitespace",
|
41
|
-
filter: [
|
42
|
-
"lowercase",
|
43
|
-
"asciifolding",
|
44
|
-
"nGram_filter"
|
45
|
-
]
|
46
|
-
},
|
47
|
-
whitespace_analyzer: {
|
48
|
-
type: "custom",
|
49
|
-
tokenizer: "whitespace",
|
50
|
-
filter: [
|
51
|
-
"lowercase",
|
52
|
-
"asciifolding"
|
53
|
-
]
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|
57
|
-
}
|
21
|
+
index: Auth::Concerns::EsConcern::AUTOCOMPLETE_INDEX_SETTINGS
|
58
22
|
},
|
59
23
|
mappings: {
|
60
|
-
Auth::OmniAuth::Path.pathify(Auth.configuration.cart_item_class) =>
|
61
|
-
properties: {
|
62
|
-
_all_fields: {
|
63
|
-
type: "text",
|
64
|
-
analyzer: "nGram_analyzer",
|
65
|
-
search_analyzer: "whitespace_analyzer"
|
66
|
-
},
|
67
|
-
name: {
|
68
|
-
type: "keyword",
|
69
|
-
copy_to: "_all_fields"
|
70
|
-
},
|
71
|
-
price: {
|
72
|
-
type: "double",
|
73
|
-
copy_to: "_all_fields"
|
74
|
-
},
|
75
|
-
public: {
|
76
|
-
type: "keyword"
|
77
|
-
},
|
78
|
-
resource_id: {
|
79
|
-
type: "keyword",
|
80
|
-
copy_to: "_all_fields"
|
81
|
-
}
|
82
|
-
}
|
83
|
-
}
|
24
|
+
Auth::OmniAuth::Path.pathify(Auth.configuration.cart_item_class) => Auth::Concerns::EsConcern::AUTOCOMPLETE_INDEX_MAPPINGS
|
84
25
|
}
|
85
26
|
}
|
86
27
|
}
|
87
|
-
|
28
|
+
|
29
|
+
|
88
30
|
|
89
31
|
##PERMITTED
|
90
32
|
##the id of the product to which this cart item refers.
|
@@ -134,6 +76,9 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
134
76
|
#################################################################
|
135
77
|
field :unit_id, type: String
|
136
78
|
|
79
|
+
field :personality_id, type: String
|
80
|
+
|
81
|
+
field :place_id, type: String
|
137
82
|
|
138
83
|
|
139
84
|
before_destroy do |document|
|
@@ -159,8 +104,10 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
159
104
|
end
|
160
105
|
|
161
106
|
|
162
|
-
|
163
|
-
document.
|
107
|
+
after_initialize do |document|
|
108
|
+
if document.new_record?
|
109
|
+
document.assign_product_attributes
|
110
|
+
end
|
164
111
|
end
|
165
112
|
|
166
113
|
|
@@ -175,16 +122,16 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
175
122
|
## that's it, now all the communication instructions are enqueued.
|
176
123
|
## 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
124
|
after_save do |document|
|
178
|
-
puts "came to after_save document #{document.accepted_changed?}"
|
179
|
-
puts "is it true :#{document.accepted == true}"
|
125
|
+
#puts "came to after_save document #{document.accepted_changed?}"
|
126
|
+
#puts "is it true :#{document.accepted == true}"
|
180
127
|
if document.accepted_changed? && document.accepted == true
|
181
|
-
puts "accepted changed."
|
128
|
+
#puts "accepted changed."
|
182
129
|
document.instructions.each do |instruction|
|
183
|
-
puts "doing instruction: #{instruction.id.to_s}"
|
130
|
+
#puts "doing instruction: #{instruction.id.to_s}"
|
184
131
|
instruction.communications.each do |communication|
|
185
132
|
## Test seperately?
|
186
133
|
## => fuck that.
|
187
|
-
puts "doing communication: #{communication.id.to_s}"
|
134
|
+
#puts "doing communication: #{communication.id.to_s}"
|
188
135
|
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
136
|
end
|
190
137
|
end
|
@@ -367,6 +314,8 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
367
314
|
return true if self.parent_id
|
368
315
|
return false if (owner_matches(cart) == false)
|
369
316
|
self.parent_id = cart.id.to_s
|
317
|
+
self.personality_id = cart.personality_id
|
318
|
+
self.place_id = cart.place_id
|
370
319
|
self.accepted = nil
|
371
320
|
self.accepted_by_payment_id = nil
|
372
321
|
self.save
|
@@ -425,9 +374,16 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
425
374
|
begin
|
426
375
|
if self.product_id
|
427
376
|
if product = Auth.configuration.product_class.constantize.find(product_id)
|
377
|
+
#puts "product found."
|
378
|
+
#puts "product miscellaneous_attributes to assign"
|
379
|
+
#puts product_attributes_to_assign.to_s
|
428
380
|
product_attributes_to_assign.each do |attr|
|
381
|
+
#puts "doing attribute:"
|
382
|
+
#puts attr.to_s
|
429
383
|
if self.respond_to? attr.to_sym
|
384
|
+
#puts "responds"
|
430
385
|
if self.send("#{attr}").nil?
|
386
|
+
#puts "it is nil"
|
431
387
|
self.send("#{attr}=",product.send("#{attr}"))
|
432
388
|
elsif (self.send("#{attr}").respond_to? :embedded_in) && (self.send("#{attr}").empty?)
|
433
389
|
self.send("#{attr}=",product.send("#{attr}"))
|
@@ -435,29 +391,45 @@ module Auth::Concerns::Shopping::CartItemConcern
|
|
435
391
|
end
|
436
392
|
end
|
437
393
|
end
|
394
|
+
else
|
395
|
+
#puts "no product id."
|
438
396
|
end
|
439
|
-
rescue
|
440
|
-
|
397
|
+
rescue => e
|
398
|
+
#puts e.to_s
|
441
399
|
end
|
400
|
+
|
401
|
+
self.instructions.each do |instruction|
|
402
|
+
instruction.created_at = nil
|
403
|
+
instruction.updated_at = nil
|
404
|
+
instruction.bullets.each do |bullet|
|
405
|
+
bullet.created_at = nil
|
406
|
+
bullet.updated_at = nil
|
407
|
+
end
|
408
|
+
instruction.communications.each do |communication|
|
409
|
+
communication.created_at = nil
|
410
|
+
communication.updated_at = nil
|
411
|
+
end
|
412
|
+
instruction.links.each do |link|
|
413
|
+
link.created_at = nil
|
414
|
+
link.updated_at = nil
|
415
|
+
end
|
416
|
+
end
|
417
|
+
#puts "attributes assigned are:"
|
418
|
+
#puts self.attributes.to_s
|
442
419
|
end
|
443
420
|
|
444
421
|
def product_attributes_to_assign
|
445
|
-
["name","price","bundle_name","instructions"]
|
422
|
+
["name","price","bundle_name","instructions","components"]
|
446
423
|
end
|
447
424
|
|
448
425
|
## this is got by multiplying the price of the cart item by the minimum_acceptable at field.
|
449
426
|
def minimum_price_required_to_accept_cart_item
|
450
427
|
price*accept_order_at_percentage_of_price
|
451
428
|
end
|
429
|
+
|
430
|
+
|
431
|
+
|
452
432
|
|
453
|
-
def as_indexed_json(options={})
|
454
|
-
{
|
455
|
-
name: name,
|
456
|
-
price: price,
|
457
|
-
resource_id: resource_id,
|
458
|
-
public: public
|
459
|
-
}
|
460
|
-
end
|
461
433
|
|
462
434
|
=begin
|
463
435
|
## @param[String] req : the requirement from the definition. It consists of "*" wildcard, or a product id, or a definition address + product_id -> which is basically one of the output products of the definition. But here it will have the product id, not the self id.
|
@@ -2,82 +2,102 @@ module Auth::Concerns::Shopping::PersonalityConcern
|
|
2
2
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
include Auth::Concerns::OwnerConcern
|
5
|
-
include Auth::Concerns::EsConcern
|
5
|
+
include Auth::Concerns::EsConcern
|
6
|
+
include Mongoid::Autoinc
|
7
|
+
|
6
8
|
|
7
9
|
included do
|
8
10
|
|
9
11
|
INDEX_DEFINITION = {
|
10
12
|
index_options: {
|
11
13
|
settings: {
|
12
|
-
index:
|
13
|
-
analysis: {
|
14
|
-
filter: {
|
15
|
-
nGram_filter: {
|
16
|
-
type: "nGram",
|
17
|
-
min_gram: 2,
|
18
|
-
max_gram: 20,
|
19
|
-
token_chars: [
|
20
|
-
"letter",
|
21
|
-
"digit",
|
22
|
-
"punctuation",
|
23
|
-
"symbol"
|
24
|
-
]
|
25
|
-
}
|
26
|
-
},
|
27
|
-
analyzer: {
|
28
|
-
nGram_analyzer: {
|
29
|
-
type: "custom",
|
30
|
-
tokenizer: "whitespace",
|
31
|
-
filter: [
|
32
|
-
"lowercase",
|
33
|
-
"asciifolding",
|
34
|
-
"nGram_filter"
|
35
|
-
]
|
36
|
-
},
|
37
|
-
whitespace_analyzer: {
|
38
|
-
type: "custom",
|
39
|
-
tokenizer: "whitespace",
|
40
|
-
filter: [
|
41
|
-
"lowercase",
|
42
|
-
"asciifolding"
|
43
|
-
]
|
44
|
-
}
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
14
|
+
index: Auth::Concerns::EsConcern::AUTOCOMPLETE_INDEX_SETTINGS
|
48
15
|
},
|
49
16
|
mappings: {
|
50
|
-
Auth::OmniAuth::Path.pathify(Auth.configuration.personality_class) =>
|
51
|
-
properties: {
|
52
|
-
_all_fields: {
|
53
|
-
type: "text",
|
54
|
-
analyzer: "nGram_analyzer",
|
55
|
-
search_analyzer: "whitespace_analyzer"
|
56
|
-
},
|
57
|
-
fullname: {
|
58
|
-
type: "keyword",
|
59
|
-
copy_to: "_all_fields"
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}
|
17
|
+
Auth::OmniAuth::Path.pathify(Auth.configuration.personality_class) => Auth::Concerns::EsConcern::AUTOCOMPLETE_INDEX_MAPPINGS
|
63
18
|
}
|
64
19
|
}
|
65
20
|
}
|
66
|
-
|
67
|
-
before_save do |document|
|
68
|
-
document.public = "no"
|
69
|
-
end
|
70
21
|
|
71
22
|
## this will get stored as an epoch.
|
72
|
-
field :date_of_birth, type:
|
23
|
+
field :date_of_birth, type: String
|
73
24
|
|
74
25
|
## full name
|
75
26
|
field :fullname, type: String
|
76
27
|
|
28
|
+
## this is a simple field that is set whenever the date of birth is set.
|
29
|
+
field :age, type: Integer
|
77
30
|
|
78
31
|
field :sex, type: String
|
32
|
+
|
33
|
+
|
34
|
+
##################################################################
|
35
|
+
##
|
36
|
+
##
|
37
|
+
## AUTOINCREMENTING AND HASHID
|
38
|
+
##
|
39
|
+
##
|
40
|
+
##################################################################
|
41
|
+
|
42
|
+
field :auto_incrementing_number, type: Integer
|
43
|
+
|
44
|
+
increments :auto_incrementing_number
|
45
|
+
|
46
|
+
field :unique_hash_id, type: String
|
47
|
+
|
79
48
|
end
|
80
49
|
|
50
|
+
###############################################################
|
51
|
+
##
|
52
|
+
##
|
53
|
+
## METHOD OVERRIDDEN BECAUSE MONGOID-AUTOINC, CALLS THIS METHOD TO SET THE VALUE OF THE AUTOINCREMENTING FIELD, AND WE NEEDED TO HOOK INTO THAT TO SET THE HASHID.
|
54
|
+
##
|
55
|
+
##
|
56
|
+
###############################################################
|
57
|
+
|
58
|
+
def write_attribute(field,value)
|
59
|
+
super(field,value)
|
60
|
+
if field.to_s == "auto_incrementing_number"
|
61
|
+
if self.auto_incrementing_number_changed?
|
62
|
+
unless self.unique_hash_id
|
63
|
+
hashids = Hashids.new(Auth.configuration.hashids_salt,0,Auth.configuration.hashids_alphabet)
|
64
|
+
self.unique_hash_id = hashids.encode(self.auto_incrementing_number)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
################################################################
|
71
|
+
|
72
|
+
## adds the name, sex, age in years, and the unique hash id for this personality
|
73
|
+
def add_info(tags)
|
74
|
+
tags << self.fullname
|
75
|
+
tags << self.sex
|
76
|
+
tags << ("Age: " + self.age.to_s + " years")
|
77
|
+
tags << self.unique_hash_id
|
78
|
+
end
|
79
|
+
|
80
|
+
## date of birth is going to be a simple string.
|
81
|
+
## format : YYYY-DD-MM, zero padded in case of single digits
|
82
|
+
## so this sets the age, now what.
|
83
|
+
def date_of_birth=(date_of_birth)
|
84
|
+
|
85
|
+
super(date_of_birth)
|
86
|
+
return unless date_of_birth
|
87
|
+
|
88
|
+
birth_time = Time.parse(date_of_birth)
|
89
|
+
self.age = ((Time.now - birth_time)/1.year).to_i
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
######################################################################
|
94
|
+
##
|
95
|
+
##
|
96
|
+
## AUTOCOMPLETE METHODS.
|
97
|
+
##
|
98
|
+
##
|
99
|
+
######################################################################
|
100
|
+
|
81
101
|
## @param[Hash] options : can contain a :resource key. which should be the resource(user) to which all the personalities belong.
|
82
102
|
module ClassMethods
|
83
103
|
def find_personalities(options)
|