<commit_before># We need to force loading of all submission rules so that methods
# like .const_defined? work correctly (rails abuse of autoload was
# causing issues)
Dir.glob('app/models/*_submission_rule.rb').each do |rule|
  require File.expand_path(rule)
end

class AssignmentsController < ApplicationController
  before_filter      :authorize_only_for_admin,
                     except: [:deletegroup,
                              :delete_rejected,
                              :disinvite_member,
                              :invite_member,
                              :creategroup,
                              :join_group,
                              :decline_invitation,
                              :index,
                              :student_interface,
                              :update_collected_submissions,
                              :render_test_result]

  before_filter      :authorize_for_student,
                     only: [:student_interface,
                            :deletegroup,
                            :delete_rejected,
                            :disinvite_member,
                            :invite_member,
                            :creategroup,
                            :join_group,
                            :decline_invitation]

  before_filter      :authorize_for_user,
                     only: [:index, :render_test_result]

  auto_complete_for  :assignment,
                     :name

  # Copy of API::AssignmentController without the id and order changed
  # to put first the 4 required fields
  DEFAULT_FIELDS = [:short_identifier, :description, :repository_folder,
                    :due_date, :message, :group_min, :group_max, :tokens_per_day,
                    :allow_web_submits, :student_form_groups, :remark_due_date,
                    :remark_message, :assign_graders_to_criteria, :enable_test,
                    :allow_remarks, :display_grader_names_to_students,
                    :group_name_autogenerated, :marking_scheme_type, :is_hidden]

  # Publicly accessible actions ---------------------------------------

  #=== Description
  # Action called via Rails' remote_function from the test_result_window partial
  # Prepares test result and updates content in window.
  def render_test_result
    @assignment = Assignment.find(params[:aid])
    @test_result = TestResult.find(params[:test_result_id])

    # Students can use this action only, when marks have been released
    if current_user.student? &&
        (@test_result.submission.grouping.membership_status(current_user).nil? ||
        @test_result.submission.get_latest_result.released_to_students == false)
      render partial: 'shared/handle_error',
             formats: [:js],
             handlers: [:erb],
             locals: { error: t('test_result.error.no_access',
                       test_result_id: @test_result.id) }
      return
    end

    render template: 'assignments/render_test_result', layout: 'plain'
  end

  def student_interface
    @assignment = Assignment.find(params[:id])
    if @assignment.is_hidden
      render file: "public/404.html", status: 404
      return
    end

    @student = current_user
    @grouping = @student.accepted_grouping_for(@assignment.id)
    @penalty = SubmissionRule.find_by_assignment_id(@assignment.id)
    @enum_penalty = Period.find_all_by_submission_rule_id(@penalty.id).sort

    if @student.section &&
       !@student.section.section_due_date_for(@assignment.id).nil?
      @due_date =
        @student.section.section_due_date_for(@assignment.id).due_date
    end
    if @due_date.nil?
      @due_date = @assignment.due_date
    end
    if @student.has_pending_groupings_for?(@assignment.id)
      @pending_grouping = @student.pending_groupings_for(@assignment.id)
    end
    if @grouping.nil?
      if @assignment.group_max == 1
        begin
          # fix for issue #627
          # currently create_group_for_working_alone_student only returns false
          # when saving a grouping throws an exception
          unless @student.create_group_for_working_alone_student(@assignment.id)
            # if create_group_for_working_alone_student returned false then the student
            # must have an ( empty ) existing grouping that he is not a member of.
            # we must delete this grouping for the transaction to succeed.
            Grouping.find_by_group_id_and_assignment_id( Group.find_by_group_name(@student.user_name), @assignment.id).destroy
          end
        rescue RuntimeError => @error<commit_msg>Revert "Fixed sorting issue with enum_penalty"<commit_after># We need to force loading of all submission rules so that methods
# like .const_defined? work correctly (rails abuse of autoload was
# causing issues)
Dir.glob('app/models/*_submission_rule.rb').each do |rule|
  require File.expand_path(rule)
