Hi Jakub
Here's the implementation i ended up with. Its not very clean but it
does the job.
[code] def link_to(*args, &block)
unless params[:controller] =~ /admin/
super
else
if args.size > 2
super if action_allowed(args[1], args[2]["method"])
else
super if action_allowed(args[1])
end
end
end
def link_to_remote(name, options = {}, html_options = nil)
unless params[:controller] =~ /admin/
super
else
super if action_allowed(options[:url], options[:method])
end
end
def action_allowed(url, method = :get)
return false unless current_user
path = ActionController::Routing::Routes.recognize_path(url, :method
=> method) rescue nil
return true unless path
return true if current_user.roles.find(:first, :conditions =>
["unrestricted = ?", true])
permissions = Permission.find(:all, :conditions => ["role_id in
(?)", current_user.roles.map(&:id)])
if path[:action] =~ /^\d+$/
perm = permissions.select { |p| p.controller == path[:controller]
&& p.action == path[:id] }.first
else
perm = permissions.select { |p| p.controller == path[:controller]
&& p.action == path[:action] }.first
end
return true if perm
false
end[/code]
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---