From b16e65cddc5aec4c023390db4c2020cccda376de Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Fri, 8 Oct 2021 16:27:56 +0200 Subject: [PATCH] Show warning about inaccessible activities to course admins on course show --- app/controllers/courses_controller.rb | 4 +++- app/models/course.rb | 4 ++++ config/locales/views/courses/en.yml | 3 +-- config/locales/views/courses/nl.yml | 5 ++--- test/models/course_test.rb | 11 +++++++++++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index dfb8d9fafd..862da92a3e 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -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 @@ -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 } diff --git a/app/models/course.rb b/app/models/course.rb index a98676dea3..eb98f95db0 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -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 diff --git a/config/locales/views/courses/en.yml b/config/locales/views/courses/en.yml index c8f3db212d..11c628025b 100644 --- a/config/locales/views/courses/en.yml +++ b/config/locales/views/courses/en.yml @@ -88,6 +88,7 @@ en: other: "You can't remove a course with more than %{count} submissions yourself." contact_html: "Contact us 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." @@ -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" diff --git a/config/locales/views/courses/nl.yml b/config/locales/views/courses/nl.yml index a9266d9651..928ffcbdf5 100644 --- a/config/locales/views/courses/nl.yml +++ b/config/locales/views/courses/nl.yml @@ -96,6 +96,7 @@ nl: other: "Je kan een cursus met meer dan %{count} oplossingen niet zelf verwijderen." contact_html: "Contacteer ons 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.' @@ -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" @@ -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: diff --git a/test/models/course_test.rb b/test/models/course_test.rb index 65973fe5bb..b9c9046f2b 100644 --- a/test/models/course_test.rb +++ b/test/models/course_test.rb @@ -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