Skip to content

Commit

Permalink
Fix permissions in overridden ACM navbar template
Browse files Browse the repository at this point in the history
Use the new edit -> staff_edit permission in the overridden ACM
navbar template. Add tests to check that links only appear when
appropriate.
  • Loading branch information
amstilp committed Nov 9, 2023
1 parent a7ed5d2 commit d04de1e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions primed/primed_anvil/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,53 @@
User = get_user_model()


class ACMNavbarTest(TestCase):
"""Tests for the ACM navbar."""

def setUp(self):
"""Set up test class."""
self.factory = RequestFactory()
self.model_factory = factories.StudyFactory
# Create a user with both view and edit permission.
self.user = User.objects.create_user(username="test", password="test")
self.user.user_permissions.add(
Permission.objects.get(
codename=acm_models.AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME
)
)

def get_url(self, *args):
"""Get the url for the view being tested."""
return reverse("anvil_consortium_manager:index", args=args)

def test_staff_view_links(self):
user = UserFactory.create()
user.user_permissions.add(
Permission.objects.get(
codename=acm_models.AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME
)
)
self.client.force_login(user)
response = self.client.get(self.get_url())
self.assertNotContains(response, reverse("primed_anvil:studies:new"))

def test_staff_edit_links(self):
user = UserFactory.create()
user.user_permissions.add(
Permission.objects.get(
codename=acm_models.AnVILProjectManagerAccess.STAFF_VIEW_PERMISSION_CODENAME
)
)
user.user_permissions.add(
Permission.objects.get(
codename=acm_models.AnVILProjectManagerAccess.STAFF_EDIT_PERMISSION_CODENAME
)
)
self.client.force_login(user)
response = self.client.get(self.get_url())
self.assertContains(response, reverse("primed_anvil:studies:new"))


class HomeTest(TestCase):
"""Tests of the home page. This is maybe not the best place to put this test?"""

Expand Down
2 changes: 1 addition & 1 deletion primed/templates/anvil_consortium_manager/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<li>
<a class="dropdown-item" href="{% url 'primed_anvil:studies:list' %}">List studies</a>
</li>
{% if perms.anvil_consortium_manager.anvil_project_manager_edit %}
{% if perms.anvil_consortium_manager.anvil_consortium_manager_staff_edit %}
<li>
<a class="dropdown-item" href="{% url 'primed_anvil:studies:new' %}">Add a new study</a>
</li>
Expand Down

0 comments on commit d04de1e

Please sign in to comment.