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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/auth/auth_modals_and_navbar.js +1 -0
  3. data/app/controllers/auth/concerns/token_concern.rb +9 -10
  4. data/app/controllers/auth/search_controller.rb +25 -23
  5. data/app/models/auth/concerns/chief_model_concern.rb +4 -15
  6. data/app/models/auth/concerns/es_concern.rb +137 -0
  7. data/app/models/auth/concerns/image_load_concern.rb +21 -0
  8. data/app/models/auth/concerns/search/autocompleted_concern.rb +139 -0
  9. data/app/models/auth/concerns/shopping/bar_code_concern.rb +29 -0
  10. data/app/models/auth/concerns/shopping/cart_concern.rb +20 -6
  11. data/app/models/auth/concerns/shopping/cart_item_concern.rb +54 -82
  12. data/app/models/auth/concerns/shopping/personality_concern.rb +75 -55
  13. data/app/models/auth/concerns/shopping/place_concern.rb +1 -3
  14. data/app/models/auth/concerns/shopping/product_concern.rb +71 -174
  15. data/app/models/auth/concerns/user_concern.rb +7 -66
  16. data/app/models/auth/shopping/bar_code.rb +71 -0
  17. data/app/models/auth/shopping/personality.rb +9 -0
  18. data/app/models/auth/work/bullet.rb +3 -1
  19. data/app/models/auth/work/communication.rb +3 -1
  20. data/app/models/auth/work/instruction.rb +2 -1
  21. data/app/models/auth/work/link.rb +3 -1
  22. data/app/views/auth/search/_search_bar.html.erb +12 -7
  23. data/app/views/auth/search/_search_result.html.erb +21 -7
  24. data/app/views/auth/search/authenticated_user_search.js.erb +8 -15
  25. data/app/views/auth/search/authenticated_user_search.json +1 -1
  26. data/app/views/layouts/auth/application.html.erb +1 -1
  27. data/app/views/layouts/auth/navbar/_navbar.html.erb +5 -5
  28. data/config/initializers/omniauth.rb +0 -3
  29. data/lib/assets/javascripts/bar_code.js +97 -0
  30. data/lib/assets/javascripts/search.js +32 -12
  31. data/lib/assets/javascripts/spinner.js +5 -3
  32. data/lib/auth/engine.rb +40 -0
  33. data/lib/auth/rails/routes.rb +2 -0
  34. data/lib/auth/search/main.rb +28 -13
  35. data/lib/auth/version.rb +1 -1
  36. data/lib/wordjelly-auth.rb +2 -1
  37. data/spec/dummy/app/assets/time_hashes.json +1 -1
  38. data/spec/dummy/app/models/shopping/cart.rb +1 -1
  39. data/spec/dummy/app/models/shopping/cart_item.rb +11 -1
  40. data/spec/dummy/app/models/shopping/personality.rb +1 -0
  41. data/spec/dummy/app/models/shopping/place.rb +1 -0
  42. data/spec/dummy/app/models/shopping/product.rb +8 -10
  43. data/spec/dummy/app/models/user.rb +8 -17
  44. data/spec/dummy/config/initializers/preinitializer.rb +0 -1
  45. data/spec/factories/client_factory.rb +2 -0
  46. data/spec/requests/search/search_request_spec.rb +50 -50
  47. data/spec/support/sign_in_support.rb +40 -0
  48. metadata +35 -3
  49. data/app/views/auth/search/_search_results.html.erb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0275837f30cb48e6a6b6909f90df80197f83b386
4
- data.tar.gz: a13e56f04e6bf1083ceb4c960a81825ce7b0148a
3
+ metadata.gz: ed99b909d845c1b58ae7ba9cb2001ff13393c8b2
4
+ data.tar.gz: 79dc45fb85d5c0eb1903551da31bdde8c42cf40d
5
5
  SHA512:
6
- metadata.gz: f8d984f122cf6cec119aa08296ee7361a1fafe4d9067492da3bcf8539b01d8c9f5c6b56405aa091d1d7e0ea59f1caca5effde9390cd942338a68c03b73ad5a57
7
- data.tar.gz: 924471718cb3b23c47cfbb47b82f462cde14da23998503f84a0cb6e60db53bd36b6a8cad1c76bc5f9a0328407b05d9b054ebb292e7eb65951f49649a574a547a
6
+ metadata.gz: 363a176574715a842f40fca2aa57a0f8d9dbec28752ef27e68c73249e547a7153b1877fa055f0f711b2797764909a7a883ef94b887a4d84514e0a2e2f7ab8eb5
7
+ data.tar.gz: 73cfe19dfba421533665e78d4cb503e3cccef9cb8ab701760c63f9b5117dcea5d79ecc5a0f169be7fdce00630ac3be14597edfb7138569ffab995881ff632c0d
@@ -27,6 +27,7 @@ payumoney.js
27
27
  //= require you_need_to_sign_in.js
