<commit_before>class ExamAuthorizationRequestsController < ApplicationController

  before_action :set_registration!
  before_action :verify_registration_opened!

  def create
    authorization_request = @registration.authorization_requests.find_or_create_by! user: current_user do |it|
      it.assign_attributes authorization_request_params
    end
    current_user.read_notification! @registration
    flash.notice = I18n.t :exam_authorization_request_created
    redirect_to root_path
  end

  def update
    @registration.authorization_requests.update params[:id], authorization_request_params
    flash.notice = I18n.t :exam_authorization_request_saved
    redirect_to root_path
  end

  private

  def authorization_request_params
    params
        .require(:exam_authorization_request).permit(:exam_id, :exam_registration_id)
        .merge(user: current_user, organization: Organization.current)
  end

  def set_registration!
    @registration = ExamRegistration.find(authorization_request_params[:exam_registration_id])
  end

  def verify_registration_opened!
    raise Mumuki::Domain::GoneError if @registration.ended?
  end
end<commit_msg>Fix issue with invalid organization<commit_after>class ExamAuthorizationRequestsController < ApplicationController

  before_action :set_registration!
  before_action :verify_registration_opened!
  before_action :verify_registration_in_current_organization!

  def create
    authorization_request = @registration.authorization_requests.find_or_create_by! user: current_user do |it|
      it.assign_attributes authorization_request_params
    end
    current_user.read_notification! @registration
    flash.notice = I18n.t :exam_authorization_request_created
    redirect_to root_path
  end

  def update
    @registration.authorization_requests.update params[:id], authorization_request_params
    flash.notice = I18n.t :exam_authorization_request_saved
    redirect_to root_path
  end

  private

  def authorization_request_params
    params
        .require(:exam_authorization_request).permit(:exam_id, :exam_registration_id)
        .merge(user: current_user, organization: Organization.current)
  end

  def set_registration!
    @registration = ExamRegistration.find(authorization_request_params[:exam_registration_id])
  end

  def verify_registration_in_current_organization!
    raise Mumuki::Domain::NotFoundError unless @registration.organization == Organization.current
  end

  def verify_registration_opened!
    raise Mumuki::Domain::GoneError if @registration.ended?
  end
end
{'fraction_non_alphanumeric': 0.05886970172684458, 'fraction_numerical': 0.0031397174254317113, 'mean_word_length': 5.552699228791774, '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': '1560821', 'n_tokens_mistral': 751, 'n_tokens_neox': 697, 'n_words': 135}