lockdown 0.4.3 → 0.4.4

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.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.4.4 2008-05-08
2
+ * Modified: refactored the link_to_secured and authorized? code to be more efficient
3
+
1
4
  == 0.4.3 2008-05-08
2
5
  * Fixed: broken show (and destroy) permission test. also reduced calls to polymorphic path by generating the url once
3
6
 
@@ -104,9 +104,11 @@ module Lockdown
104
104
  return true if current_user_is_admin?
105
105
 
106
106
  # See if path is known
107
- return true if path_allowed?(path)
108
-
109
- return false
107
+ if path_allowed?(path)
108
+ true
109
+ else
110
+ false
111
+ end
110
112
  end
111
113
 
112
114
  # Can log Error => e if desired, I don't desire to now.
@@ -157,33 +159,33 @@ module Lockdown
157
159
  request.request_uri
158
160
  end
159
161
 
160
- def authorized?(options)
162
+ def authorized?(url)
161
163
  return true if current_user_is_admin?
162
164
 
163
- url_parts = URI::split url_for(options)
165
+ url_parts = URI::split(url)
164
166
 
165
167
  path = url_parts[5]
166
168
 
167
169
  # See if path is known
168
170
  return true if path_allowed?(path)
169
171
 
170
- if options.is_a?(String)
171
- # Test for a named routed
172
- begin
173
- hsh = ActionController::Routing::Routes.recognize_path(options)
174
- return true if path_allowed?(path_from_hash(hsh)) unless hsh.nil?
175
- rescue Exception => e
176
- # continue on
177
- end
178
- end
179
-
180
172
  # Test to see if url contains id
181
173
  parts = path.split("/").collect{|p| p unless p =~ /\A\d+\z/}.compact
182
174
  new_path = parts.join("/")
183
175
 
184
176
  return true if path_allowed?(new_path)
185
177
 
186
- return false
178
+ # Test for a named routed
179
+ begin
180
+ hsh = ActionController::Routing::Routes.recognize_path(url)
181
+ unless hsh.nil?
182
+ return true if path_allowed?(path_from_hash(hsh))
183
+ end
184
+ rescue Exception => e
185
+ # continue on
186
+ end
187
+
188
+ false
187
189
  end
188
190
 
189
191
  def access_denied(e)
@@ -2,7 +2,7 @@ module Lockdown #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/lockdown/view.rb CHANGED
@@ -23,7 +23,7 @@ module Lockdown
23
23
  end
24
24
 
25
25
  def link_to_or_show(name, url = '', options = {})
26
- lnk = link_to(name, options, html_options)
26
+ lnk = link_to(name, url , options)
27
27
  lnk.length == 0 ? name : lnk
28
28
  end
29
29
  end # Merb
@@ -39,8 +39,8 @@ module Lockdown
39
39
  end
40
40
 
41
41
  def link_to_secured(name, options = {}, html_options = nil)
42
- # Don't want to go through the polymorphic test twice
43
- url = real_url(options, html_options)
42
+ # Don't want to go through the url_for twice
43
+ url = url_for(options)
44
44
  if authorized? test_path(url, html_options)
45
45
  return link_to_open(name, url, html_options)
46
46
  end
@@ -53,25 +53,17 @@ module Lockdown
53
53
  end
54
54
 
55
55
  def button_to_secured(name, options = {}, html_options = nil)
56
- url = real_url(options, html_options)
57
- if authorized? test_path(url,html_options)
58
- return button_to_open(name,url,html_options)
56
+ url = url_for(options)
57
+ if authorized? test_path(url, html_options)
58
+ return button_to_open(name, url, html_options)
59
59
  end
60
60
  return ""
61
61
  end
62
62
 
63
63
  private
64
64
 
65
- def real_url(options, html_options = {})
66
- unless options.respond_to?(:new_record?)
67
- options
68
- else
69
- polymorphic_path(options)
70
- end
71
- end
72
-
73
65
  def test_path(url, html_options)
74
- if url.split("/").last.to_i > 0
66
+ if url.split("/").last =~ /\A\d+\z/
75
67
  url += "/show"
76
68
  elsif html_options.is_a?(Hash) && html_options[:method] == :delete
77
69
  url += "/destroy"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Stone