Skip to content

Commit

Permalink
Show warning about inaccessible activities to course admins on course…
Browse files Browse the repository at this point in the history
… show
  • Loading branch information
chvp committed Oct 8, 2021
1 parent 62e351f commit b16e65c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def show
redirect_unless_secret_correct
return if performed?
end
if current_user&.course_admin?(@course) && !@course.all_activities_accessible?
flash[:alert] = I18n.t('courses.show.has_private_exercises')
end
@title = @course.name
@series = policy_scope(@course.series).includes(:evaluation)
@series_loaded = params[:secret].present? ? @course.series.count : 2
Expand Down Expand Up @@ -134,7 +137,6 @@ def create

respond_to do |format|
if @course.save
flash[:alert] = I18n.t('courses.create.added_private_exercises') unless @course.exercises.where(access: :private).count.zero?
@course.administrating_members << current_user unless @course.administrating_members.include?(current_user)
format.html { redirect_to @course, notice: I18n.t('controllers.created', model: Course.model_name.human) }
format.json { render :show, status: :created, location: @course }
Expand Down
4 changes: 4 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ def secret_required?(user = nil)
true
end

def all_activities_accessible?
activities.where(access: :private).where.not(repository_id: usable_repositories).count.zero?
end

def invalidate_subscribed_members_count_cache
Rails.cache.delete(format(SUBSCRIBED_MEMBERS_COUNT_CACHE_STRING, id: id))
end
Expand Down
3 changes: 1 addition & 2 deletions config/locales/views/courses/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ en:
other: "You can't remove a course with more than %{count} submissions yourself."
contact_html: "<a href=\"%{contact_url}\">Contact us</a> if you want to delete the course anyway."
show:
has_private_exercises: "This course uses private exercises that it hasn't been granted the rights to."
course: Course
hidden_show_link: "Secret link"
visibility-visible_for_all-info: "This course is visible for everyone: everyone can access this course from the course overview, and the contents are visible for everyone."
Expand Down Expand Up @@ -175,8 +176,6 @@ en:
exercise_count: Exercises
content_count: Reading activities
more_statistics: "More statistics >"
create:
added_private_exercises: "Private exercises were added while creating this course. To use these exercises, this course will need to be granted permission from the relevant repositories."
copy_courses_table:
info: "Course"
users: "# users"
Expand Down
5 changes: 2 additions & 3 deletions config/locales/views/courses/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ nl:
other: "Je kan een cursus met meer dan %{count} oplossingen niet zelf verwijderen."
contact_html: "<a href=\"%{contact_url}\">Contacteer ons</a> als je de cursus toch wilt verwijderen."
show:
has_private_exercises: "Deze cursus gebruikt privé oefeningen waartoe die geen rechten heeft."
course: Cursus
hidden_show_link: 'Geheime link'
visibility-visible_for_all-info: 'Deze cursus is zichtbaar voor iedereen: ze wordt opgelijst in het cursusoverzicht en de inhoud is toegankelijk voor iedereen.'
Expand Down Expand Up @@ -171,8 +172,6 @@ nl:
content_count: Leesactiviteiten
submitted_solutions: Ingediende oplossingen
more_statistics: "Meer statistieken >"
create:
added_private_exercises: "Er werden privé oefeningen toegevoegd tijdens het aanmaken van deze cursus. Om deze oefeningen te kunnen gebruiken zal deze cursus toestemming moeten krijgen van de relevante repository's."
copy_courses_table:
info: "Cursus"
users: "# gebruikers"
Expand Down Expand Up @@ -204,7 +203,7 @@ nl:
enable: Schakel vragen in.
disable: Schakel vragen uit.
ical:
serie_deadline: "Deadline voor %{serie_name} van cursus %{course_name}: %{serie_url}"
serie_deadline: "Deadline voor %{serie_name} van cursus %{course_name}: %{serie_url}"
submissions:
show:
questions:
Expand Down
11 changes: 11 additions & 0 deletions test/models/course_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,15 @@ class CourseTest < ActiveSupport::TestCase
assert course.destroy
assert_equal code, submission.reload.code
end

test 'all_activities_accessible? should be correct' do
course = create :course, series_count: 1, exercises_per_series: 0
ex = create :exercise, access: :public
course.series.first.exercises << ex
assert course.all_activities_accessible?
ex.update(access: :private)
assert_not course.all_activities_accessible?
course.usable_repositories << ex.repository
assert course.all_activities_accessible?
end
end

0 comments on commit b16e65c

Please sign in to comment.