Module: Course::Assessment::Answer::ProgrammingAbility

Included in:
Course::Assessment::AssessmentAbility
Defined in:
app/models/course/assessment/answer/programming_ability.rb

Instance Method Summary collapse

Instance Method Details

#allow_staff_download_programming_filesObject


38
39
40
# File 'app/models/course/assessment/answer/programming_ability.rb', line 38

def allow_staff_download_programming_files
  can :download, Course::Assessment::Answer::ProgrammingFile
end

#allow_students_create_programming_filesObject


15
16
17
18
19
20
21
22
# File 'app/models/course/assessment/answer/programming_ability.rb', line 15

def allow_students_create_programming_files
  can :create_programming_files, Course::Assessment::Answer::Programming do |programming_answer|
    multiple_file_submission?(programming_answer.question) &&
      creator?(programming_answer.submission) &&
      can_update_submission?(programming_answer.submission) &&
      current_answer?(programming_answer)
  end
end

#allow_students_destroy_programming_filesObject


24
25
26
27
28
29
30
31
# File 'app/models/course/assessment/answer/programming_ability.rb', line 24

def allow_students_destroy_programming_files
  can :destroy_programming_file, Course::Assessment::Answer::Programming do |programming_answer|
    multiple_file_submission?(programming_answer.question) &&
      creator?(programming_answer.submission) &&
      can_update_submission?(programming_answer.submission) &&
      current_answer?(programming_answer)
  end
end

#allow_students_download_programming_filesObject


33
34
35
36
# File 'app/models/course/assessment/answer/programming_ability.rb', line 33

def allow_students_download_programming_files
  can :download, Course::Assessment::Answer::ProgrammingFile,
      answer: { submission: { creator_id: user.id } }
end

#can_update_submission?(submission) ⇒ Boolean


47
48
49
# File 'app/models/course/assessment/answer/programming_ability.rb', line 47

def can_update_submission?(submission)
  can? :update, submission
end

#creator?(submission) ⇒ Boolean


51
52
53
# File 'app/models/course/assessment/answer/programming_ability.rb', line 51

def creator?(submission)
  submission.creator_id == user.id
end

#current_answer?(programming_answer) ⇒ Boolean


55
56
57
# File 'app/models/course/assessment/answer/programming_ability.rb', line 55

def current_answer?(programming_answer)
  programming_answer.answer.current_answer?
end

#define_permissionsObject


3
4
5
6
7
8
9
10
11
12
13
# File 'app/models/course/assessment/answer/programming_ability.rb', line 3

def define_permissions
  if user
    allow_students_create_programming_files
    allow_students_destroy_programming_files
    allow_students_download_programming_files

    allow_staff_download_programming_files if course_user&.staff?
  end

  super
end

#multiple_file_submission?(question) ⇒ Boolean

Checks if the question that the answer belongs to is a file_submission question


43
44
45
# File 'app/models/course/assessment/answer/programming_ability.rb', line 43

def multiple_file_submission?(question)
  question.specific.multiple_file_submission
end