<commit_before>class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new # guest user (not logged in)

    if user.has_role? :admin
      can :manage, :all
    end

    if user.id
      # TODO: Should all logged in users be able to view editorial pages?
      can :view, :editorial_page
      can :manage, Node, :section => {:id => Section.with_role(:author, user).pluck(:id)}, :state => :draft
      can :read, Node, :section => {:id => Section.with_role(:reviewer, user).pluck(:id)}, :state => :draft
      can :create_in, Section, :id => Section.with_role(:author, user).pluck(:id)
    end

    # Everyone (signed in or not) can view published pages.
    can :read, Node, :state => :published
  end
end<commit_msg>Update ability checks to use blocks<commit_after>class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new # guest user (not logged in)

    if user.has_role? :admin
      can :manage, :all
    end

    if user.id
      # TODO: Should all logged in users be able to view editorial pages?
      can :view, :editorial_page
      can :manage, Node do |node|
        node.state == :draft && user.has_role?(:author, node.section)
      end
      can :read, Node do |node|
        node.state == :draft && user.has_role?(:reviewer, node.section)
      end
      can :create_in, Section do |section|
        user.has_role?(:author, section)
      end
    end

    # Everyone (signed in or not) can view published pages.
    can :read, Node, :state => :published
  end
end
{'fraction_non_alphanumeric': 0.12044270833333333, 'fraction_numerical': 0.0, 'mean_word_length': 2.8813131313131315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '1738471', 'n_tokens_mistral': 487, 'n_tokens_neox': 472, 'n_words': 164}