From 74845558ac8d50004f8ab57d33322c8ee48ffd75 Mon Sep 17 00:00:00 2001 From: carofun Date: Tue, 7 Jun 2022 17:43:12 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(forum)=20list=20forums=20of=20the=20c?= =?UTF-8?q?ourse=20to=20be=20locked?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the intructor wants to lock the forums of the course, we give the list of forums of the course as a reminder. --- CHANGELOG.md | 5 +++ src/ashley/machina_extensions/forum/views.py | 17 +++++++++- src/ashley/templates/forum/forum_lock.html | 4 +-- tests/ashley/test_course_locked.py | 34 ++++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38c7319c..04a4bc34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- Show the listing of forums part of the course that would be locked if CTA is + confirmed + ## [1.2.0] - 2022-05-16 ### Added diff --git a/src/ashley/machina_extensions/forum/views.py b/src/ashley/machina_extensions/forum/views.py index 2963698e..ce6cc739 100644 --- a/src/ashley/machina_extensions/forum/views.py +++ b/src/ashley/machina_extensions/forum/views.py @@ -256,6 +256,20 @@ class ForumLockCourseView(PermissionRequiredMixin, UpdateView): fields = ["lti_contexts"] template_name = "forum/forum_lock.html" + def get_list_forums(self): + """Returns the list of forums of this course""" + return Forum.objects.filter( + lti_contexts=self.get_object().lti_contexts.get( + id=self.request.forum_permission_handler.current_lti_context_id + ) + ) + + def get_context_data(self, **kwargs): + """Sends list_forum to the view""" + context = super().get_context_data() + context["list_forum"] = self.get_list_forums() + return context + def get_success_url(self): """Returns the success URL to redirect the user to.""" return reverse("forum:index") @@ -277,13 +291,14 @@ def post(self, request, *args, **kwargs): We lock all forums of this course. Default group shouldn't have writing permissions anymore. The LTIContex will then be marked as blocked. """ + lti_context = self.get_object().lti_contexts.get( id=self.request.forum_permission_handler.current_lti_context_id ) default_group = lti_context.get_base_group() # remove all permissions for each forum of this LTIContext - for forum in Forum.objects.filter(lti_contexts=lti_context): + for forum in self.get_list_forums(): # pylint: disable=not-an-iterable for perm in DEFAULT_FORUM_BASE_WRITE_PERMISSIONS: remove_perm(perm, default_group, forum) diff --git a/src/ashley/templates/forum/forum_lock.html b/src/ashley/templates/forum/forum_lock.html index d8843a9a..b422ca50 100644 --- a/src/ashley/templates/forum/forum_lock.html +++ b/src/ashley/templates/forum/forum_lock.html @@ -13,9 +13,7 @@

{% trans "Lock the forum" %}

{% trans "Are you sure you want to lock the entire course? All the forums in this course will be locked." %}

-

- {{ object.name }} -

+ {% for forum in list_forum %}

{{ forum.name }}

{% endfor %}

{% csrf_token %}
diff --git a/tests/ashley/test_course_locked.py b/tests/ashley/test_course_locked.py index f21f0980..593bf756 100644 --- a/tests/ashley/test_course_locked.py +++ b/tests/ashley/test_course_locked.py @@ -769,3 +769,37 @@ def test_is_marked_locked_set_in_the_back(self): ).values_list("permission__codename", flat=True) ), ) + + def test_course_create_multiple_forums_listing_on(self): + """ + Instructor wants to lock the course that has multiple forums. + The list of forums should be displayed before the confirmation's + button. + """ + forum1 = self._connects("instructor") + forum2 = ForumFactory(name="Forum2") + forum3 = ForumFactory(name="Forum3") + # connects user and add forums to the lti_context + forum2 = self._connects("instructor", forum_uuid=forum2.lti_id) + forum3 = self._connects("instructor", forum_uuid=forum3.lti_id) + + # go on the page to lock the course from the forum1 + response = self.client.get(f"/forum/admin/lock-course/{forum1.id}/") + self.assertEqual(200, response.status_code) + # this listing is common for all the forums of the course + forums_list = ( + f'

{forum1.name}

' + '

Forum2

' + '

Forum3

' + ) + self.assertContains(response, forums_list) + + # go on the page to lock the course from the forum2 + response = self.client.get(f"/forum/admin/lock-course/{forum2.id}/") + self.assertEqual(200, response.status_code) + self.assertContains(response, forums_list) + + # go on the page to lock the course from the forum3 + response = self.client.get(f"/forum/admin/lock-course/{forum3.id}/") + self.assertEqual(200, response.status_code) + self.assertContains(response, forums_list)