hobo 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa3c69c088cf89eb5b2d6b877c17437c026ca795
4
- data.tar.gz: 545a25135cc273cab0b952710559315b9826c380
3
+ metadata.gz: 12fc9a9fb6626d3e125ab54d4357c98f4ffec9b6
4
+ data.tar.gz: bd705d3d658a46e93373599305f85476616911cb
5
5
  SHA512:
6
- metadata.gz: d013a30cde686a23630791d048ba675ff58401791f5d0aedf477d55fc0a5e94f98204b1788173107a9ccd854e587e486495900169da8f6b6a7728801410debd7
7
- data.tar.gz: 8b1430a8ed7eeb40ed5f062a7fd4c89a4be47a7276f7a806befe3bc7fd76c413984eceb81deaca56106aa4b827fec032afc4f5259d5e2ae4b7be053f18c6f792
6
+ metadata.gz: f43ce9b0b3b8f70fa5f702de7b7ad11d0e5b1e347fd49718582ffdd63a23bfe6e1821ca36fd046b43f86850046d17448146fdd62b49bdcb0a376cfcc958172f9
7
+ data.tar.gz: 61186300408c90cc1dbc6c24a0257fd027fd299a424e0ba3a59237d924b6ea282431ae78222be644fec1af91402e60ad73d6f647922e9ea0be0f430166f853a1
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem 'rubydoctest', :git => 'git://github.com/bryanlarsen/rubydoctest.git'
4
- gem 'rails', '3.2.12'
4
+ gem 'rails', '4.0.8'
5
+ gem 'protected_attributes'
5
6
  gemspec :path => "../dryml"
6
7
  gemspec :path => "../hobo_support"
7
8
  gemspec :path => "../hobo_fields"
@@ -13,3 +14,5 @@ end
13
14
  platform :jruby do
14
15
  gem 'activerecord-jdbcsqlite3-adapter'
15
16
  end
17
+
18
+ gem "irt"
data/Rakefile CHANGED
@@ -4,6 +4,10 @@ require 'rake/testtask'
4
4
  require 'tmpdir'
5
5
 
6
6
  require 'active_record'
7
+ require 'action_view'
8
+ require 'action_controller'
9
+ require 'action_mailer'
10
+
7
11
  ActiveRecord::ActiveRecordError # hack for https://rails.lighthouseapp.com/projects/8994/tickets/2577-when-using-activerecordassociations-outside-of-rails-a-nameerror-is-thrown
8
12
  $:.unshift File.expand_path('../lib', __FILE__)
9
13
  $:.unshift File.expand_path('../../hobo_support/lib', __FILE__)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.1.2
@@ -21,13 +21,20 @@ module HoboPermissionsHelper
21
21
  object = object.new
22
22
  elsif (refl = object.try.proxy_association._?.reflection) && refl.macro == :has_many
23
23
  if Hobo.simple_has_many_association?(object)
24
- object = object.build
25
- object.set_creator(current_user)
24
+ new_object = object.build
25
+ new_object.set_creator(current_user)
26
26
  else
27
27
  return false
28
28
  end
29
29
  end
30
- object.creatable_by?(current_user)
30
+ # When running `can_create?(@something.children)`, a new object is instantiated to check if we can create
31
+ # After the check we need to remove it from memory
32
+ if new_object
33
+ new_object.creatable_by?(current_user)
34
+ object.delete(new_object)
35
+ else
36
+ object.creatable_by?(current_user)
37
+ end
31
38
  end
32
39
 
33
40
 
@@ -16,9 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.add_runtime_dependency('dryml', ["= #{version}"])
17
17
  s.add_runtime_dependency('hobo_will_paginate')
18
18
 
19
- s.add_development_dependency('rubydoctest', [">= 1.1.3"])
19
+ # s.add_development_dependency('rubydoctest', [">= 1.1.3"])
20
20
  s.add_development_dependency('shoulda', [">= 0"])