28
28
  //= require payumoney.js
29
29
  //= require search.js
30
+ //= require bar_code.js
30
31
 
31
32
  /////THIS CODE SHOWS HOW TO OVERRIDE ALL THE CLIENT SIDE CODE NEEDED
32
33
  /////FOR VALIDATIONS TO WORK FOR THE SIGN_IN_FORM.
@@ -33,6 +33,7 @@ module Auth::Concerns::TokenConcern
33
33
 
34
34
 
35
35
  TCONDITIONS = {} unless defined? TCONDITIONS
36
+ LAST_FALLBACK = :devise unless defined? LAST_FALLBACK
36
37
 
37
38
 
38
39
  if Auth.configuration.enable_token_auth
@@ -65,14 +66,14 @@ module Auth::Concerns::TokenConcern
65
66
  ## for the last one, just dont add the fallback as none, other conditions are the same.
66
67
  res = Auth.configuration.auth_resources.keys[-1]
67
68
 
68
- acts_as_token_authentication_handler_for(res.constantize,Auth.configuration.auth_resources[res].merge(self::TCONDITIONS || {}))
69
+ acts_as_token_authentication_handler_for(res.constantize,Auth.configuration.auth_resources[res].merge({:fallback => self::LAST_FALLBACK}).merge(self::TCONDITIONS || {}))
69
70
 
70
71
 
71
72
  else
72
73
  ## in case there is only one authentication resource, then the conditions are like the last one in case there are multiple(like above.)
73
74
  res = Auth.configuration.auth_resources.keys[0]
74
75
 
75
- acts_as_token_authentication_handler_for(res.constantize,Auth.configuration.auth_resources[res].merge(self::TCONDITIONS || {}))
76
+ acts_as_token_authentication_handler_for(res.constantize,Auth.configuration.auth_resources[res].merge({:fallback => self::LAST_FALLBACK}).merge(self::TCONDITIONS || {}))
76
77
 
77
78
  end
78
79
 
@@ -91,32 +92,30 @@ module Auth::Concerns::TokenConcern
91
92
  ## if yes, sets the resource to the first encoutered such key and breaks the iteration
92
93
  ## basically a convenience method to set @resource variable, since when we have more than one model that is being authenticated with Devise, there is no way to know which one to call.
93
94
  def set_resource
94
-
95
+
96
+ puts "came to set resource."
95
97
 
96
98
  Auth.configuration.auth_resources.keys.each do |resource|
97
99
  break if @resource = self.send("current_#{resource.downcase}")
98
100
  end
99
101
 
100
- #puts "do we have a resource"
101
- #puts @resource.to_s
102
-
103
102
  ## devise in registrations_controller#destroy assumes the existence of an 'resource' variable, so we set that here.
104
103
  if devise_controller?
105
104
  self.resource = @resource
106
105
  end
107
106
 
108
-
107
+ puts "resource is: #{@resource.to_s}"
109
108
 
110
109
  end
111
110
 
112
111
 
113
112
 
114
113
  def lookup_resource
115
- puts "came to lookup resource."
114
+ #puts "came to lookup resource."
116
115
  ## if the current signed in resource si not an admin, just return it, because the concept of proxy arises only if the current_signed in resource is an admin.
117
- puts "current signed in resource : #{current_signed_in_resource}"
116
+ #puts "current signed in resource : #{current_signed_in_resource}"
118
117
  return current_signed_in_resource unless current_signed_in_resource.is_admin?
119
- puts "crossed resource."
118
+ #puts "crossed resource."
120
119
  ## else.
121
120
 
122
121
  ## first check the session or the params for a proxy resource.
@@ -4,50 +4,52 @@ class Auth::SearchController < ApplicationController
4
4
  CONDITIONS_FOR_TOKEN_AUTH = [:authenticated_user_search]
5
5
 
6
6
  TCONDITIONS = {:only => CONDITIONS_FOR_TOKEN_AUTH}
7
+ LAST_FALLBACK = :none
7
8
 
8
9
  include Auth::Concerns::DeviseConcern
