<commit_before>class AddressesController < ApplicationController
  before_action :set_address, only: [:show, :edit, :update, :destroy]
  # Updates FK user_id
  #before_update


  def index
    @addresses = Address.all
  end

  def new
  end

  def show
  end

  def edit
  end

  def destroy
  end
  
  # PATCH/PUT /addresss/1
  # PATCH/PUT /addresss/1.json
  def update
    respond_to do |format|
      # Updates the FK user_id here
      pars = address_params
      pars[:user_id] = find_user_id(pars[:user_id])
      if @address.update(pars)
        flash[:success] = "Address was successfully updated. #{address_params.inspect}"
        format.html { redirect_to addresses_path }
        format.json { head :no_content }
      else
        flash[:danger] = 'There was a problem updating the Address.'
        format.html { render action: 'edit' }
        format.json { render json: @address.errors, status: :unprocessable_entity }
      end
    end
  end

  private

    # Use callbacks to share common setup or constraints between actions.
    def set_address
      @address = Address.find(params[:id])
    end
  
    # Never trust parameters from the scary internet, only allow the white list through.
    # lan_id is FK.
    def address_params
      params[:address].permit(:vlan_id, :user_id, :ip, :mac_address, :usage, :start_date, :end_date,
        :application_form)
    end

   # Resolves FK user_id before saving the modified @address
   def find_user_id(name)
     user = User.find_by(name: name)
     user ||= User.find_by(name: 'NOBODY')
     user.id
   end
end<commit_msg>Create a new user belonging to NONEXISTENT department if it does't exist<commit_after>class AddressesController < ApplicationController
  before_action :set_address, only: [:show, :edit, :update, :destroy]
  # Updates FK user_id
  #before_update


  def index
    @addresses = Address.all
  end

  def new
  end

  def show
  end

  def edit
  end

  def destroy
  end
  
  # PATCH/PUT /addresss/1
  # PATCH/PUT /addresss/1.json
  def update
    respond_to do |format|
      # Updates the FK user_id here
      pars = address_params
      pars[:user_id] = find_user_id(pars[:user_id])
      if @address.update(pars)
        flash[:success] = "Address was successfully updated. #{address_params.inspect}"
        format.html { redirect_to addresses_path }
        format.json { head :no_content }
      else
        flash[:danger] = 'There was a problem updating the Address.'
        format.html { render action: 'edit' }
        format.json { render json: @address.errors, status: :unprocessable_entity }
      end
    end
  end

  private

    # Use callbacks to share common setup or constraints between actions.
    def set_address
      @address = Address.find(params[:id])
    end
  
    # Never trust parameters from the scary internet, only allow the white list through.
    # lan_id is FK.
    def address_params
      params[:address].permit(:vlan_id, :user_id, :ip, :mac_address, :usage, :start_date, :end_date,
        :application_form)
    end

   # Resolves FK user_id before saving the modified @address
   def find_user_id(name)
     user = User.find_by(name: name)
     unless user
       u1 = Department.find_by(dept_name: 'NONEXISTENT').users.create(name: name)
       user = u1 if u1.valid?
       user ||= User.find_by(name: 'NOBODY')
     end
     user.id
   end
end
{'fraction_non_alphanumeric': 0.08878366380585972, 'fraction_numerical': 0.0020716188221367266, 'mean_word_length': 2.8192090395480225, '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': '3733203', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1048, 'n_words': 315}