<commit_before>require 'base64'


class AssignmentsController < ApplicationController
  responders :flash

  before_action      :authorize_only_for_admin,
                     except: [:index,
                              :student_interface,
                              :update_collected_submissions,
                              :render_feedback_file,
                              :peer_review,
                              :summary]

  before_action      :authorize_for_ta_and_admin,
                     only: [:summary]

  before_action      :authorize_for_student,
                     only: [:student_interface,
                            :peer_review]

  before_action      :authorize_for_user,
                     only: [:index, :render_feedback_file]

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

  def render_feedback_file
    @feedback_file = FeedbackFile.find(params[:feedback_file_id])

    # Students can use this action only, when marks have been released
    if current_user.student? &&
        (@feedback_file.submission.grouping.membership_status(current_user).nil? ||
         !@feedback_file.submission.get_latest_result.released_to_students)
      flash_message(:error, t('feedback_file.error.no_access',
                              feedback_file_id: @feedback_file.id))
      head :forbidden
      return
    end

    if @feedback_file.mime_type.start_with? 'image'
      content = Base64.encode64(@feedback_file.file_content)
    else
      content = @feedback_file.file_content
    end

    send_data content,
              type: @feedback_file.mime_type,
              filename: @feedback_file.filename,
              disposition: 'inline'
  end

  def student_interface
    assignment = Assignment.find(params[:id])
    @assignment = assignment.is_peer_review? ? assignment.parent_assignment : assignment
    if @assignment.is_hidden
      render 'shared/http_status',
             formats: [:html],
             locals: {
               code: '404',
               message: HttpStatusHelper::ERROR_CODE['message']['404']
             },
             status: 404,
             layout: false
      return
    end

    @student = current_user
    @grouping = @student.accepted_grouping_for(@assignment.id)
    @penalty = SubmissionRule.find_by_assignment_id(@assignment.id)
    @enum_penalty = Period.where(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 && !@assignment.scanned_exam
        begin
          @student.create_group_for_working_alone_student(@assignment.id)
        rescue RuntimeError => error
          flash_message(:error, error.message)
        end
        redirect_to action: 'student_interface', id: @assignment.id
      else
        if @assignment.scanned_exam
          flash_now(:notice, t('assignments.scanned_exam.under_review'))
        end
        render :student_interface
      end
    else
      # We look for the information on this group...
      # The members
      @studentmemberships = @grouping.student_memberships
      # The group name
      @group = @grouping.group
      # The inviter
      @inviter = @grouping.inviter

      # Look up submission information
      set_repo_vars(@assignment, @grouping)
    end
  end

  def peer_review
    assignment = Assignment.find(params[:id])
    @assignment = assignment.is_peer_review? ? assignment : assignment.pr_assignment
    if @assignment.nil? || @assignment.is_hidden
      render 'shared/http_status',
             formats: [:html],
             locals: {
                 code: '404',
                 message: HttpStatusHelper::ERROR_CODE['message']['404']
             },
             status: 404,
             layout: false
      return
    end

    @student = current_user
    @grouping = @student.accepted_grouping_for(@assignment.id)
    @penalty = @assignment.submission_rule
    @enum_penalty = Period.where(submission_rule_id: @penalty.id).sort

    @prs = @student.grouping_for(@assignment.parent_assignment.id).
        peer_reviews.where(results: { released_to_students: true })

    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 @assignment.past_all_collection_dates?
      flash_now(:notice, t('submissions.grading_can_begin'))
    else
      if @assignment.section_due_dates_type
        section_due_dates = Hash.new
        now = Time.zone.now
        Section.all.each do |section|
          collection_time = @assignment.submission_rule
                                .calculate_collection_time(section)
          collection_time = now if now >= collection_time
          if section_due_dates[collection_time].nil?
            section_due_dates[collection_time] = Array.new
          end
          section_due_dates[collection_time].push(section.name)
        end
        section_due_dates.each do |collection_time, sections|<commit_msg>added default if student did not submit parent assignment<commit_after>require 'base64'


class AssignmentsController < ApplicationController
  responders :flash

  before_action      :authorize_only_for_admin,
                     except: [:index,
                              :student_interface,
                              :update_collected_submissions,
                              :render_feedback_file,
                              :peer_review,
                              :summary]

  before_action      :authorize_for_ta_and_admin,
                     only: [:summary]

  before_action      :authorize_for_student,
                     only: [:student_interface,
                            :peer_review]

  before_action      :authorize_for_user,
                     only: [:index, :render_feedback_file]

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

  def render_feedback_file
    @feedback_file = FeedbackFile.find(params[:feedback_file_id])

    # Students can use this action only, when marks have been released
    if current_user.student? &&
        (@feedback_file.submission.grouping.membership_status(current_user).nil? ||
         !@feedback_file.submission.get_latest_result.released_to_students)
      flash_message(:error, t('feedback_file.error.no_access',
                              feedback_file_id: @feedback_file.id))
      head :forbidden
      return
    end

    if @feedback_file.mime_type.start_with? 'image'
      content = Base64.encode64(@feedback_file.file_content)
    else
      content = @feedback_file.file_content
    end

    send_data content,
              type: @feedback_file.mime_type,
              filename: @feedback_file.filename,
              disposition: 'inline'
  end

  def student_interface
    assignment = Assignment.find(params[:id])
    @assignment = assignment.is_peer_review? ? assignment.parent_assignment : assignment
    if @assignment.is_hidden
      render 'shared/http_status',
             formats: [:html],
             locals: {
               code: '404',
               message: HttpStatusHelper::ERROR_CODE['message']['404']
             },
             status: 404,
             layout: false
      return
    end

    @student = current_user
    @grouping = @student.accepted_grouping_for(@assignment.id)
    @penalty = SubmissionRule.find_by_assignment_id(@assignment.id)
    @enum_penalty = Period.where(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 && !@assignment.scanned_exam
        begin
          @student.create_group_for_working_alone_student(@assignment.id)
        rescue RuntimeError => error
          flash_message(:error, error.message)
        end
        redirect_to action: 'student_interface', id: @assignment.id
      else
        if @assignment.scanned_exam
          flash_now(:notice, t('assignments.scanned_exam.under_review'))
        end
        render :student_interface
      end
    else
      # We look for the information on this group...
      # The members
      @studentmemberships = @grouping.student_memberships
      # The group name
      @group = @grouping.group
      # The inviter
      @inviter = @grouping.inviter

      # Look up submission information
      set_repo_vars(@assignment, @grouping)
    end
  end

  def peer_review
    assignment = Assignment.find(params[:id])
    @assignment = assignment.is_peer_review? ? assignment : assignment.pr_assignment
    if @assignment.nil? || @assignment.is_hidden
      render 'shared/http_status',
             formats: [:html],
             locals: {
                 code: '404',
                 message: HttpStatusHelper::ERROR_CODE['message']['404']
             },
             status: 404,
             layout: false
      return
    end

    @student = current_user
    @grouping = @student.accepted_grouping_for(@assignment.id)
    @penalty = @assignment.submission_rule
    @enum_penalty = Period.where(submission_rule_id: @penalty.id).sort

    @prs = @student.grouping_for(@assignment.parent_assignment.id)&.
        peer_reviews&.where(results: { released_to_students: true })
    if @prs.nil?
      @prs = []
    end

    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 @assignment.past_all_collection_dates?
      flash_now(:notice, t('submissions.grading_can_begin'))
    else
      if @assignment.section_due_dates_type
        section_due_dates = Hash.new
        now = Time.zone.now
        Section.all.each do |section|
          collection_time = @assignment.submission_rule
                                .calculate_collection_time(section)
          collection_time = now if now >= collection_time
          if section_due_dates[collection_time].nil?
            section_due_dates[collection_time] = Array.new
          end
          section_due_dates[collection_time].push(section.name)
        end
        section_due_dates.each do |collection_time, sections|
{'fraction_non_alphanumeric': 0.0949923028162637, 'fraction_numerical': 0.004527755139002083, 'mean_word_length': 2.2869047619047618, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7307942', 'n_tokens_mistral': 3266, 'n_tokens_neox': 3140, 'n_words': 551}