<commit_before>class Diamond::ThesisEnrollmentsController < DiamondController

  authorize_resource :except => [:accept, :reject]

  def create
    @thesis = Diamond::Thesis.find(params[:thesis_id])
    @enrollment = Diamond::ThesisEnrollment.new enrollment_params
    @enrollment.tap do |e|
      e.thesis_id = params[:thesis_id]
      if can?(:manage, Diamond::ThesisEnrollment)
        e.student_id = params[:thesis_enrollment][:student_id]
      else
        e.student_id = current_user.verifable_id
      end
    end

    student = Student.where(id: @enrollment.student_id).first
    if student.present?
      @enrollment.save
      if can?(:manage, Diamond::ThesisEnrollment)
        @enrollment.accept!
        if @thesis.can_assign? && @thesis.has_required_students? &&
            (can?(:manage_department, @thesis) ||
              (@thesis.current_state >= :open && can?(:manage_own, @thesis)))
          @thesis.assign!
          (@thesis.enrollments - [@enrollment]).each do |enrollment|
            enrollment.reject! if enrollment.can_reject?
          end
        end
        flash[:notice] = t(:label_thesis_enrolled_by_employee, :student => student.surname_name)
      else
        Diamond::ThesesMailer.new_enrollment(current_user.id, @enrollment.id).deliver
        flash[:notice] = t(:label_thesis_enrolled_by_student)
      end<commit_msg>Inform student about his enrollment if enrolled by employee<commit_after>class Diamond::ThesisEnrollmentsController < DiamondController

  authorize_resource :except => [:accept, :reject]

  def create
    @thesis = Diamond::Thesis.find(params[:thesis_id])
    @enrollment = Diamond::ThesisEnrollment.new enrollment_params
    @enrollment.tap do |e|
      e.thesis_id = params[:thesis_id]
      if can?(:manage, Diamond::ThesisEnrollment)
        e.student_id = params[:thesis_enrollment][:student_id]
      else
        e.student_id = current_user.verifable_id
      end
    end

    student = Student.where(id: @enrollment.student_id).first
    if student.present?
      @enrollment.save
      if can?(:manage, Diamond::ThesisEnrollment)
        @enrollment.accept!
        Diamond::ThesesMailer.enrollment_accepted(@enrollment.id).deliver
        if @thesis.can_assign? && @thesis.has_required_students? &&
            (can?(:manage_department, @thesis) ||
              (@thesis.current_state >= :open && can?(:manage_own, @thesis)))
          @thesis.assign!
          (@thesis.enrollments - [@enrollment]).each do |enrollment|
            enrollment.reject! if enrollment.can_reject?
          end
        end
        flash[:notice] = t(:label_thesis_enrolled_by_employee, :student => student.surname_name)
      else
        Diamond::ThesesMailer.new_enrollment(current_user.id, @enrollment.id).deliver
        flash[:notice] = t(:label_thesis_enrolled_by_student)
      end
{'fraction_non_alphanumeric': 0.11541168191414497, 'fraction_numerical': 0.0, 'mean_word_length': 3.275187969924812, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1214024', 'n_tokens_mistral': 902, 'n_tokens_neox': 904, 'n_words': 144}