authorization and rails 2.2?

1 view
Skip to first unread message

Tom Wood

unread,
Dec 3, 2008, 11:08:41 PM12/3/08
to Rails Authorization Plugin
Hi ... has anyone tried the authorization plugin with the new Rails
2.2 release?

Kieran

unread,
Dec 24, 2008, 4:37:45 AM12/24/08
to Rails Authorization Plugin
Hey Tom,

I've just been working with the authorization code and tests on Rails
2.2, and I've had no issues apart from a config change needed in the
test repo (doesn't affect the plugin itself)

Regards
Kieran

Synth

unread,
Jan 24, 2009, 8:10:09 PM1/24/09
to Rails Authorization Plugin
There indeed is an issue. It has to do with trying to call any
methods provided by the Identity module on an association. In
Rails2.2 they enforce visibility(public/private) on association_proxy
proxy_target's. What this does is prevent the method_missing(if
implemented) from being called on the proxy_target. The workaround(or
solution, whichever), according to Michael Koziarski in this ticket:

http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1083-calls-to-private-methods-via-association-proxies-should-act-consistently-with-ruby-method-dispatch#ticket-1083-22

is that if you implement method_missing, you should implement
respond_to? as well. I kind of agree with this, but it should be
advertised better in the association_proxy documentation.

If anyone has trouble, stick the code at the bottom in identity.rb
after method_missing. I don't have the time right now to get gel'in
with github, otherwise I'd commit it myself. Hopefully, someone else
can take the lead though.


def respond_to?(method_name)
method_name = method_name.to_s

base_regex = "is_(\\w+)"
fancy_regex = base_regex + "_(#
{Authorization::Base::VALID_PREPOSITIONS_PATTERN})"
is_either_regex = '^((' + fancy_regex + ')|(' + base_regex +
'))'
base_not_regex = "is_no[t]?_(\\w+)"
fancy_not_regex = base_not_regex + "_(#
{Authorization::Base::VALID_PREPOSITIONS_PATTERN})"
is_not_either_regex = '^((' + fancy_not_regex + ')|(' +
base_not_regex + '))'

if method_name =~ Regexp.new(is_either_regex + '_what$')
return true
elsif method_name =~ Regexp.new(is_not_either_regex + '\?$')
return true
elsif method_name =~ Regexp.new(is_either_regex + '\?$')
return true
elsif method_name =~ Regexp.new(is_not_either_regex + '$')
return true
elsif method_name =~ Regexp.new(is_either_regex + '$')
return true
else
return super
end
end
Reply all
Reply to author
Forward
0 new messages