21
- s.add_development_dependency('irt', ["= 1.2.11"])
21
+ s.add_development_dependency('irt', ["= 1.3.2"])
22
22
  s.add_development_dependency('mocha')
23
23
  s.add_development_dependency('yard')
24
24
 
@@ -134,6 +134,7 @@ en:
134
134
  you_signed_up: "You have signed up"
135
135
  none: "No %{model} available."
136
136
  confirm: "Are you sure?"
137
+ confirm_delete: "Are you sure that you want to delete #{name}?"
137
138
 
138
139
  # default hobo collection translation
139
140
  collection:
@@ -109,7 +109,7 @@ NOTE: You might want to sign up as the administrator before adding this!
109
109
  @invite_only = invite_only?
110
110
  private_site = options[:private_site]
111
111
  end
112
- inject_into_file 'app/controllers/application_controller.rb', <<EOI, :after => "protect_from_forgery\n" if private_site
112
+ inject_into_file 'app/controllers/application_controller.rb', <<EOI, :after => "protect_from_forgery with: :exception\n" if private_site
113
113
  include Hobo::Controller::AuthenticationSupport
114
114
  before_filter :except => [:login, :forgot_password, :accept_invitation, :do_accept_invitation, :reset_password,
115
115
  :do_reset_password] do
@@ -2,6 +2,11 @@
2
2
  hobo_user_model # Don't put anything above this
3
3
 
4
4
  fields do
5
+
6
+ # NOTE: If you add fields here, you may need to include them in both the attr_accessible list, and
7
+ # the list of fields passed to 'only_changed?' in the update_permitted? method for them to appear
8
+ # on the user#edit form.
9
+
5
10
  name :string, :required, :unique
6
11
  email_address :email_address, :login => true
7
12
  administrator :boolean, :default => false
@@ -335,7 +335,7 @@ module Hobo
335
335
 
336
336
 
337
337
  def parse_sort_param(*args)
338
- _, desc, field = *params[:sort]._?.match(/^(-)?([a-z_]+(?:\.[a-z_]+)?)$/)
338
+ _, desc, field = *params[:sort]._?.match(/^(-)?([a-z0-9_]+(?:\.[a-z0-9_]+)?)$/)
339
339
 
340
340
  if field
341
341
  hash = args.extract_options!
@@ -103,13 +103,21 @@ ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
103
103
 
104
104
  # TODO - add dependent option support
105
105
  def delete_records_with_hobo_permission_check(records, method)
106
- klass = @reflection.through_reflection.klass
107
106
  user = acting_user
107
+
108
+ problem_joiner=nil
109
+ association = self.respond_to?(:proxy_association) ? proxy_association : self
110
+ through_assoc_name = association.send(:through_reflection).name
108
111
  if user && records.any? { |r|
109
- joiner = klass.where(construct_join_attributes(r)).first
112
+ ja = construct_join_attributes(r)
113
+ problem_joiner = joiner = association.owner.send(through_assoc_name).where(ja).first
110
114
  joiner.is_a?(Hobo::Model) && !joiner.destroyable_by?(user)
111
115
  }
112
- raise Hobo::PermissionDeniedError, "#{@owner.class}##{proxy_association.reflection.name}.destroy"
116
+ message = "#{@owner.class}##{association.reflection.name}.destroy "
117
+ if 'development' == Rails.env
118
+ message += " because of #{problem_joiner.class.name}(#{problem_joiner.to_json})"
119
+ end
120
+ raise Hobo::PermissionDeniedError, message
113
121
  end
114
122
  delete_records_without_hobo_permission_check(records, method)
115
123
  end
@@ -132,13 +132,29 @@ module Hobo
132
132
  names += public_instance_methods.*.to_s
133
133
  end
134
134
 