9
10
  include Auth::Concerns::TokenConcern
10
11
 
11
12
  before_action :do_before_request, TCONDITIONS
12
-
13
-
14
- ## the intention of this action is :
15
- ## to search all records as admin.
16
- ## to search a user's own records if you are user.
17
- ## to search all public records
18
13
 
19
- ## so if the user is an admin, then no resource_id is provided to the search.(basically all records are searched)
20
- ## if he's not an admin, then the lookup_resource user's id is provided.
21
-
22
- ## this action assumes that the user is signed_in, will return not authenticated otherwise.
14
+ ## only option is to set no fallback
15
+ ## so that it will just go through.
23
16
 
24
- ## rendering logic :
17
+
18
+ ## permitted_params[:query] is expected to be a hash, which can provide the following arguments
19
+ ## :query_string => a string for the query
20
+ ## :search_on_field => the field name on which the search can be performed, will default to the 'tags' field.
21
+ ## :size => the number of results to return, will default to 5.
25
22
  ## @js erb -> renders html erb -> there each result class is detected and the requisite "_search.html.erb" partial is found for that class and rendered.
26
23
  ## @json => authenticated_user_search.json is rendered.
27
24
  ## @html => currently does not support html request.
28
25
  def authenticated_user_search
29
-
30
-
31
- ## m client will be available at this stage.
32
- ## the problem is that it is hard to pass it forward to the mongoid elasticsearch object.
33
- ## because while initializing the user it will have to first be set on the user.
34
- ## is there any other way to achieve this?
26
+
27
+ ## remaining implementation is that a default as_json public has to be set to "no" for everything, and overriding it will be the job of the implementer to set it to "yes"
28
+ ## that way a filter is maintained.
29
+
35
30
  query = permitted_params[:query]
36
- query[:resource_id] = lookup_resource.id.to_s if !current_signed_in_resource.is_admin?
37
31
 
32
+ if current_signed_in_resource
33
+ if current_signed_in_resource.is_admin?
34
+ query[:resource_is_admin] = true
35
+ else
36
+ query[:resource_id] = lookup_resource.id.to_s
37
+ end
38
+ end
38
39
 
39
40
  @search_results = Auth::Search::Main.search(query)
40
41
 
41
-
42
- #dummy_product = Auth.configuration.product_class.constantize.new
43
- #dummy_product.name = "test product"
44
- #dummy_product.price = 100.20
45
- #@search_results = [dummy_product,dummy_product]
46
42
  @search_results.each do |res|
47
43
  if res.respond_to? :m_client
48
44
  res.m_client = self.m_client
49
45
  end
50
46
  end
47
+
48
+ puts "these are the search results."
49
+ @search_results.each do |result|
50
+ puts result.to_s
51
+ end
52
+
51
53
  respond_with @search_results
52
54
  end
53
55
 
@@ -10,6 +10,7 @@ module Auth::Concerns::ChiefModelConcern
10
10
  include Mongoid::Document
11
11
  include Mongoid::Timestamps
12
12
  include Mongoid::EmbeddedErrors
13
+ include Auth::Concerns::ImageLoadConcern
13
14
  ## expected to be a hash with names of callbacks and boolean values.
14
15
  ## eg: {:before_save => true, :after_save => false..}
15
16
  ## used in conjunction with the provided skip_callback?(callback_name) method to determine whether to execute the callbacks or not.
@@ -24,15 +25,8 @@ module Auth::Concerns::ChiefModelConcern
24
25
  attr_accessor :embedded_document
25
26
 
26
27
  ## array of image ids, that are associated with the current document.
27
- attr_accessor :images
28
-
29
- field :public, type:String, default: "no"
30
-
31
-
32
- after_initialize do |document|
33
- document.load_images
34
- end
35
-
28
+
29
+ ## moved field public to the es_concern.
36
30
 
37
31
  def field_names_to_skip_while_making_form
38
32
  ["_id","_type.,","resource_id","resource_class","created_at","updated_at","public"]
@@ -43,12 +37,7 @@ module Auth::Concerns::ChiefModelConcern
43
37
  end
44
38
 
45
39
 
46
- ##find an image/ images with this parent id.
47
- ##and add them to an images array.
48
- def load_images
49
- self.images = Auth::Image.where(:parent_id => self.id.to_s) || []
50
- end
51
-
40
+
52
41
 
53
42
  ## returns a list of attributes of tis model other than those mentioned in #FIELD_NAMES_TO_SKIP_WHILE_MAKING_FORM in this concern.
