<commit_before>require 'cancan'

module Forem
  class Ability
    include CanCan::Ability

    def initialize(user)

      user ||= User.new # anonymous user

      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
<commit_msg>Don't hard-code to User in forem/ability.rb. Fixes #88.<commit_after>require 'cancan'

module Forem
  class Ability
    include CanCan::Ability

    def initialize(user)

      user ||= Forem.user_class.new # anonymous user

      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

{'fraction_non_alphanumeric': 0.09959623149394348, 'fraction_numerical': 0.0013458950201884253, 'mean_word_length': 2.7741116751269037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6408438', 'n_tokens_mistral': 522, 'n_tokens_neox': 505, 'n_words': 109}