Skip to content

Instantly share code, notes, and snippets.

@kulpae
Created November 30, 2011 04:07
Show Gist options
  • Save kulpae/1407965 to your computer and use it in GitHub Desktop.
Save kulpae/1407965 to your computer and use it in GitHub Desktop.
require 'cancan'
module Forem
class Ability
include CanCan::Ability
def initialize(user)
user ||= Forem.user_class.new # anonymous user
user.class.send :include, Forem::DefaultPermissions
can :read, Forem::Category do |category|
user.can_read_forem_category?(category)
end
if user.can_read_forem_forums?
can :read, Forem::Forum do |forum|
user.can_read_forem_category?(forum.category) && user.can_read_forem_forum?(forum)
end
end
can :create_topic, Forem::Forum do |forum|
can?(:read, forum) && user.can_create_forem_topics?(forum)
end
can :reply, Forem::Topic do |topic|
user.can_reply_to_forem_topic?(topic)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment