Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2490 - SPIKE: Research students unable to submit updates/content to their profiles #933

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions rca/people/templates/admin/panels/student_page_inline_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
{% comment "Always render the formset so the form can be saved" %}{% endcomment %}
{{ self.formset.management_form }}

{% comment "Hide the visibe form fields to non-superusers" %}{% endcomment %}
{% if request.user.is_superuser %}

{% comment %}
Hide the visible form fields to non-superusers. We only want to toggle the visibility since
the fields must still exist in the template so it's part of the POSTed data.
{% endcomment %}
<div {% if not request.user.is_superuser %}style="display: none;"{% endif %}>
<ul class="multiple" id="id_{{ self.formset.prefix }}-FORMS">
{% if self.formset.non_form_errors %}
<li class="error-message">
Expand Down Expand Up @@ -50,5 +52,4 @@
panel.updateAddButtonState();
})();
</script>

{% endif %}
</div>
57 changes: 57 additions & 0 deletions rca/people/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,60 @@ def test_create_page_validation_no_collection(self):
"If you are adding a student user account so a student can access "
"this page, an image collection must be added.",
)


class TestStudentPageEdit(TestCase, WagtailTestUtils):

create_view_name = "student_account_create"

def setUp(self):
super().setUp()
self.student = UserFactory(username="student")
self.user = UserFactory(is_superuser=True)
self.student_group = Group.objects.get(name="Students")
admin_permission = Permission.objects.get(codename="access_admin")
self.student_group.permissions.add(admin_permission)
self.student.groups.add(self.student_group)
self.student.set_password("test")
self.student.save()

self.home_page = HomePage.objects.first()
self.home_page.add_child(
instance=StudentIndexPage(
title="Students",
slug="students",
introduction="students",
)
)
self.student_index = StudentIndexPage.objects.first()
GroupPagePermission.objects.create(
group=self.student_group,
page=self.student_index,
permission_type="edit",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @patrickcuagan I needed to revert this work as it was pushed to dev and causing problem with deploying the Wagtail 5.1 upgrade to dev for testing.

My suggestion here is untested but reflects the changes required here: https://docs.wagtail.org/en/stable/releases/5.1.html#grouppagepermission-now-uses-django-s-permission-model

Suggested change
permission_type="edit",
permission=Permission.objects.get(
content_type__app_label="wagtailcore", codename="change_page"
)

It may be best to wait until the 5.1 upgrade has been deployed and the rebase your work to see the error in the test.

)
self.student_index.add_child(
instance=StudentPage(
title="A student", slug="a-student", first_name="a", last_name="student"
)
)
self.student_page = StudentPage.objects.first()

self.url = reverse("wagtailadmin_pages:edit", args=(self.student_page.id,))

def test_related_school_fields_should_be_in_page(self):
# As a superuser, there should be an option to add related schools and I should see it.
self.client.force_login(self.user)
response = self.client.get(self.url)
self.assertContains(response, "Add related schools")
self.assertContains(
response, '<div >\n <ul class="multiple" id="id_related_schools-FORMS">'
)

# As a student, I shouldn't see it but it should still be in the template.
self.client.force_login(self.student)
response = self.client.get(self.url)
self.assertContains(response, "Add related schools")
self.assertContains(
response,
'<div style="display: none;">\n <ul class="multiple" id="id_related_schools-FORMS">',
)