54
43
  ## this is only used in the web api.
@@ -2,9 +2,104 @@ module Auth::Concerns::EsConcern
2
2
 
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ unless Auth::Concerns::EsConcern.included_modules.include? Mongoid::Document
6
+ include Mongoid::Document
7
+ end
8
+
5
9
  included do
6
10
 
11
+ ## the page to which the user will be taken if they click on the suggestion.
12
+ ## REQUIRED
13
+ field :primary_link, type: String
14
+
15
+
16
+ ## key -> display name
17
+ ## value -> hash
18
+ ## value_key -> :url -> the url
19
+ ## value_key -> :data -> hash of optional data-attributes.
20
+ field :secondary_links, type: Hash, default: {}
21
+
22
+
23
+ ## now let us configure that bitch to show this bitch.
24
+ ## REQUIRED
25
+ ## array of tags on which to do the autocomplete
26
+ field :tags, type: Array, default: []
27
+
28
+ ## OPTIONAL
29
+ ## an optional description that will be shown below the result in the autocomplete.
30
+ field :autocomplete_description, type: String
31
+
32
+ AUTOCOMPLETE_INDEX_SETTINGS =
33
+ {
34
+ analysis: {
35
+ filter: {
36
+ nGram_filter: {
37
+ type: "nGram",
38
+ min_gram: 2,
39
+ max_gram: 20,
40
+ token_chars: [
41
+ "letter",
42
+ "digit",
43
+ "punctuation",
44
+ "symbol"
45
+ ]
46
+ }
47
+ },
48
+ analyzer: {
49
+ nGram_analyzer: {
50
+ type: "custom",
51
+ tokenizer: "whitespace",
52
+ filter: [
53
+ "lowercase",
54
+ "asciifolding",
55
+ "nGram_filter"
56
+ ]
57
+ },
58
+ whitespace_analyzer: {
59
+ type: "custom",
60
+ tokenizer: "whitespace",
61
+ filter: [
62
+ "lowercase",
63
+ "asciifolding"
64
+ ]
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ AUTOCOMPLETE_INDEX_MAPPINGS =
71
+ {
72
+ properties: {
73
+ tags: {
74
+ type: "text",
75
+ analyzer: "nGram_analyzer",
76
+ search_analyzer: "whitespace_analyzer"
77
+ },
78
+ public: {
79
+ type: "keyword"
80
+ },
81
+ resource_id: {
82
+ type: "keyword"
83
+ }
84
+ }
85
+ }
86
+
87
+ before_save do |document|
88
+ document.set_primary_link
89
+ document.set_secondary_links
90
+ document.set_autocomplete_description
91
+ document.set_autocomplete_tags
92
+ end
93
+
94
+
95
+
96
+ field :public, type:String, default: "no"
97
+
98
+
7
99
  def self.create_es_index(definition)
100
+ ## check the presence of a resource_id and a resource_class
101
+ #raise "Please define a resource_id field on this model to use it with elasticsearch, this field should be a string" unless self.respond_to? :resource_id
102
+ #raise "Please define a resource_class field on this model as well." unless self.respond_to? :resource_class
8
103
  definition ||= {}
9
104
  if Auth.configuration.use_es == true
10
105
  include Mongoid::Elasticsearch
@@ -12,10 +107,52 @@ module Auth::Concerns::EsConcern
12
107
  definition
13
108
  )
14
109
  end
110
+
15
111
  end
16
112
 
17
113
  end
18
114
 
115
+ def as_indexed_json(options={})
116
+ {
117
+ tags: self.tags,
118
+ public: self.public,
119
+ resource_id: self.resource_id,
120
+ resource_class: self.resource_class
121
+ }
122
+ end
123
+
124
+
125
+ def set_autocomplete_tags
126
+
127
+ end
128
+
129
+ def set_primary_link
130
+
131
+ end
132
+
133
+ def set_secondary_links
19
134
 
135
+ end
136
+
137
+ def set_autocomplete_description
138
+
139
+ end
140
+
141
+ def created_at=(created_at)
142
+
143
+ super(created_at)
144
+
145
+ return unless self.created_at
146
+
147
+ human_readable = self.created_at.strftime("%B %-d %Y")
148
+ self.tags << human_readable unless self.tags.include? human_readable
149
+ end
150
+
151
+ def clear_autocomplete_data
152
+ self.primary_link = nil
153
+ self.secondary_links.clear
154
+ self.autocomplete_description = nil
155
+ self.tags.clear
156
+ end
20
157
 
21
158
  end
@@ -0,0 +1,21 @@
1
+ module Auth::Concerns::ImageLoadConcern
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ attr_accessor :images
8
+
9
+ after_initialize do |document|
10
+ document.load_images
11
+ end
12
+
13
+ ##find an image/ images with this parent id.
14
+ ##and add them to an images array.
15
+ def load_images
16
+ self.images = Auth::Image.where(:parent_id => self.id.to_s) || []
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,139 @@
1
+ module Auth::Concerns::Search::AutocompletedConcern
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ unless Auth::Concerns::Search::AutocompleteConcern.included_modules.include? Mongoid::Document
6
+ include Mongoid::Document
7
+ end
8
+
9
+ unless Auth::Concerns::Search::AutocompleteConcern.included_modules.include? Mongoid::Elasticsearch
10
+ include Mongoid::Elasticsearch
11
+ end
12
+
13
+ included do
14
+
15
+ ## the page to which the user will be taken if they click on the suggestion.
16
+ ## REQUIRED
17
+ field :primary_link, type: String
18
+
19
+ ## key -> display name
20
+ ## value -> hash
21
+ ## value_key -> :url -> the url
22
+ ## value_key -> :data -> hash of optional data-attributes.
23
+ field :secondary_links, type: Hash, default: {}
24
+
25
+
26
+ ## now let us configure that bitch to show this bitch.
27
+ ## REQUIRED
28
+ ## array of tags on which to do the autocomplete
29
+ field :tags, type: Array, default: []
30
+
31
+
32
+ ## the tags that are shown in case the owner of the resource is not viewing the resource
33
+ field :masked_tags, type: Array, default: []
34
+
35
+ ## OPTIONAL
36
+ ## an optional description that will be shown below the result in the autocomplete.
37
+ field :autocomplete_description, type: String
38
+
39
+ AUTOCOMPLETE_INDEX_SETTINGS =
40
+ {
41
+ analysis: {
42
+ filter: {
43
+ nGram_filter: {
44
+ type: "nGram",
45
+ min_gram: 2,
46
+ max_gram: 20,
47
+ token_chars: [
48
+ "letter",
49
+ "digit",
50
+ "punctuation",
51
+ "symbol"
52
+ ]
53
+ }
54
+ },
55
+ analyzer: {
56
+ nGram_analyzer: {
57
+ type: "custom",
58
+ tokenizer: "whitespace",
59
+ filter: [
60
+ "lowercase",
61
+ "asciifolding",
62
+ "nGram_filter"
63
+ ]
64
+ },
65
+ whitespace_analyzer: {
66
+ type: "custom",
67
+ tokenizer: "whitespace",
68
+ filter: [
69
+ "lowercase",
70
+ "asciifolding"
71
+ ]
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ AUTOCOMPLETE_INDEX_MAPPINGS =
78
+ {
79
+ properties: {
80
+ tags: {
81
+ type: "text",
82
+ analyzer: "nGram_analyzer",
83
+ search_analyzer: "whitespace_analyzer"
84
+ },
85
+ public: {
86
+ type: "keyword"
87
+ },
88
+ resource_id: {
89
+ type: "keyword"
90
+ }
91
+ }
92
+ }
93
+
94
+ before_save do |document|
95
+ document.set_primary_link
96
+ document.set_secondary_links
97
+ document.set_autocomplete_description
98
+ document.set_autocomplete_tags
99
+ end
100
+
101
+ end
102
+
103
+ def set_autocomplete_tags
104
+
105
+ end
106
+
107
+ def set_primary_link
108
+
109
+ end
110
+
111
+ def set_secondary_links
112
+
113
+ end
114
+
115
+ def set_autocomplete_description
116
+
117
+ end
118
+
119
+ def created_at=(created_at)
120
+
121
+ super(created_at)
122
+
123
+ return unless self.created_at
124
+
125
+ human_readable = self.created_at.strftime("%B %-d %Y")
126
+ self.tags << human_readable unless self.tags.include? human_readable
127
+ end
128
+
129
+ def clear_autocomplete_data
130
+ self.primary_link = nil
131
+ self.secondary_links.clear
132
+ self.autocomplete_description = nil
133
+ self.tags.clear
134
+ end
135
+
136
+ ## we don't want to index the primary or secondary links
137
+ ## only the tags are considered
138
+
139
+ end