Class: Course::Assessment::AssessmentsController

Inherits:
Controller show all
Defined in:
app/controllers/course/assessment/assessments_controller.rb

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

#authenticateObject


61
62
63
64
65
66
67
# File 'app/controllers/course/assessment/assessments_controller.rb', line 61

def authenticate
  if authentication_service.authenticate(params.require(:assessment).permit(:password)[:password])
    render json: { success: true }
  else
    render json: { success: false }
  end
end

#createObject


17
18
19
20
21
22
23
# File 'app/controllers/course/assessment/assessments_controller.rb', line 17

def create
  if @assessment.save
    render json: { id: @assessment.id }, status: :ok
  else
    render json: { errors: @assessment.errors }, status: :bad_request
  end
end

#destroyObject


37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/course/assessment/assessments_controller.rb', line 37

def destroy
  if @assessment.destroy
    redirect_to course_assessments_path(current_course, category: @assessment.tab.category_id,
                                                        tab: @assessment.tab_id),
                success: t('.success', assessment: @assessment.title)
  else
    redirect_to course_assessment_path(current_course, @assessment),
                danger: t('.failure', error: @assessment.errors.full_messages.to_sentence)
  end
end

#editObject


25
26
# File 'app/controllers/course/assessment/assessments_controller.rb', line 25

def edit
end

#indexObject


5
6
7
8
# File 'app/controllers/course/assessment/assessments_controller.rb', line 5

def index
  @assessments = @assessments.ordered_by_date_and_title.with_submissions_by(current_user)
  @conditional_service = Course::Assessment::AchievementPreloadService.new(@assessments)
end

#load_assessment_optionsObject (protected)


71
72
73
74
75
# File 'app/controllers/course/assessment/assessments_controller.rb', line 71

def load_assessment_options
  return super if skip_tab_filter?

  { through: :tab }
end

#newObject


14
15
# File 'app/controllers/course/assessment/assessments_controller.rb', line 14

def new
end

#reorderObject

Reorder questions for an assessment


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

def reorder
  unless valid_ordering?(question_order_ids)
    raise ArgumentError, 'Invalid ordering for assessment questions'
  end

  Course::QuestionAssessment.transaction do
    question_order_ids.each_with_index do |id, index|
      question_assessments_hash[id].update_attribute(:weight, index)
    end
  end
end

#showObject


10
11
12
# File 'app/controllers/course/assessment/assessments_controller.rb', line 10

def show
  render 'authenticate' unless can_access_assessment?
end

#updateObject


28
29
30
31
32
33
34
35
# File 'app/controllers/course/assessment/assessments_controller.rb', line 28

def update
  @assessment.update_mode(autograded_params)
  if @assessment.update(assessment_params)
    head :ok
  else
    render json: { errors: @assessment.errors }, status: :bad_request
  end
end