Skip to content

Commit

Permalink
✨(forum) list forums of the course to be locked
Browse files Browse the repository at this point in the history
When the intructor wants to lock the forums of the course, we give
the list of forums of the course as a reminder.
  • Loading branch information
carofun committed Jun 8, 2022
1 parent 5846b24 commit 7484555
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion src/ashley/machina_extensions/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/ashley/templates/forum/forum_lock.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ <h3 class="m-0 h5 card-title">{% trans "Lock the forum" %}</h3>
<div class="card-body">
<div class="mb-3 warning-message">
<p>{% trans "Are you sure you want to lock the entire course? All the forums in this course will be locked." %}</p>
<p class="ml-3 pb-3">
<strong>{{ object.name }}</strong>
<p>
{% for forum in list_forum %}<p class="ml-3 pb-3"><strong>{{ forum.name }}</strong><p>{% endfor %}
</div>
<form method="post" action="." class="form" enctype="multipart/form-data" novalidate>{% csrf_token %}
<div class="row">
Expand Down
34 changes: 34 additions & 0 deletions tests/ashley/test_course_locked.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<p class="ml-3 pb-3"><strong>{forum1.name}</strong><p>'
'<p class="ml-3 pb-3"><strong>Forum2</strong><p>'
'<p class="ml-3 pb-3"><strong>Forum3</strong><p>'
)
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)

0 comments on commit 7484555

Please sign in to comment.