Class: Course::Assessment::Submission::SubmissionsController

Inherits:
Controller show all
Includes:
SubmissionsControllerServiceConcern
Defined in:
app/controllers/course/assessment/submission/submissions_controller.rb

Constant Summary collapse

STUDENTS =
{ my: 'my', phantom: 'phantom' }.freeze

Instance Method Summary collapse

Methods included from ApplicationSignInCallbacksConcern

#sign_in

Methods included from ApplicationPaginationConcern

#page_param

Methods included from ApplicationAnnouncementsConcern

#global_announcements, #unread_global_announcements

Methods included from ApplicationInstanceUserConcern

#current_instance_user

Methods included from ApplicationUserTimeZoneConcern

#set_time_zone

Methods included from ApplicationUserConcern

#handle_access_denied, #publicly_accessible?

Methods included from ApplicationComponentsConcern

#handle_component_not_found

Instance Method Details

#auto_gradeObject


62
63
64
65
66
# File 'app/controllers/course/assessment/submission/submissions_controller.rb', line 62

def auto_grade
  authorize!(:grade, @submission)
  job = @submission.auto_grade!
  render json: { redirect_url: job_path(job.job) }
end

#createObject


38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/course/assessment/submission/submissions_controller.rb', line 38

def create
  @submission.session_id = authentication_service.generate_authentication_token!
  if @submission.save
    log_service.log_submission_access(request) if @assessment.session_password_protected?
    redirect_to edit_course_assessment_submission_path(current_course, @assessment, @submission,
                                                       new_submission: true)
  else
    redirect_to course_assessments_path(current_course),
                danger: t('.failure', error: @submission.errors.full_messages.to_sentence)
  end
end

#download_allObject

Download either all of or a subset of submissions for an assessment.


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/course/assessment/submission/submissions_controller.rb', line 104

def download_all
  authorize!(:manage, @assessment)
  if !@assessment.downloadable?
    head :bad_request
  elsif @assessment.submissions.confirmed.empty?
    head :bad_request
  else
    job = Course::Assessment::Submission::ZipDownloadJob.
          perform_later(current_course_user, @assessment, params[:students]).job
    respond_to do |format|
      format.html { redirect_to(job_path(job)) }
      format.json { render json: { redirect_url: job_path(job) } }
    end
  end
end

#download_statisticsObject


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/controllers/course/assessment/submission/submissions_controller.rb', line 120

def download_statistics
  authorize!(:manage, @assessment)
  submission_ids = @assessment.submissions.by_users(student_ids).pluck(:id)
  if submission_ids.empty?
    render json: { error:
           I18n.t('course.assessment.submission.submissions.download_statistics.no_submission_statistics') },
           status: :bad_request
  else
    job = Course::Assessment::Submission::StatisticsDownloadJob.
          perform_later(current_user, submission_ids).job
    respond_to do |format|
      format.html { redirect_to(job_path(job)) }
      format.json { render json: { redirect_url: job_path(job) } }
    end
  end
end

#editObject


50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/course/assessment/submission/submissions_controller.rb', line 50

def edit
  return if @submission.attempting?

  respond_to do |format|
    format.html {}
    format.json do
      calculated_fields = [:graded_at]
      @submission = @submission.calculated(*calculated_fields)
    end
  end
end

#indexObject


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/course/assessment/submission/submissions_controller.rb', line 24

def index
  authorize!(:manage, @assessment)

  respond_to do |format|
    format.html {}
    format.json do
      @assessment = @assessment.calculated(:maximum_grade)
      @submissions = @submissions.calculated(:log_count, :graded_at).includes(:answers)
      @my_students = current_course_user&.my_students || []
      @course_students = current_course.course_users.students.order_alphabetically
    end
  end
end

#publish_allObject

Publish all the graded submissions.


88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/course/assessment/submission/submissions_controller.rb', line 88

def publish_all
  authorize!(:publish_grades, @assessment)
  graded_submissions = @assessment.submissions.with_graded_state
  if !graded_submissions.empty?
    job = Course::Assessment::Submission::PublishingJob.
          perform_later(@assessment, current_user).job
    respond_to do |format|
      format.html { redirect_to(job_path(job)) }
      format.json { render json: { redirect_url: job_path(job) } }
    end
  else
    head :ok
  end
end

#reload_answerObject

Reload the current answer or reset it, depending on parameters. current_answer has the most recent copy of the answer.


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/course/assessment/submission/submissions_controller.rb', line 70

def reload_answer
  @answer = @submission.answers.find_by(id: reload_answer_params[:answer_id])

  if @answer.nil?
    head :bad_request
    return
  elsif reload_answer_params[:reset_answer]
    @new_answer = @answer.reset_answer
  else
    @new_answer = @answer
  end

  respond_to do |format|
    format.json { render @new_answer }
  end
end