Skip to content

Instantly share code, notes, and snippets.

@lawrencecurtis
Created November 17, 2009 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawrencecurtis/236844 to your computer and use it in GitHub Desktop.
Save lawrencecurtis/236844 to your computer and use it in GitHub Desktop.
def prepare(user)
can :manage, :all do |action, object_class, object|
# Check first to see if the object is public
if (object.has_attribute?("public") and object.public)
true
elsif(user.present?)
user.permissions.find_all_by_action(action).any? do |permission|
permission.object_type.constantize == object_class &&
(object.nil? || permission.object_id.nil? || permission.object_id == object.id)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment