Created
November 30, 2011 04:07
-
-
Save kulpae/1407965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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