<commit_before>class Ability

  include CanCan::Ability

  def initialize(user)
    user ||= User.new

    # User
    can [:list, :show],   User
    can [:edit, :update], User, id: user.id

    if user.moderator?
      can [:index, :new, :create], User
    end

    # Group
    can :index, Group
    can :show,  Group
    can [:edit, :update, :destroy], Group do |group|
      user.agroups.include?(group)
    end

    # Meeting
    can [:list, :show], Meeting

    if user.moderator?
      can [:index, :new, :create], Meeting
    end

    can [:edit, :update, :destroy], Meeting do |meeting|
      ans = false
      user.agroups.each do |group|
        if meeting.groups.include?(group)
          ans = true
        end
      end
      ans
    end


    # Payment
    if user.has_role? :finance_manager
      can :manage, Payment
    end


    # MeetingGroups
    can :create, MeetingGroup do |meeting_group|
      can? :edit, meeting_group.meeting
    end

    can :destroy, MeetingGroup do |meeting_group|
      meeting = meeting_group.meeting
      group   = meeting_group.group
      can?(:edit, meeting) && group.admins.include?(user)
    end

    # Admin
    if user.admin?
      can :manage, :all
    end
  end

end
<commit_msg>only allow admins to users#index (too heavy to render)<commit_after>class Ability

  include CanCan::Ability

  def initialize(user)
    user ||= User.new

    # User
    can [:list, :show],   User
    can [:edit, :update], User, id: user.id

    if user.moderator?
      can [:new, :create], User
      can [:edit, :update], User
    end

    # users#index is getting way to heavy. Only admins should access:
    if user.admin?
      can :index, User
    end

    # Group
    can :index, Group
    can :show,  Group
    can [:edit, :update, :destroy], Group do |group|
      user.agroups.include?(group)
    end

    # Meeting
    can [:list, :show], Meeting

    if user.moderator?
      can [:index, :new, :create], Meeting
    end

    can [:edit, :update, :destroy], Meeting do |meeting|
      ans = false
      user.agroups.each do |group|
        if meeting.groups.include?(group)
          ans = true
        end
      end
      ans
    end


    # Payment
    if user.has_role? :finance_manager
      can :manage, Payment
    end


    # MeetingGroups
    can :create, MeetingGroup do |meeting_group|
      can? :edit, meeting_group.meeting
    end

    can :destroy, MeetingGroup do |meeting_group|
      meeting = meeting_group.meeting
      group   = meeting_group.group
      can?(:edit, meeting) && group.admins.include?(user)
    end

    # Admin
    if user.admin?
      can :manage, :all
    end
  end

end

{'fraction_non_alphanumeric': 0.10785419015407742, 'fraction_numerical': 0.0, 'mean_word_length': 2.207228915662651, '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': '7209069', 'n_tokens_mistral': 890, 'n_tokens_neox': 865, 'n_words': 259}