File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
app/controllers/api/v8/courses Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,21 @@ def index
34
34
course = Course . find_by! ( id : params [ :course_id ] ) if params [ :course_id ]
35
35
exercises = Exercise . includes ( :available_points ) . where ( course_id : course . id )
36
36
37
- visible = exercises . select { |ex | ex . visible_to? ( current_user ) }
38
- presentable = visible . map do |ex |
37
+ unlocked_exercises = course . unlocks
38
+ . where ( user_id : current_user . id )
39
+ . where ( [ 'valid_after IS NULL OR valid_after < ?' , Time . now ] )
40
+ . pluck ( :exercise_name )
41
+
42
+ unless current_user . administrator? || current_user . teacher? ( course . organization ) || current_user . assistant? ( course )
43
+ exercises = exercises . where ( hidden : false , disabled_status : 0 )
44
+ exercises = if unlocked_exercises . empty?
45
+ exercises . where ( unlock_spec : nil )
46
+ else
47
+ exercises . where ( [ "unlock_spec IS NULL OR name IN (#{ unlocked_exercises . map { |_ | '?' } . join ( ', ' ) } )" , *unlocked_exercises ] )
48
+ end . select { |e | e . _fast_visible_to? ( current_user ) }
49
+ end
50
+
51
+ presentable = exercises . map do |ex |
39
52
{
40
53
id : ex . id ,
41
54
available_points : ex . available_points ,
@@ -47,8 +60,7 @@ def index
47
60
}
48
61
end
49
62
50
- authorize_collection :read , visible
51
- present ( presentable )
63
+ render json : presentable
52
64
end
53
65
end
54
66
end
You can’t perform that action at this time.
0 commit comments