<commit_before>class Admin::OrganizationsController < ApplicationController

  before_filter :login_required

  def index
    redirect_to edit_admin_organization_path(current_user.organization) and return unless current_user.admin?

    organizations = if params[:q]
      q = "%#{params[:q].sanitize_sql!}%"
      Organization.where(["name ilike ? OR description ilike ?", q, q])
    else
      Organization
    end
    @organizations = organizations.order('name asc').paginate :per_page => 20, :order => 'created_at DESC', :page => params[:page]
  end

  def new
    @organization = Organization.new
  end

  def create
    @organization = Organization.new(params[:organization])
    if @organization.save
      flash[:notice] = 'Organization created successfully.'
      redirect_to edit_admin_organization_path(@organization), :flash => {:success => 'Organization has been created successfully'}
    else
      render :action => 'new'
    end
  end

  def specific_information
    @organization = Organization.find(params[:id])
    @site = Site.find(params[:site_id])
    @organization.attributes = @organization.attributes_for_site(@site)
  end

  def edit
    @organization = Organization.find(params[:id])
  end

  def update
    @organization = Organization.find(params[:id])
    if params[:organization][:projects_file].present?
      projects_with_errors = @organization.sync_projects(params[:organization].delete(:projects_file))

      if projects_with_errors.present?
        send_data projects_with_errors,
          :type        => 'application/vnd.ms-excel',
          :disposition => "attachment; filename=#{@organization.name}_projects.xls"
      end<commit_msg>Fixes an error creating organizations in the admin panel<commit_after>class Admin::OrganizationsController < ApplicationController

  before_filter :login_required

  def index
    redirect_to edit_admin_organization_path(current_user.organization) and return unless current_user.admin?

    organizations = if params[:q]
      q = "%#{params[:q].sanitize_sql!}%"
      Organization.where(["name ilike ? OR description ilike ?", q, q])
    else
      Organization
    end
    @organizations = organizations.order('name asc').paginate :per_page => 20, :order => 'created_at DESC', :page => params[:page]
  end

  def new
    @organization = Organization.new
  end

  def create
    @organization = Organization.new(params[:organization])
    @organization.updated_by = current_user
    if @organization.save
      flash[:notice] = 'Organization created successfully.'
      redirect_to edit_admin_organization_path(@organization), :flash => {:success => 'Organization has been created successfully'}
    else
      render :action => 'new'
    end
  end

  def specific_information
    @organization = Organization.find(params[:id])
    @site = Site.find(params[:site_id])
    @organization.attributes = @organization.attributes_for_site(@site)
  end

  def edit
    @organization = Organization.find(params[:id])
  end

  def update
    @organization = Organization.find(params[:id])
    if params[:organization][:projects_file].present?
      projects_with_errors = @organization.sync_projects(params[:organization].delete(:projects_file))

      if projects_with_errors.present?
        send_data projects_with_errors,
          :type        => 'application/vnd.ms-excel',
          :disposition => "attachment; filename=#{@organization.name}_projects.xls"
      end
{'fraction_non_alphanumeric': 0.10995068175224833, 'fraction_numerical': 0.0011604293588627793, 'mean_word_length': 4.033576642335767, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '3624972', 'n_tokens_mistral': 983, 'n_tokens_neox': 929, 'n_words': 211}