<commit_before>class SampleTypesController < ApplicationController
  before_action :load_vars, only: [:edit, :update]
  before_action :load_vars_nested, only: [:new, :create]
  before_action :check_create_permissions, only: [:new, :create]
  before_action :check_edit_permissions, only: [:edit, :update]

  def new
    @sample_type = SampleType.new
    session[:return_to] ||= request.referer
  end

  def create
    @sample_type = SampleType.new(sample_type_params)
    @sample_type.organization = @organization
    @sample_type.created_by = current_user
    @sample_type.last_modified_by = current_user

    respond_to do |format|
      if @sample_type.save
        # flash[:success] = t(
        #   "sample_types.create.success_flash",
        #   sample_type: @sample_type.name,
        #   organization: @organization.name
        # )
        format.json {
          render json: {
            id: @sample_type.id,
            flash: t(
              'sample_types.create.success_flash',
              sample_type: @sample_type.name,
              organization: @organization.name
            )
          },
          status: :ok
        }
      else
        format.json {
          render json: @sample_type.errors,
            status: :unprocessable_entity
        }
      end
    end
  end

  def edit

  end

  def update
    @sample_type.last_modified_by = current_user
    if @sample_type.update_attributes(sample_type_params)
      flash[:success] = t(
        "sample_types.update.success_flash",
        sample_type: @sample_type.name,
        organization: @organization.name)
      redirect_to (session.delete(:return_to) || root_path)
    else
      render :edit
    end
  end

  def destroy
  end

  private

  def load_vars
    @sample_type = SampleType.find_by_id(params[:id])
    @organization = @sample_type.organization

    unless @sample_type
      render_404
    end
  end

  def load_vars_nested
    @organization = Organization.find_by_id(params[:organization_id])

    unless @organization
      render_404
    end
  end

  def check_create_permissions
    unless can_create_sample_type_in_organization(@organization)
      render_403
    end
  end

  def check_edit_permissions
    unless can_edit_sample_type_in_organization(@organization)
      render_403
    end
  end

  def sample_type_params
    params.require(:sample_type).permit(:name)
  end
end
<commit_msg>delete comment<commit_after>class SampleTypesController < ApplicationController
  before_action :load_vars, only: [:edit, :update]
  before_action :load_vars_nested, only: [:new, :create]
  before_action :check_create_permissions, only: [:new, :create]
  before_action :check_edit_permissions, only: [:edit, :update]

  def new
    @sample_type = SampleType.new
    session[:return_to] ||= request.referer
  end

  def create
    @sample_type = SampleType.new(sample_type_params)
    @sample_type.organization = @organization
    @sample_type.created_by = current_user
    @sample_type.last_modified_by = current_user

    respond_to do |format|
      if @sample_type.save
        format.json {
          render json: {
            id: @sample_type.id,
            flash: t(
              'sample_types.create.success_flash',
              sample_type: @sample_type.name,
              organization: @organization.name
            )
          },
          status: :ok
        }
      else
        format.json {
          render json: @sample_type.errors,
            status: :unprocessable_entity
        }
      end
    end
  end

  def edit

  end

  def update
    @sample_type.last_modified_by = current_user
    if @sample_type.update_attributes(sample_type_params)
      flash[:success] = t(
        "sample_types.update.success_flash",
        sample_type: @sample_type.name,
        organization: @organization.name)
      redirect_to (session.delete(:return_to) || root_path)
    else
      render :edit
    end
  end

  def destroy
  end

  private

  def load_vars
    @sample_type = SampleType.find_by_id(params[:id])
    @organization = @sample_type.organization

    unless @sample_type
      render_404
    end
  end

  def load_vars_nested
    @organization = Organization.find_by_id(params[:organization_id])

    unless @organization
      render_404
    end
  end

  def check_create_permissions
    unless can_create_sample_type_in_organization(@organization)
      render_403
    end
  end

  def check_edit_permissions
    unless can_edit_sample_type_in_organization(@organization)
      render_403
    end
  end

  def sample_type_params
    params.require(:sample_type).permit(:name)
  end
end

{'fraction_non_alphanumeric': 0.07950606585788561, 'fraction_numerical': 0.005199306759098787, 'mean_word_length': 2.70545746388443, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1678430', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1389, 'n_words': 280}