SHARE
TWEET

Untitled

a guest Apr 26th, 2018 234 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def initialize(user)
  2.     if User.find_by_username "guest" && !user
  3.       user = User.find_by_username "guest"
  4.     else
  5.       user ||= User.create!(:role => "guest", :username => "guest", :email => "seivan@kth.se", :password => "secret", :password_confirmation => "secret")
  6.     end
  7.     if user.role? :admin
  8.       can :manage, :all
  9.     end
  10.    
  11.     if user.role? :moderator
  12.       can :manage, :all
  13.     end
  14.    
  15.     if user.role? :user
  16.       can :read, :all
  17.       can :create, :all
  18.       can :destroy, :all do |all|
  19.         all.try(:user) == user
  20.         3.minutes.ago <= all.created_at
  21.       end
  22.       can :update, :all do |all|
  23.         all.try(:user) == user
  24.         3.minutes.ago <= all.created_at
  25.       end
  26.     end
  27.    
  28.     if user.role? :guest
  29.       can :read, :all
  30.     end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top