Skip to content

Commit

Permalink
Show button to change status on SignedAgreement detail pages
Browse files Browse the repository at this point in the history
  • Loading branch information
amstilp committed Sep 22, 2023
1 parent 1a2d5fe commit 662efcb
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 2 deletions.
123 changes: 123 additions & 0 deletions primed/cdsa/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,47 @@ def test_response_show_deprecation_message_not_valid(self):
self.assertTrue(response.context_data["show_deprecation_message"])
self.assertIn(b"Deprecated CDSA version", response.content)

def test_change_status_button_user_has_edit_perm(self):
"""Invalidate button appears when the user has edit permission and the instance is valid."""
user = User.objects.create_user(username="test_edit", password="test_edit")
user.user_permissions.add(
Permission.objects.get(
codename=AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME
)
)
user.user_permissions.add(
Permission.objects.get(
codename=AnVILProjectManagerAccess.EDIT_PERMISSION_CODENAME
)
)
self.client.force_login(user)
response = self.client.get(self.get_url(self.obj.signed_agreement.cc_id))
self.assertEqual(response.status_code, 200)
self.assertIn("show_update_button", response.context_data)
self.assertTrue(response.context_data["show_update_button"])
self.assertContains(
response,
reverse(
"cdsa:signed_agreements:members:update",
args=[self.obj.signed_agreement.cc_id],
),
)

def test_change_status_button_user_has_view_perm(self):
"""Invalidate button does not appear when the user has view permission and the instance is valid."""
self.client.force_login(self.user)
response = self.client.get(self.get_url(self.obj.signed_agreement.cc_id))
self.assertEqual(response.status_code, 200)
self.assertIn("show_update_button", response.context_data)
self.assertFalse(response.context_data["show_update_button"])
self.assertNotContains(
response,
reverse(
"cdsa:signed_agreements:members:update",
args=[self.obj.signed_agreement.cc_id],
),
)


class MemberAgreementListTest(TestCase):
"""Tests for the MemberAgreementList view."""
Expand Down Expand Up @@ -3430,6 +3471,47 @@ def test_response_show_deprecation_message_not_valid(self):
self.assertTrue(response.context_data["show_deprecation_message"])
self.assertIn(b"Deprecated CDSA version", response.content)

def test_change_status_button_user_has_edit_perm(self):
"""Invalidate button appears when the user has edit permission and the instance is valid."""
user = User.objects.create_user(username="test_edit", password="test_edit")
user.user_permissions.add(
Permission.objects.get(
codename=AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME
)
)
user.user_permissions.add(
Permission.objects.get(
codename=AnVILProjectManagerAccess.EDIT_PERMISSION_CODENAME
)
)
self.client.force_login(user)
response = self.client.get(self.get_url(self.obj.signed_agreement.cc_id))
self.assertEqual(response.status_code, 200)
self.assertIn("show_update_button", response.context_data)
self.assertTrue(response.context_data["show_update_button"])
self.assertContains(
response,
reverse(
"cdsa:signed_agreements:data_affiliates:update",
args=[self.obj.signed_agreement.cc_id],
),
)

def test_change_status_button_user_has_view_perm(self):
"""Invalidate button does not appear when the user has view permission and the instance is valid."""
self.client.force_login(self.user)
response = self.client.get(self.get_url(self.obj.signed_agreement.cc_id))
self.assertEqual(response.status_code, 200)
self.assertIn("show_update_button", response.context_data)
self.assertFalse(response.context_data["show_update_button"])
self.assertNotContains(
response,
reverse(
"cdsa:signed_agreements:data_affiliates:update",
args=[self.obj.signed_agreement.cc_id],
),
)


class DataAffiliateAgreementListTest(TestCase):
"""Tests for the DataAffiliateAgreement view."""
Expand Down Expand Up @@ -4434,6 +4516,47 @@ def test_response_show_deprecation_message_is_not_valid(self):
self.assertTrue(response.context_data["show_deprecation_message"])
self.assertIn(b"Deprecated CDSA version", response.content)

