File tree Expand file tree Collapse file tree 1 file changed +4
-16
lines changed
app/controllers/api/v8/courses Expand file tree Collapse file tree 1 file changed +4
-16
lines changed Original file line number Diff line number Diff line change @@ -34,21 +34,8 @@ 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
- 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 |
37
+ visible = exercises . select { |ex | ex . visible_to? ( current_user ) }
38
+ presentable = visible . map do |ex |
52
39
{
53
40
id : ex . id ,
54
41
available_points : ex . available_points ,
@@ -60,7 +47,8 @@ def index
60
47
}
61
48
end
62
49
63
- render json : presentable
50
+ authorize_collection :read , visible
51
+ present ( presentable )
64
52
end
65
53
end
66
54
end
You can’t perform that action at this time.
0 commit comments