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
@@ -7,92 +7,40 @@ module Auth::Concerns::Shopping::ProductConcern
|
|
7
7
|
include Auth::Concerns::EsConcern
|
8
8
|
|
9
9
|
|
10
|
-
|
11
10
|
included do
|
12
|
-
|
13
11
|
|
14
|
-
|
15
12
|
embeds_many :cycles, :class_name => "Auth::Work::Cycle", :as => :product_cycles
|
16
13
|
|
17
14
|
embeds_many :instructions, :class_name => "Auth::Work::Instruction", :as => :product_instructions
|
18
15
|
|
19
|
-
INDEX_DEFINITION =
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
}
|
58
|
-
},
|
59
|
-
mappings: {
|
60
|
-
Auth::OmniAuth::Path.pathify(Auth.configuration.product_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
|
-
bundle_name: {
|
83
|
-
type: "text",
|
84
|
-
copy_to: "_all_fields",
|
85
|
-
fields: {
|
86
|
-
raw: {
|
87
|
-
type: "keyword"
|
88
|
-
}
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
92
|
-
}
|
16
|
+
INDEX_DEFINITION =
|
17
|
+
{
|
18
|
+
index_options:
|
19
|
+
{
|
20
|
+
settings:
|
21
|
+
{
|
22
|
+
index: Auth::Concerns::EsConcern::AUTOCOMPLETE_INDEX_SETTINGS
|
23
|
+
},
|
24
|
+
mappings:
|
25
|
+
{
|
26
|
+
Auth::OmniAuth::Path.pathify(Auth.configuration.product_class) => Auth::Concerns::EsConcern::AUTOCOMPLETE_INDEX_MAPPINGS.deep_merge(
|
27
|
+
{
|
28
|
+
properties: {
|
29
|
+
bundle_name: {
|
30
|
+
type: "text",
|
31
|
+
fields: {
|
32
|
+
raw: {
|
33
|
+
type: "keyword"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
)
|
93
40
|
}
|
94
41
|
}
|
95
|
-
|
42
|
+
}
|
43
|
+
|
96
44
|
#include MongoidVersionedAtomic::VAtomic
|
97
45
|
field :price, type: BigDecimal
|
98
46
|
field :name, type: String
|
@@ -120,133 +68,82 @@ module Auth::Concerns::Shopping::ProductConcern
|
|
120
68
|
##
|
121
69
|
field :bundle_name, type: String
|
122
70
|
|
123
|
-
|
71
|
+
|
124
72
|
before_save do |document|
|
125
73
|
self.public = "yes"
|
126
74
|
end
|
127
75
|
|
128
|
-
## forget it.
|
129
|
-
|
130
76
|
end
|
131
77
|
|
132
|
-
|
133
|
-
|
134
78
|
|
135
79
|
def as_indexed_json(options={})
|
136
|
-
{
|
137
|
-
name: name,
|
138
|
-
bundle_name: bundle_name,
|
139
|
-
price: price,
|
140
|
-
resource_id: resource_id,
|
141
|
-
public: public
|
142
|
-
}
|
80
|
+
super.merge({bundle_name: bundle_name})
|
143
81
|
end
|
82
|
+
|
83
|
+
## so we have completed the rolling n minutes.
|
84
|
+
def add_to_previous_rolling_n_minutes(minutes,origin_epoch,cycle_to_add)
|
144
85
|
|
86
|
+
## get all the minutes less than that.
|
87
|
+
rolling_n_minutes_less_than_that = minutes.keys.select{|c| c < origin_epoch}
|
145
88
|
|
146
|
-
|
147
|
-
|
148
|
-
## @return[SearchResult]
|
149
|
-
def bundle_autocomplete_aggregation(query)
|
150
|
-
query[:body][:aggregations] = {
|
151
|
-
bundle_names: {
|
152
|
-
terms: {
|
153
|
-
field: "bundle_name.raw"
|
154
|
-
}
|
155
|
-
}
|
156
|
-
}
|
157
|
-
|
158
|
-
result = Auth.configuration.product_class.constantize.es.search query
|
159
|
-
|
160
|
-
puts "these are the aggs."
|
161
|
-
puts result.raw_response.to_s
|
162
|
-
#mash = Hashie::Mash.new result
|
163
|
-
#has_more_results = false if mash.aggregations.bundle_names["buckets"].size == 0
|
164
|
-
#mash.aggregations.bundle_names["buckets"].each do |bucket|
|
165
|
-
# puts "this is the bucket: "
|
166
|
-
# puts bucket.to_s
|
167
|
-
#after = bucket["key"]["symptom_thing"]
|
168
|
-
#doc_count = bucket["doc_count"]
|
169
|
-
#create_symptom(after,doc_count)
|
170
|
-
#puts "created #{counter} symptoms"
|
171
|
-
#counter+=1
|
172
|
-
#end
|
173
|
-
=begin
|
174
|
-
mash = Hashie::Mash.new symptom_co_occurrence_query
|
175
|
-
has_more_results = false if mash.aggregations.my_buckets["buckets"].size == 0
|
176
|
-
mash.aggregations.my_buckets["buckets"].each do |bucket|
|
177
|
-
after = bucket["key"]["symptom_thing"]
|
178
|
-
doc_count = bucket["doc_count"]
|
179
|
-
create_symptom(after,doc_count)
|
180
|
-
puts "created #{counter} symptoms"
|
181
|
-
counter+=1
|
182
|
-
end
|
183
|
-
=end
|
184
|
-
end
|
89
|
+
end_min = rolling_n_minutes_less_than_that.size < Auth.configuration.rolling_minutes ? rolling_n_minutes_less_than_that.size : Auth.configuration.rolling_minutes
|
185
90
|
|
186
|
-
|
187
|
-
def add_to_previous_rolling_n_minutes(minutes,origin_epoch,cycle_to_add)
|
91
|
+
end_min = end_min - 1
|
188
92
|
|
189
|
-
|
190
|
-
|
93
|
+
end_min = end_min > 0 ? end_min : 0
|
94
|
+
rolling_n_minutes_less_than_that[0..end_min].each do |epoch|
|
95
|
+
minutes[epoch].cycles << cycle_to_add
|
96
|
+
end
|
191
97
|
|
192
|
-
|
98
|
+
end
|
193
99
|
|
194
|
-
|
100
|
+
## adds the relevant cycles to the minutes, and returns the hash that came in.
|
101
|
+
## does not save the minutes, after adding the cycles to them.
|
102
|
+
##@return[Hash] {epoch => minute object}
|
103
|
+
def schedule_cycles(minutes,location_id,conditions = {})
|
195
104
|
|
196
|
-
|
197
|
-
rolling_n_minutes_less_than_that[0..end_min].each do |epoch|
|
198
|
-
minutes[epoch].cycles << cycle_to_add
|
199
|
-
end
|
105
|
+
products = Auth.configuration.product_class.constantize.all if conditions.blank?
|
200
106
|
|
201
|
-
|
107
|
+
products = Auth.configuration.product_class.constantize.where(conditions) if !conditions.blank?
|
202
108
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
109
|
+
minutes.keys.each do |epoch|
|
110
|
+
|
111
|
+
products.each do |product|
|
112
|
+
|
113
|
+
all_cycles_valid = true
|
114
|
+
product.cycles.each do |cycle|
|
207
115
|
|
208
|
-
|
116
|
+
all_cycles_valid = cycle.requirements_satisfied(epoch + cycle.time_since_prev_cycle.minutes*60,location_id)
|
117
|
+
|
118
|
+
end
|
209
119
|
|
210
|
-
products = Auth.configuration.product_class.constantize.where(conditions) if !conditions.blank?
|
211
120
|
|
212
|
-
|
213
|
-
|
214
|
-
products.each do |product|
|
215
|
-
|
216
|
-
all_cycles_valid = true
|
121
|
+
if all_cycles_valid == true
|
122
|
+
cycle_chain = []
|
217
123
|
product.cycles.each do |cycle|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
124
|
+
epoch_at_which_to_add = epoch + cycle.time_since_prev_cycle.minutes*60
|
125
|
+
cycle_to_add = cycle.dup
|
126
|
+
cycle_to_add.start_time = epoch_at_which_to_add
|
127
|
+
cycle_to_add.end_time = cycle_to_add.start_time + cycle_to_add.duration
|
128
|
+
cycle_to_add.cycle_chain = cycle_chain
|
129
|
+
if minutes[epoch_at_which_to_add]
|
130
|
+
|
131
|
+
#add_to_previous_rolling_n_minutes(minutes,epoch_at_which_to_add,cycle_to_add)
|
222
132
|
|
223
133
|
|
224
|
-
|
225
|
-
cycle_chain = []
|
226
|
-
product.cycles.each do |cycle|
|
227
|
-
epoch_at_which_to_add = epoch + cycle.time_since_prev_cycle.minutes*60
|
228
|
-
cycle_to_add = cycle.dup
|
229
|
-
cycle_to_add.start_time = epoch_at_which_to_add
|
230
|
-
cycle_to_add.end_time = cycle_to_add.start_time + cycle_to_add.duration
|
231
|
-
cycle_to_add.cycle_chain = cycle_chain
|
232
|
-
if minutes[epoch_at_which_to_add]
|
233
|
-
|
234
|
-
#add_to_previous_rolling_n_minutes(minutes,epoch_at_which_to_add,cycle_to_add)
|
134
|
+
minutes[epoch_at_which_to_add].cycles << cycle_to_add
|
235
135
|
|
236
136
|
|
237
|
-
minutes[epoch_at_which_to_add].cycles << cycle_to_add
|
238
137
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
else
|
243
|
-
#raise "necessary minute not in range."
|
244
|
-
end
|
138
|
+
cycle_chain << cycle_to_add.id.to_s
|
139
|
+
else
|
140
|
+
#raise "necessary minute not in range."
|
245
141
|
end
|
246
142
|
end
|
247
143
|
end
|
248
144
|
end
|
249
|
-
minutes
|
250
145
|
end
|
146
|
+
minutes
|
251
147
|
end
|
148
|
+
|
252
149
|
end
|
@@ -11,73 +11,11 @@ module Auth::Concerns::UserConcern
|
|
11
11
|
|
12
12
|
INDEX_DEFINITION = {
|
13
13
|
index_options: {
|
14
|
-
|
15
|
-
index:
|
16
|
-
analysis: {
|
17
|
-
filter: {
|
18
|
-
nGram_filter: {
|
19
|
-
type: "nGram",
|
20
|
-
min_gram: 2,
|
21
|
-
max_gram: 20,
|
22
|
-
token_chars: [
|
23
|
-
"letter",
|
24
|
-
"digit",
|
25
|
-
"punctuation",
|
26
|
-
"symbol"
|
27
|
-
]
|
28
|
-
}
|
29
|
-
},
|
30
|
-
analyzer: {
|
31
|
-
nGram_analyzer: {
|
32
|
-
type: "custom",
|
33
|
-
tokenizer: "whitespace",
|
34
|
-
filter: [
|
35
|
-
"lowercase",
|
36
|
-
"asciifolding",
|
37
|
-
"nGram_filter"
|
38
|
-
]
|
39
|
-
},
|
40
|
-
whitespace_analyzer: {
|
41
|
-
type: "custom",
|
42
|
-
tokenizer: "whitespace",
|
43
|
-
filter: [
|
44
|
-
"lowercase",
|
45
|
-
"asciifolding"
|
46
|
-
]
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}
|
14
|
+
settings: {
|
15
|
+
index: Auth::Concerns::EsConcern::AUTOCOMPLETE_INDEX_SETTINGS
|
51
16
|
},
|
52
17
|
mappings: {
|
53
|
-
Auth::OmniAuth::Path.pathify(Auth.configuration.
|
54
|
-
properties: {
|
55
|
-
_all_fields: {
|
56
|
-
type: "text",
|
57
|
-
analyzer: "nGram_analyzer",
|
58
|
-
search_analyzer: "whitespace_analyzer"
|
59
|
-
},
|
60
|
-
name: {
|
61
|
-
type: "text",
|
62
|
-
copy_to: "_all_fields"
|
63
|
-
},
|
64
|
-
email: {
|
65
|
-
type: "keyword",
|
66
|
-
copy_to: "_all_fields"
|
67
|
-
},
|
68
|
-
additional_login_param: {
|
69
|
-
type: "keyword",
|
70
|
-
copy_to: "_all_fields"
|
71
|
-
},
|
72
|
-
public: {
|
73
|
-
type: "keyword"
|
74
|
-
},
|
75
|
-
resource_id: {
|
76
|
-
type: "keyword",
|
77
|
-
copy_to: "_all_fields"
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|
18
|
+
Auth::OmniAuth::Path.pathify(Auth.configuration.user_class) => Auth::Concerns::EsConcern::AUTOCOMPLETE_INDEX_MAPPINGS
|
81
19
|
}
|
82
20
|
}
|
83
21
|
}
|
@@ -608,6 +546,8 @@ module Auth::Concerns::UserConcern
|
|
608
546
|
## this is needed in
|
609
547
|
def as_json(options={})
|
610
548
|
|
549
|
+
## basically here the problem is that if the user himself is searching for his own record, then it is trying to return the authentication token.
|
550
|
+
##
|
611
551
|
|
612
552
|
json = {:nothing => true}
|
613
553
|
|
@@ -617,7 +557,8 @@ module Auth::Concerns::UserConcern
|
|
617
557
|
|
618
558
|
json = {}
|
619
559
|
json[:es] = self.client_authentication[self.m_client.current_app_id]
|
620
|
-
json[:authentication_token] = self.authentication_token
|
560
|
+
json[:authentication_token] = self. authentication_token
|
561
|
+
|
621
562
|
unless options[:show_id].nil?
|
622
563
|
json[:id] = self.id.to_s
|
623
564
|
json[:admin] = self.admin.to_s
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class Auth::Shopping::BarCode
|
2
|
+
include Mongoid::Document
|
3
|
+
field :resource_id, type: String
|
4
|
+
field :resource_class, type: String
|
5
|
+
field :assigned_to_object_id, type: String
|
6
|
+
field :assigned_to_object_class, type: String
|
7
|
+
field :bar_code_tag, type: String
|
8
|
+
index({ bar_code_tag: 1 }, { unique: true, name: "bar_code_tag_index" })
|
9
|
+
|
10
|
+
## we do this to delet a reference to an object from a bar code.
|
11
|
+
def self.clear_object(bar_code_tag)
|
12
|
+
returned_document = collection.where(:bar_code_tag => bar_code_tag).find_one_and_update(
|
13
|
+
{
|
14
|
+
"$set" => {
|
15
|
+
"resource_id" => nil,
|
16
|
+
"resource_class" => nil,
|
17
|
+
"assigned_to_object_id" => nil,
|
18
|
+
"assigned_to_object_class" => nil
|
19
|
+
}
|
20
|
+
},
|
21
|
+
{
|
22
|
+
:return_document => :after
|
23
|
+
}
|
24
|
+
)
|
25
|
+
true if returned_document.assigned_to_object_id == nil
|
26
|
+
end
|
27
|
+
|
28
|
+
## the object here must be implementing the bar code concern.
|
29
|
+
## what if another bar code has this object on it?
|
30
|
+
## now two barcodes refer to the same object, and we have no way of catching that
|
31
|
+
## so the
|
32
|
+
def self.upsert_and_assign_object(object)
|
33
|
+
returned_document = collection.where(
|
34
|
+
"$or" => [
|
35
|
+
{
|
36
|
+
:bar_code_tag => bar_code_tag
|
37
|
+
},
|
38
|
+
{
|
39
|
+
:assigned_to_object_id => object.id.to_s,
|
40
|
+
:assigned_to_object_class => object.class.name.to_s
|
41
|
+
}
|
42
|
+
]
|
43
|
+
).find_one_and_update(
|
44
|
+
{
|
45
|
+
"setOnInsert" => {
|
46
|
+
"resource_id" => object.resource_id,
|
47
|
+
"resource_class" => object.resource_class,
|
48
|
+
"assigned_to_object_id" => object.id.to_s,
|
49
|
+
"assigned_to_object_class" => object.assigned_to_object_class,
|
50
|
+
"bar_code_tag" => object.bar_code_tag
|
51
|
+
}
|
52
|
+
},
|
53
|
+
{
|
54
|
+
:returned_document => :after,
|
55
|
+
:upsert => true
|
56
|
+
}
|
57
|
+
)
|
58
|
+
|
59
|
+
false unless returned_document
|
60
|
+
|
61
|
+
false if returned_document.assigned_to_object_id != object.id.to_s
|
62
|
+
|
63
|
+
false if returned_document.bar_code_tag != object.bar_code_tag
|
64
|
+
|
65
|
+
## as long as all this is satisfied, it means that there is either already this bar code assigned to this object, or
|
66
|
+
|
67
|
+
true
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|