<commit_before>class Ability
  include CanCan::Ability

  def initialize(user)

    user ||= User.new # anonymous visitor
    
    # roles per messageboard
    # superadmin  - can do anything across the site
    # admin       - a moderator that can do anything for a given messageboard
    # moderator   - member that can create/update categories. can post on some/all of the messageboards
    # member      - user that's participating in a given messageboard
    # logged_in   - herp
    # anonymous   - derp
    
    if user.superadmin?
      can :manage, :all
    end
    
    can :read, Messageboard do |messageboard|
      (messageboard.restricted_to_private?    && user.member_of?(messageboard)) ||
      (messageboard.restricted_to_logged_in?  && user.valid?) ||
      messageboard.public?
    end
    
    can :read, Topic do |topic|
      topic.messageboard.public? && topic.public? ||
      topic.messageboard.public? && topic.private? && topic.users.include?(user) ||
      topic.messageboard.restricted_to_logged_in? && user.logged_in? && topic.public? ||
      topic.messageboard.restricted_to_logged_in? && user.logged_in? && topic.private? && topic.users.include?(user) ||
      topic.messageboard.restricted_to_private? && user.member_of?(topic.messageboard) && topic.public? ||
      topic.messageboard.restricted_to_private? && user.member_of?(topic.messageboard) && topic.private? && topic.users.include?(user) 
    end

    can :create, Topic do |topic|
      (topic.messageboard.restricted_to_private?    && user.member_of?(topic.messageboard)) ||
      (topic.messageboard.restricted_to_logged_in?  && user.valid?) ||
      topic.messageboard.public?
    end

    can :manage, Topic do |topic|
      user.admins?(topic.messageboard) ||
      topic.user == user.name
    end
    
    can :manage, Post do |post|
      user.admins?(post.topic.messageboard) || post.user == user.name
    end
    

    # if messageboard is private
    #   - members can read topics listing
    #
    # if messageboard is logged_in
    #   - logged_in can read
    #
    # if messageboard is public
    #   - anonymous can read
    
    # if posting permission is members
    #   - members can post
    #
    # if posting permission is logged_in
    #   - logged in can post
    #
    # if posting permission is anonymous
    #   - anonymous can post


  end
end
<commit_msg>setting access to the Site model via CanCan abilities file<commit_after>class Ability
  include CanCan::Ability

  def initialize(user)

    user ||= User.new # anonymous visitor
    
    # roles per messageboard
    # superadmin  - can do anything across the site
    # admin       - a moderator that can do anything for a given messageboard
    # moderator   - member that can create/update categories. can post on some/all of the messageboards
    # member      - user that's participating in a given messageboard
    # logged_in   - herp
    # anonymous   - derp
    
    if user.superadmin?
      can :manage, :all
    end
    
    can :read, Site do |site|
      user.valid? || site.permission == "public"
    end

    can :read, Messageboard do |messageboard|
      (messageboard.restricted_to_private?    && user.member_of?(messageboard)) ||
      (messageboard.restricted_to_logged_in?  && user.valid?) ||
      messageboard.public?
    end
    
    can :read, Topic do |topic|
      topic.messageboard.public? && topic.public? ||
      topic.messageboard.public? && topic.private? && topic.users.include?(user) ||
      topic.messageboard.restricted_to_logged_in? && user.logged_in? && topic.public? ||
      topic.messageboard.restricted_to_logged_in? && user.logged_in? && topic.private? && topic.users.include?(user) ||
      topic.messageboard.restricted_to_private? && user.member_of?(topic.messageboard) && topic.public? ||
      topic.messageboard.restricted_to_private? && user.member_of?(topic.messageboard) && topic.private? && topic.users.include?(user) 
    end

    can :create, Topic do |topic|
      (topic.messageboard.restricted_to_private?    && user.member_of?(topic.messageboard)) ||
      (topic.messageboard.restricted_to_logged_in?  && user.valid?) ||
      topic.messageboard.public?
    end

    can :manage, Topic do |topic|
      user.admins?(topic.messageboard) ||
      topic.user == user.name
    end
    
    can :manage, Post do |post|
      user.admins?(post.topic.messageboard) || post.user == user.name
    end
    

    # if messageboard is private
    #   - members can read topics listing
    #
    # if messageboard is logged_in
    #   - logged_in can read
    #
    # if messageboard is public
    #   - anonymous can read
    
    # if posting permission is members
    #   - members can post
    #
    # if posting permission is logged_in
    #   - logged in can post
    #
    # if posting permission is anonymous
    #   - anonymous can post


  end
end

{'fraction_non_alphanumeric': 0.10337768679631525, 'fraction_numerical': 0.0, 'mean_word_length': 2.7015151515151516, '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': '195830', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1452, 'n_words': 372}