135
- def belongs_to_with_creator_metadata(name, options={}, &block)
135
+ def belongs_to_with_creator_metadata(name, *args, &block)
136
+ if args.size == 0 || (args.size == 1 && args[0].kind_of?(Proc))
137
+ options = {}
138
+ args.push(options)
139
+ elsif args.size == 1
140
+ options = args[0]
141
+ else
142
+ options = args[1]
143
+ end
136
144
  self.creator_attribute = name.to_sym if options.delete(:creator)
137
- belongs_to_without_creator_metadata(name, options, &block)
145
+ belongs_to_without_creator_metadata(name, *args, &block)
138
146
  end
139
147
 
140
- def belongs_to_with_test_methods(name, options={}, &block)
141
- belongs_to_without_test_methods(name, options, &block)
148
+ def belongs_to_with_test_methods(name, *args, &block)
149
+ if args.size == 0 || (args.size == 1 && args[0].kind_of?(Proc))
150
+ options = {}
151
+ args.push(options)
152
+ elsif args.size == 1
153
+ options = args[0]
154
+ else
155
+ options = args[1]
156
+ end
157
+ belongs_to_without_test_methods(name, *args, &block)
142
158
  refl = reflections[name]
143
159
  id_method = refl.options[:primary_key] || refl.klass.primary_key
144
160
  if options[:polymorphic]
@@ -103,21 +103,20 @@ module Hobo
103
103
 
104
104
  # --- has_many mass assignment support --- #
105
105
 
106
- def self.has_many_with_accessible(name, received_scope=nil, options={}, &block)
106
+ def self.has_many_with_accessible(name, *args, &block)
107
107
  # Rails 4 supports a lambda as the second argument in a has_many association
108
108
  # We need to support it too (required for gems like papertrail)
109
109
  # The problem is that when it is not used, the options hash is taken as the scope
110
110
  # To fix this, we make a small hack checking the second argument's class
111
- if received_scope.is_a?(Proc)
112
- has_many_without_accessible(name, received_scope, options, &block)
113
- else
114
- if received_scope == nil
111
+ if args.size == 0 || (args.size == 1 && args[0].kind_of?(Proc))
115
112
  options = {}
116
- else
117
- options = received_scope
118
- end
119
- has_many_without_accessible(name, options, &block)
113
+ args.push(options)
114
+ elsif args.size == 1
115
+ options = args[0]
116
+ else
117
+ options = args[1]
120
118
  end
119
+ has_many_without_accessible(name, *args, &block)
121
120
  # End of the received_scope hack
122
121
 
123
122
  if options[:accessible]
@@ -138,8 +137,16 @@ module Hobo
138
137
 
139
138
  # --- belongs_to assignment support --- #
140
139
 
141
- def self.belongs_to_with_accessible(name, options={}, &block)
142
- belongs_to_without_accessible(name, options, &block)
140
+ def self.belongs_to_with_accessible(name,*args, &block)
141
+ if args.size == 0 || (args.size == 1 && args[0].kind_of?(Proc))
142
+ options = {}
143
+ args.push(options)
144
+ elsif args.size == 1
145
+ options = args[0]
146
+ else
147
+ options = args[1]
148
+ end
149
+ belongs_to_without_accessible(name,*args, &block)
143
150
 
144
151
  if options[:accessible]
