<commit_before>ActiveAdmin.register Group do

  controller do
    def collection
      super.includes(:group_request)
    end
  end

  actions :index, :show, :edit
  before_filter :set_pagination
  filter :name 
  filter :payment_plan, as: :select, collection: Group::PAYMENT_PLANS


  scope "Parent groups" do |group|
    group.where(parent_id: nil)
  end

  scope "<5 members" do |group|
    group.where('memberships_count <= ?', 5)
  end

  scope "> 85% full" do |group|
    group.where('max_size > ? AND memberships_count/max_size >= ?', 0, 0.85)
  end


  csv do
    column :id
    column :name
    column :member_email_addresses do |g|
      g.members.map{|m| [m.name, m.email] }.map{|ne| "#{ne[0]} <#{ne[1]}>"}.join(', ')
    end

    column :admin_email_addresses do |g|
      g.admins.map{|m| [m.name, m.email] }.map{|ne| "#{ne[0]} <#{ne[1]}>"}.join(', ')
    end
  end

  index :download_links => false do
    column :id
    column :name
    column :contact do |g|
      admin_name = ERB::Util.h(g.requestor_name)
      admin_email = ERB::Util.h(g.requestor_email)
      simple_format "#{admin_name} \n &lt;#{admin_email}&gt;"
    end

    column "Size", :sortable => :memberships_count do |group|
      if group.max_size
        group_max_size = " (#{group.max_size})"
      else
        group_max_size = ""
      end
      "#{group.memberships_count}"+group_max_size
    end

    column "Discussions", :discussions_count
    column "Motions", :motions_count
    column :created_at
    column :viewable_by
    column :description, :sortable => :description do |group|
      group.description
    end
    column :payment_plan
    default_actions
  end

  show do |group|
    attributes_table do
      row :group_request
      group.attributes.each do |k,v|
        row k.to_sym
      end
    end
    panel("Group Admins") do
        table_for group.admins.each do |admin|
          column :name
          column :email do |user|
            if user.email == group.admin_email
              simple_format "#{mail_to(user.email,user.email)} <<<<< ADMIN_EMAIL"
            else
              mail_to(user.email,user.email)
            end
          end
        end
    end
    active_admin_comments
  end

  form do |f|
    f.inputs "Details" do
      f.input :id, :input_html => { :disabled => true }
      f.input :name, :input_html => { :disabled => true }
      f.input :max_size
      f.input :payment_plan, :as => :select, :collection => Group::PAYMENT_PLANS
    end
    f.buttons
  end

  member_action :update, :method => :put do
    group = Group.find(params[:id])
    group.max_size = params[:group][:max_size]
    if group.save
      redirect_to admin_groups_url, :notice => "Group updated."
    else
      redirect_to admin_groups_url, :notice => "WARNING: Group could not be updated."
    end
  end

  controller do
    def set_pagination
      if params[:pagination].blank?
        @per_page = 40
      elsif params[:pagination] == 'false'
        @per_page = 999999999
      else
        @per_page = params[:pagination]
      end
    end
  end
end
<commit_msg>Fix admin panel bug for group update<commit_after>ActiveAdmin.register Group do

  controller do
    def collection
      super.includes(:group_request)
    end
  end

  actions :index, :show, :edit
  before_filter :set_pagination
  filter :name 
  filter :payment_plan, as: :select, collection: Group::PAYMENT_PLANS


  scope "Parent groups" do |group|
    group.where(parent_id: nil)
  end

  scope "<5 members" do |group|
    group.where('memberships_count <= ?', 5)
  end

  scope "> 85% full" do |group|
    group.where('max_size > ? AND memberships_count/max_size >= ?', 0, 0.85)
  end


  csv do
    column :id
    column :name
    column :member_email_addresses do |g|
      g.members.map{|m| [m.name, m.email] }.map{|ne| "#{ne[0]} <#{ne[1]}>"}.join(', ')
    end

    column :admin_email_addresses do |g|
      g.admins.map{|m| [m.name, m.email] }.map{|ne| "#{ne[0]} <#{ne[1]}>"}.join(', ')
    end
  end

  index :download_links => false do
    column :id
    column :name
    column :contact do |g|
      admin_name = ERB::Util.h(g.requestor_name)
      admin_email = ERB::Util.h(g.requestor_email)
      simple_format "#{admin_name} \n &lt;#{admin_email}&gt;"
    end

    column "Size", :sortable => :memberships_count do |group|
      if group.max_size
        group_max_size = " (#{group.max_size})"
      else
        group_max_size = ""
      end
      "#{group.memberships_count}"+group_max_size
    end

    column "Discussions", :discussions_count
    column "Motions", :motions_count
    column :created_at
    column :viewable_by
    column :description, :sortable => :description do |group|
      group.description
    end
    column :payment_plan
    default_actions
  end

  show do |group|
    attributes_table do
      row :group_request
      group.attributes.each do |k,v|
        row k.to_sym
      end
    end
    panel("Group Admins") do
        table_for group.admins.each do |admin|
          column :name
          column :email do |user|
            if user.email == group.admin_email
              simple_format "#{mail_to(user.email,user.email)}"
            else
              mail_to(user.email,user.email)
            end
          end
        end
    end
    active_admin_comments
  end

  form do |f|
    f.inputs "Details" do
      f.input :id, :input_html => { :disabled => true }
      f.input :name, :input_html => { :disabled => true }
      f.input :max_size
      f.input :payment_plan, :as => :select, :collection => Group::PAYMENT_PLANS
    end
    f.buttons
  end

  member_action :update, :method => :put do
    group = Group.find(params[:id])
    group.update_attributes(params[:group])
    group.max_size = params[:group][:max_size]
    if group.save
      redirect_to admin_groups_url, :notice => "Group updated."
    else
      redirect_to admin_groups_url, :notice => "WARNING: Group could not be updated."
    end
  end

  controller do
    def set_pagination
      if params[:pagination].blank?
        @per_page = 40
      elsif params[:pagination] == 'false'
        @per_page = 999999999
      else
        @per_page = params[:pagination]
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.12087558345404796, 'fraction_numerical': 0.00740383067761146, 'mean_word_length': 2.544780376497433, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '189716', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2058, 'n_words': 514}