<commit_before>require 'csv'

class RolesController < EventBaseController
  respond_to :html, :json, :csv
  skip_before_filter :show_join_prompt, :only => [:registration_form, :register, :join, :create_from_current_user]

  # GET /events/1/hosts
  # GET /events/1/visitors
  def index
    if params[:format] == 'csv'
      headers.merge!({
        'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
        'Content-Type' => 'text/csv',
        'Content-Disposition' => "attachment; filename=\"data.csv\"",
        'Content-Transfer-Encoding' => 'binary'
      })
      @column_names = get_csv_column_names
    end
    if params[:id].blank?
      @roles = get_roles
    else
      @roles = [get_role]
    end
    respond_with @event, @roles
  end

  # GET /events/1/hosts/1
  # GET /events/1/visitors/1
  def show
    @role = get_role
    respond_with @event, @role
  end

  # GET /events/1/hosts/new
  # GET /events/1/visitors/new
  def new
    @people = Person.all
    @role = get_role
    respond_with @event, @role
  end

  # GET /events/1/hosts/registration_form
  # GET /events/1/visitors/registration_form
  def registration_form
    redirect_to join_event_url(@event) unless @current_user.new_record?
    @role = get_role(:person => @current_user)
  end

  # GET /events/1/hosts/join
  # GET /events/1/visitors/join
  def join
  end

  # GET /events/1/hosts/1/edit
  # GET /events/1/visitors/1/edit
  def edit
    @role = get_role
    respond_with @event, @role
  end

  # GET /events/1/hosts/1/delete
  # GET /events/1/visitors/1/delete
  def delete
    @role = get_role
    respond_with @event, @role
  end

  # POST /events/1/hosts
  # POST /events/1/visitors
  def create
    @role = get_role
    flash[:notice] = t('create.success', :scope => get_i18n_scope) if @role.save and not request.xhr?
    respond_with @event, @role, :location => {:action => 'index'}
  end

  # POST /events/1/register
  # POST /events/1/register
  def register
    @role = get_role
    @role.person.ldap_id = session[:cas_user]
    if @event.id == 4
      if @role.location_id.blank?<commit_msg>Prevent joining an event if the user has already joined.<commit_after>require 'csv'

class RolesController < EventBaseController
  respond_to :html, :json, :csv
  skip_before_filter :show_join_prompt, :only => [:registration_form, :register, :join, :create_from_current_user]

  # GET /events/1/hosts
  # GET /events/1/visitors
  def index
    if params[:format] == 'csv'
      headers.merge!({
        'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
        'Content-Type' => 'text/csv',
        'Content-Disposition' => "attachment; filename=\"data.csv\"",
        'Content-Transfer-Encoding' => 'binary'
      })
      @column_names = get_csv_column_names
    end
    if params[:id].blank?
      @roles = get_roles
    else
      @roles = [get_role]
    end
    respond_with @event, @roles
  end

  # GET /events/1/hosts/1
  # GET /events/1/visitors/1
  def show
    @role = get_role
    respond_with @event, @role
  end

  # GET /events/1/hosts/new
  # GET /events/1/visitors/new
  def new
    @people = Person.all
    @role = get_role
    respond_with @event, @role
  end

  # GET /events/1/hosts/registration_form
  # GET /events/1/visitors/registration_form
  def registration_form
    redirect_to join_event_url(@event) unless @current_user.new_record?
    @role = get_role(:person => @current_user)
  end

  # GET /events/1/hosts/join
  # GET /events/1/visitors/join
  def join
    redirect_to event_url(@event) unless @current_role.blank? || @current_role.new_record?
  end

  # GET /events/1/hosts/1/edit
  # GET /events/1/visitors/1/edit
  def edit
    @role = get_role
    respond_with @event, @role
  end

  # GET /events/1/hosts/1/delete
  # GET /events/1/visitors/1/delete
  def delete
    @role = get_role
    respond_with @event, @role
  end

  # POST /events/1/hosts
  # POST /events/1/visitors
  def create
    @role = get_role
    flash[:notice] = t('create.success', :scope => get_i18n_scope) if @role.save and not request.xhr?
    respond_with @event, @role, :location => {:action => 'index'}
  end

  # POST /events/1/register
  # POST /events/1/register
  def register
    @role = get_role
    @role.person.ldap_id = session[:cas_user]
    if @event.id == 4
      if @role.location_id.blank?
{'fraction_non_alphanumeric': 0.13019390581717452, 'fraction_numerical': 0.013388734995383195, 'mean_word_length': 2.9071235347159603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '3849865', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1529, 'n_words': 337}