No PhD

I work for Nature Publishing, but I haven't got a PhD

Authoritah update

leave a comment »

I’ve pushed a couple of changes to my Authoritah gem recently that hope to make it a bit more useful. Firstly I’ve fixed using Procs that access the controller for testing whether an action is permitted or not:

class WidgetController < ApplicationController
  forbids :current_user => Proc.new {|user| user.id == params[:id }
end

This now works as expected.

I have also added the ability to change the outcome of an authorisation failure rather than always returning a 404. You can now use the on_reject option to customise the behaviour, as follows:

  
class WidgetController < ApplicationController
    permits :current_user => :logged_in?, :on_reject => :redirect_to_login
    forbids :current_user => :blacklisted?,
            :from => [:create, :destroy],
            :on_reject => Proc.new { redirect_to '/blacklisted' }

    def redirect_to_login
      flash[:notice] = "Please login to view widgets"
      redirect_to root_url
    end
  end

I hope these changes prove useful.

Advertisements

Written by spanx

18th November, 2009 at 1:45 pm

Posted in Code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: