<commit_before>require "archive"
require "csv"
require "fileutils"
require "rubygems/package"
require "statistics"
require "yaml"

class AssessmentsController < ApplicationController
  include ActiveSupport::Callbacks

    rescue_from ActionView::MissingTemplate do |exception|
      redirect_to("/home/error_404")
  end

  autolab_require Rails.root.join("app", "controllers", "assessment", "handin.rb")
  include AssessmentHandin

  autolab_require Rails.root.join("app", "controllers", "assessment", "handout.rb")
  include AssessmentHandout

  autolab_require Rails.root.join("app", "controllers", "assessment", "grading.rb")
  include AssessmentGrading

  autolab_require Rails.root.join("app", "controllers", "assessment", "autograde.rb")
  include AssessmentAutograde

  # this is inherited from ApplicationController
  before_action :set_assessment, except: [:index, :new, :create, :installAssessment,
                                          :importAsmtFromTar, :importAssessment,
                                          :log_submit, :local_submit, :autograde_done]
  before_action :set_submission, only: [:viewFeedback]

  # We have to do this here, because the modules don't inherit ApplicationController.

  # Grading
  action_auth_level :bulkGrade, :course_assistant
  action_auth_level :quickSetScore, :course_assistant
  action_auth_level :quickSetScoreDetails, :course_assistant
  action_auth_level :submission_popover, :course_assistant
  action_auth_level :score_grader_info, :course_assistant
  action_auth_level :viewGradesheet, :course_assistant
  action_auth_level :viewGradesheet2, :course_assistant
  action_auth_level :quickGetTotal, :course_assistant
  action_auth_level :statistics, :instructor

  # Handin
  action_auth_level :handin, :student

  # Handout
  action_auth_level :handout, :student

  # Autograde
  action_no_auth :autograde_done
  action_auth_level :regrade, :instructor
  action_auth_level :regradeAll, :instructor
  action_no_auth :log_submit
  action_no_auth :local_submit

  # SVN
  autolab_require Rails.root.join("app", "controllers", "assessment", "svn.rb")
  include AssessmentSVN
  action_auth_level :admin_svn, :instructor
  action_auth_level :set_repo, :instructor
  action_auth_level :import_svn, :instructor

  def index
    @is_instructor = @cud.has_auth_level? :instructor
    @announcements = Announcement.where("start_date < :now AND end_date > :now", now: Time.now)
                                 .where("course_id = ? OR system = ?", @course.id, true)
                                 .where(persistent: false).order(:start_date)
    @attachments = (@cud.instructor?) ? @course.attachments : @course.attachments.where(released: true)
  end

  # GET /assessments/new
  # Installs a new assessment, either by
  # creating it from scratch, or importing it from an existing
  # assessment directory.
  action_auth_level :new, :instructor
  def new
    @assessment = @course.assessments.new
  end

  # installAssessment - Installs a new assessment, either by
  # creating it from scratch, or importing it from an existing
  # assessment directory on file system, or from an uploaded
  # tar file with the assessment directory.
  action_auth_level :installAssessment, :instructor
  def installAssessment
    ass_dir = Rails.root.join("courses", @course.name)
    @unused_config_files = []
    flash[:error] = ""
    Dir.foreach(ass_dir) do |filename|
      # assessment's yaml file must exist
      if !File.exist?(File.join(ass_dir, filename, "#{filename}.yml"))
        flash[:error] += "Yml does not exist: " + filename +"     -     "
        next
      end
      # names must be only lowercase letters and digits
      if filename =~ /[^a-z0-9]/
        flash[:error] += "Name must be only lowercase letters and digits: "+filename
        next
      end

      # Only list assessments that aren't installed yet
      assessment_exists = @course.assessments.exists?(name: filename)
      @unused_config_files << filename unless assessment_exists
    end
    @unused_config_files.sort!
  end

  action_auth_level :importAsmtFromTar, :instructor<commit_msg>scrubbed install assessment errors<commit_after>require "archive"
require "csv"
require "fileutils"
require "rubygems/package"
require "statistics"
require "yaml"

class AssessmentsController < ApplicationController
  include ActiveSupport::Callbacks

    rescue_from ActionView::MissingTemplate do |exception|
      redirect_to("/home/error_404")
  end

  autolab_require Rails.root.join("app", "controllers", "assessment", "handin.rb")
  include AssessmentHandin

  autolab_require Rails.root.join("app", "controllers", "assessment", "handout.rb")
  include AssessmentHandout

  autolab_require Rails.root.join("app", "controllers", "assessment", "grading.rb")
  include AssessmentGrading

  autolab_require Rails.root.join("app", "controllers", "assessment", "autograde.rb")
  include AssessmentAutograde

  # this is inherited from ApplicationController
  before_action :set_assessment, except: [:index, :new, :create, :installAssessment,
                                          :importAsmtFromTar, :importAssessment,
                                          :log_submit, :local_submit, :autograde_done]
  before_action :set_submission, only: [:viewFeedback]

  # We have to do this here, because the modules don't inherit ApplicationController.

  # Grading
  action_auth_level :bulkGrade, :course_assistant
  action_auth_level :quickSetScore, :course_assistant
  action_auth_level :quickSetScoreDetails, :course_assistant
  action_auth_level :submission_popover, :course_assistant
  action_auth_level :score_grader_info, :course_assistant
  action_auth_level :viewGradesheet, :course_assistant
  action_auth_level :viewGradesheet2, :course_assistant
  action_auth_level :quickGetTotal, :course_assistant
  action_auth_level :statistics, :instructor

  # Handin
  action_auth_level :handin, :student

  # Handout
  action_auth_level :handout, :student

  # Autograde
  action_no_auth :autograde_done
  action_auth_level :regrade, :instructor
  action_auth_level :regradeAll, :instructor
  action_no_auth :log_submit
  action_no_auth :local_submit

  # SVN
  autolab_require Rails.root.join("app", "controllers", "assessment", "svn.rb")
  include AssessmentSVN
  action_auth_level :admin_svn, :instructor
  action_auth_level :set_repo, :instructor
  action_auth_level :import_svn, :instructor

  def index
    @is_instructor = @cud.has_auth_level? :instructor
    @announcements = Announcement.where("start_date < :now AND end_date > :now", now: Time.now)
                                 .where("course_id = ? OR system = ?", @course.id, true)
                                 .where(persistent: false).order(:start_date)
    @attachments = (@cud.instructor?) ? @course.attachments : @course.attachments.where(released: true)
  end

  # GET /assessments/new
  # Installs a new assessment, either by
  # creating it from scratch, or importing it from an existing
  # assessment directory.
  action_auth_level :new, :instructor
  def new
    @assessment = @course.assessments.new
  end

  # installAssessment - Installs a new assessment, either by
  # creating it from scratch, or importing it from an existing
  # assessment directory on file system, or from an uploaded
  # tar file with the assessment directory.
  action_auth_level :installAssessment, :instructor
  def installAssessment
    ass_dir = Rails.root.join("courses", @course.name)
    @unused_config_files = []
    Dir.foreach(ass_dir) do |filename|
      next unless File.exist?(File.join(ass_dir, filename, "#{filename}.yml"))

      # names must be only lowercase letters and digits
      next if filename =~ /[^a-z0-9]/

      # Only list assessments that aren't installed yet
      assessment_exists = @course.assessments.exists?(name: filename)
      @unused_config_files << filename unless assessment_exists
    end
    @unused_config_files.sort!
  end

  action_auth_level :importAsmtFromTar, :instructor
{'fraction_non_alphanumeric': 0.09084093464950643, 'fraction_numerical': 0.001499437710858428, 'mean_word_length': 4.085133418043202, 'pattern_counts': {'":': 0, '<': 11, '<?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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3387494', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2394, 'n_words': 596}