end

class AssignmentsController < ApplicationController
  before_filter      :authorize_only_for_admin,
                     except: [:deletegroup,
                              :delete_rejected,
                              :disinvite_member,
                              :invite_member,
                              :creategroup,
                              :join_group,
                              :decline_invitation,
                              :index,
                              :student_interface,
                              :update_collected_submissions,
                              :render_test_result]

  before_filter      :authorize_for_student,
                     only: [:student_interface,
                            :deletegroup,
                            :delete_rejected,
                            :disinvite_member,
                            :invite_member,
                            :creategroup,
                            :join_group,
                            :decline_invitation]

  before_filter      :authorize_for_user,
                     only: [:index, :render_test_result]

  auto_complete_for  :assignment,
                     :name

  # Copy of API::AssignmentController without the id and order changed
  # to put first the 4 required fields
  DEFAULT_FIELDS = [:short_identifier, :description, :repository_folder,
                    :due_date, :message, :group_min, :group_max, :tokens_per_day,
                    :allow_web_submits, :student_form_groups, :remark_due_date,
                    :remark_message, :assign_graders_to_criteria, :enable_test,
                    :allow_remarks, :display_grader_names_to_students,
                    :group_name_autogenerated, :marking_scheme_type, :is_hidden]

  # Publicly accessible actions ---------------------------------------

  #=== Description
  # Action called via Rails' remote_function from the test_result_window partial
  # Prepares test result and updates content in window.
  def render_test_result
    @assignment = Assignment.find(params[:aid])
    @test_result = TestResult.find(params[:test_result_id])

    # Students can use this action only, when marks have been released
    if current_user.student? &&
        (@test_result.submission.grouping.membership_status(current_user).nil? ||
        @test_result.submission.get_latest_result.released_to_students == false)
      render partial: 'shared/handle_error',
             formats: [:js],
             handlers: [:erb],
             locals: { error: t('test_result.error.no_access',
                       test_result_id: @test_result.id) }
      return
    end

    render template: 'assignments/render_test_result', layout: 'plain'
  end

  def student_interface
    @assignment = Assignment.find(params[:id])
    if @assignment.is_hidden
      render file: "public/404.html", status: 404
      return
    end

    @student = current_user
    @grouping = @student.accepted_grouping_for(@assignment.id)
    @penalty = SubmissionRule.find_by_assignment_id(@assignment.id)
    # sort if it's penaltydecay or penalty period
    @enum_penalty = Period.find_all_by_submission_rule_id(@penalty.id)
    @enum_penalty.sort_by { |obj| obj.id }

    if @student.section &&
       !@student.section.section_due_date_for(@assignment.id).nil?
      @due_date =
        @student.section.section_due_date_for(@assignment.id).due_date
    end
    if @due_date.nil?
      @due_date = @assignment.due_date
    end
    if @student.has_pending_groupings_for?(@assignment.id)
      @pending_grouping = @student.pending_groupings_for(@assignment.id)
    end
    if @grouping.nil?
      if @assignment.group_max == 1
        begin
          # fix for issue #627
          # currently create_group_for_working_alone_student only returns false
          # when saving a grouping throws an exception
          unless @student.create_group_for_working_alone_student(@assignment.id)
            # if create_group_for_working_alone_student returned false then the student
            # must have an ( empty ) existing grouping that he is not a member of.
            # we must delete this grouping for the transaction to succeed.
            Grouping.find_by_group_id_and_assignment_id( Group.find_by_group_name(@student.user_name), @assignment.id).destroy
          end
        rescue RuntimeError => @error
{'fraction_non_alphanumeric': 0.08323398721144468, 'fraction_numerical': 0.0023843069253278422, 'mean_word_length': 2.1049798115746974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5204443', 'n_tokens_mistral': 2572, 'n_tokens_neox': 2487, 'n_words': 540}