def test_change_status_button_user_has_edit_perm(self):
"""Invalidate button appears when the user has edit permission and the instance is valid."""
user = User.objects.create_user(username="test_edit", password="test_edit")
user.user_permissions.add(
Permission.objects.get(
codename=AnVILProjectManagerAccess.VIEW_PERMISSION_CODENAME
)
)
user.user_permissions.add(
Permission.objects.get(
codename=AnVILProjectManagerAccess.EDIT_PERMISSION_CODENAME
)
)
self.client.force_login(user)
response = self.client.get(self.get_url(self.obj.signed_agreement.cc_id))
self.assertEqual(response.status_code, 200)
self.assertIn("show_update_button", response.context_data)
self.assertTrue(response.context_data["show_update_button"])
self.assertContains(
response,
reverse(
"cdsa:signed_agreements:non_data_affiliates:update",
args=[self.obj.signed_agreement.cc_id],
),
)

def test_change_status_button_user_has_view_perm(self):
"""Invalidate button does not appear when the user has view permission and the instance is valid."""
self.client.force_login(self.user)
response = self.client.get(self.get_url(self.obj.signed_agreement.cc_id))
self.assertEqual(response.status_code, 200)
self.assertIn("show_update_button", response.context_data)
self.assertFalse(response.context_data["show_update_button"])
self.assertNotContains(
response,
reverse(
"cdsa:signed_agreements:non_data_affiliates:update",
args=[self.obj.signed_agreement.cc_id],
),
)


class NonDataAffiliateAgreementListTest(TestCase):
"""Tests for the NonDataAffiliateAgreement view."""
Expand Down
18 changes: 18 additions & 0 deletions primed/cdsa/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ def get_context_data(self, **kwargs):
context[
"show_deprecation_message"
] = not self.object.signed_agreement.version.major_version.is_valid
edit_permission_codename = "anvil_consortium_manager." + (
AnVILProjectManagerAccess.EDIT_PERMISSION_CODENAME
)
context["show_update_button"] = self.request.user.has_perm(
edit_permission_codename
)
return context


Expand Down Expand Up @@ -427,6 +433,12 @@ def get_context_data(self, **kwargs):
context[
"show_deprecation_message"
] = not self.object.signed_agreement.version.major_version.is_valid
edit_permission_codename = "anvil_consortium_manager." + (
AnVILProjectManagerAccess.EDIT_PERMISSION_CODENAME
)
context["show_update_button"] = self.request.user.has_perm(
edit_permission_codename
)
return context


Expand Down Expand Up @@ -476,6 +488,12 @@ def get_context_data(self, **kwargs):
context[
"show_deprecation_message"
] = not self.object.signed_agreement.version.major_version.is_valid
edit_permission_codename = "anvil_consortium_manager." + (
AnVILProjectManagerAccess.EDIT_PERMISSION_CODENAME
)
context["show_update_button"] = self.request.user.has_perm(
edit_permission_codename
)
return context


Expand Down
8 changes: 8 additions & 0 deletions primed/templates/cdsa/dataaffiliateagreement_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@

</dl>
{% endblock panel %}


{% block action_buttons %}
{% if show_update_button %}
<a href="{% url 'cdsa:signed_agreements:data_affiliates:update' cc_id=object.signed_agreement.cc_id %}" class="btn btn-primary" role="button">Update status</a>
</p>
{% endif %}
{% endblock action_buttons %}
8 changes: 8 additions & 0 deletions primed/templates/cdsa/memberagreement_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@

</dl>
{% endblock panel %}


{% block action_buttons %}
{% if show_update_button %}
<a href="{% url 'cdsa:signed_agreements:members:update' cc_id=object.signed_agreement.cc_id %}" class="btn btn-primary" role="button">Update status</a>
</p>
{% endif %}
{% endblock action_buttons %}
8 changes: 8 additions & 0 deletions primed/templates/cdsa/nondataaffiliateagreement_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@

</dl>
{% endblock panel %}


{% block action_buttons %}
{% if show_update_button %}
<a href="{% url 'cdsa:signed_agreements:non_data_affiliates:update' cc_id=object.signed_agreement.cc_id %}" class="btn btn-primary" role="button">Update status</a>
</p>
{% endif %}
{% endblock action_buttons %}
1 change: 0 additions & 1 deletion primed/templates/cdsa/signedagreement_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ <h1>{% block agreement_type_title %}{% endblock agreement_type_title %}</h1>

<button type="submit" class="btn btn-success">Save</button>
</form>

{% endblock content %}


Expand Down
2 changes: 1 addition & 1 deletion primed/templates/cdsa/signedagreement_status_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{% endblock panel %}

{% block after_panel %}
<div>
<div class="container m-3">
<form method="post">

{% csrf_token %}
Expand Down

0 comments on commit 662efcb

Please sign in to comment.