145
152
  class_eval %{
@@ -48,6 +48,7 @@ module Hobo
48
48
 
49
49
  def run!(user, attributes)
50
50
  record = lifecycle.model.new
51
+ record.set_creator user
51
52
  record.lifecycle.active_step = self
52
53
  record.with_acting_user(user) do
53
54
  prepare!(record, attributes)
@@ -79,8 +79,8 @@ module Hobo
79
79
  # ensure active_user gets passed down to :dependent => destroy
80
80
  # associations (Ticket #528)
81
81
 
82
- def has_many_with_hobo_permission_check(association_id, scope=nil, options = {}, &extension)
83
- has_many_without_hobo_permission_check(association_id, scope, options, &extension)
82
+ def has_many_with_hobo_permission_check(association_id, *args, &extension)
83
+ has_many_without_hobo_permission_check(association_id, *args, &extension)
84
84
  reflection = reflections[association_id]
85
85
  if reflection.options[:dependent]==:destroy
86
86
  #overriding dynamic method created in ActiveRecord::Associations#configure_dependency_for_has_many
@@ -91,8 +91,8 @@ module Hobo
91
91
  end
92
92
  end
93
93
 
94
- def has_one_with_hobo_permission_check(association_id, scope=nil, options = {}, &extension)
95
- has_one_without_hobo_permission_check(association_id, scope, options, &extension)
94
+ def has_one_with_hobo_permission_check(association_id, *args, &extension)
95
+ has_one_without_hobo_permission_check(association_id, *args, &extension)
96
96
  reflection = reflections[association_id]
97
97
  if reflection.options[:dependent]==:destroy
98
98
  #overriding dynamic method created in ActiveRecord::Associations#configure_dependency_for_has_one
@@ -106,8 +106,8 @@ module Hobo
106
106
  end
107
107
  end
108
108
 
109
- def belongs_to_with_hobo_permission_check(association_id, scope=nil, options = {}, &extension)
110
- belongs_to_without_hobo_permission_check(association_id, scope, options, &extension)
109
+ def belongs_to_with_hobo_permission_check(association_id, *args, &extension)
110
+ belongs_to_without_hobo_permission_check(association_id, *args, &extension)
111
111
  reflection = reflections[association_id]
112
112
  if reflection.options[:dependent]==:destroy
113
113
  #overriding dynamic method created in ActiveRecord::Associations#configure_dependency_for_belongs_to
@@ -7,9 +7,9 @@ module Hobo
7
7
  result = self
8
8
  scopes.each_pair do |scope, arg|
9
9
  if arg.is_a?(Array)
10
- result = self.send(scope, *arg) unless arg.first.blank?
10
+ result = result.send(scope, *arg) unless arg.first.blank?
11
11
  else
12
- result = self.send(scope, arg) unless arg.blank?
12
+ result = result.send(scope, arg) unless arg.blank?
13
13
  end
14
14
  end
15
15
  result
@@ -322,13 +322,18 @@ module Hobo
322
322
  return true if check_only
323
323
 
324
324
  def_scope do |query, *fields|
325
- match_keyword = %w(PostgreSQL PostGIS).include?(::ActiveRecord::Base.connection.adapter_name) ? "ILIKE" : "LIKE"
326
-
325
+ using_postgresql = %w(PostgreSQL PostGIS).include?(::ActiveRecord::Base.connection.adapter_name)
326
+ match_keyword = using_postgresql ? "ILIKE" : "LIKE"
327
327
  words = (query || "").split
328
328
  args = []
329
329
  word_queries = words.map do |word|
330
330
  field_query = '(' + fields.map { |field|
331
- field = "#{@klass.table_name}.#{field}" unless field =~ /\./
331
+ if using_postgresql
332
+ casted_field = "CAST(#{@klass.table_name}.#{field} AS TEXT)"
333
+ else
334
+ casted_field = "#{@klass.table_name}.#{field}"
335
+ end
336
+ field = "#{casted_field}" unless field =~ /\./
332
337
  "(#{field} #{match_keyword} ?)"
333
338
  }.join(" OR ") + ')'
334
339
  args += ["%#{word}%"] * fields.length
@@ -42,7 +42,7 @@ module Hobo
42
42
  # https://hobo.lighthouseapp.com/projects/8324-hobo/tickets/530
43
43
  attr_accessor :current_password, :password, :password_confirmation, :type => :password
44
44
 
45
- before_save :encrypt_password
45
+ before_save :encrypt_password, :downcase_email
46
46
  after_save :stash_current_password
47
47
 
48
48
  never_show *AUTHENTICATION_FIELDS
@@ -75,6 +75,9 @@ module Hobo
75
75
 
76
76
  # Authenticates a user by their login name and unencrypted password. Returns the user or nil.
77
77
  def authenticate(login, password)
78
+ # Downcase emails before logging in
79
+ login = login.downcase if attr_type(@login_attribute) == HoboFields::Types::EmailAddress
80
+
78
81
  u = where("#{@login_attribute} = ?", login).first # need to get the salt
79
82
 
80
83
  if u && u.authenticated?(password)
@@ -179,6 +182,13 @@ module Hobo
179
182
  if changing_password? && !authenticated?(current_password)
180
183
  end
181
184
 
185
+ # Downcase emails used for logging in before saving them to the database
186
+ def downcase_email
187
+ if self.login.class == HoboFields::Types::EmailAddress
188
+ self.login = self.login.downcase
189
+ end
190
+ end
191
+
182
192
  end
183
193
  end
184
194
  end
@@ -18,6 +18,7 @@ test_value_eql? true
18
18
 
19
19
  desc "Routes added"
20
20
  file_include? 'config/routes.rb',
21
- %(match 'search' => 'front#search', :as => 'site_search'),
21
+ %(post 'search' => 'front#search', :as => 'site_search_post'),
22
+ %(get 'search' => 'front#search', :as => 'site_search'),
22
23
  %(root :to => 'front#index')
23
24
  test_value_eql? true
@@ -24,7 +24,7 @@ file_include? 'config/application.rb',
24
24
  test_value_eql? true
25
25
 
26
26
  desc "shoulda Gemfile injection"
27
- file_include? 'Gemfile', %(gem "shoulda", :group => :test)
27
+ file_include? 'Gemfile', %(gem "shoulda", group: :test)
28
28
  test_value_eql? true
29
29
 
30
30
  git_reset_app
@@ -38,7 +38,7 @@ file_include? 'config/application.rb',
38
38
  test_value_eql? true
39
39
 
40
40
  desc "rspec Gemfile injection"
41
- file_include? 'Gemfile', %(gem "rspec-rails", ">= 2.5.0", :group => [:test, :development])
41
+ file_include? 'Gemfile', %(gem "rspec-rails", ">= 2.5.0", group: [:test, :development])
42
42
  test_value_eql? true
43
43
 
44
44
  git_reset_app
@@ -52,8 +52,8 @@ file_include? 'config/application.rb',
52
52
  test_value_eql? true
53
53
 
54
54
  desc "rspec_with_shoulda Gemfile injection"
55
- file_include? 'Gemfile', %(gem "rspec-rails", ">= 2.5.0", :group => [:test, :development]),
56
- %(gem "shoulda", :group => :test)
55
+ file_include? 'Gemfile', %(gem "rspec-rails", ">= 2.5.0", group: [:test, :development]),
56
+ %(gem "shoulda", group: :test)
57
57
  test_value_eql? true
58
58
 
59
59
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Locke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2015-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hobo_support
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.1
19
+ version: 2.1.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.1
26
+ version: 2.1.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hobo_fields
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 2.1.1
33
+ version: 2.1.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 2.1.1
40
+ version: 2.1.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dryml
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 2.1.1
47
+ version: 2.1.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 2.1.1
54
+ version: 2.1.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: hobo_will_paginate
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubydoctest
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: 1.1.3
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 1.1.3
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: shoulda
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +86,14 @@ dependencies:
100
86
  requirements:
101
87
  - - '='
102
88
  - !ruby/object:Gem::Version
103
- version: 1.2.11
89
+ version: 1.3.2
104
90
  type: :development
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - '='
109
95
  - !ruby/object:Gem::Version
110
- version: 1.2.11
96
+ version: 1.3.2
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: mocha
113
99
  requirement: !ruby/object:Gem::Requirement