Skip to content

Commit b96fa1f

Browse files
committed
Do not show empty groups in stats
1 parent 7c259e3 commit b96fa1f

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

app/controllers/api/v8/courses/exercises_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def index
5353

5454
all_exercises = course.exercises
5555
.where(hidden: false, disabled_status: 0)
56-
.select { |ex| ex._fast_visible_to?(current_user) }
56+
.select { |ex| ex._fast_visible? }
5757

5858
presentable = all_exercises.map do |ex|
5959
{

app/models/course.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,12 @@ def toggle_submission_result_visiblity
469469
def exercise_group_completion_by_user
470470
# TODO: clean up exercise group discovery
471471

472-
groups = exercises.map(&:name).map { |name| if name =~ /^(.+)-[^-]+$/ then $1 else '' end }.uniq
472+
groups = exercises
473+
.where(disabled_status: 0)
474+
.select { |e| e._fast_visible? }
475+
.map(&:name)
476+
.map { |name| if name =~ /^(.+)-[^-]+$/ then $1 else '' end }
477+
.uniq
473478

474479
result = {}
475480
for group in groups

app/models/exercise.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ def submittable_by?(user)
188188
# Whether a user may see all metadata about the exercise
189189
def visible_to?(user)
190190
user.administrator? || user.teacher?(course.organization) || user.assistant?(course) ||
191-
_fast_visible_to?(user) && unlock_spec_obj.permits_unlock_for?(user)
191+
_fast_visible? && unlock_spec_obj.permits_unlock_for?(user)
192192
end
193193

194-
def _fast_visible_to?(user)
194+
def _fast_visible?
195195
!hidden? && !disabled? && published?
196196
end
197197

lib/course_info.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def course_data_core_api(course)
4545
exercises.where(unlock_spec: nil)
4646
else
4747
exercises.where(["unlock_spec IS NULL OR exercises.name IN (#{@unlocked_exercises.map { |_| '?' }.join(', ')})", *@unlocked_exercises])
48-
end.select { |e| e._fast_visible_to?(@user) }
48+
end.select { |e| e._fast_visible? }
4949
end
5050

5151
exercises = exercises.to_a.natsort_by(&:name)

0 commit comments

Comments
 (0)