Skip to content

Commit

Permalink
Updated resignation views so that member office can view resignations…
Browse files Browse the repository at this point in the history
… but only vorstand and employees can create them.
  • Loading branch information
Theophile-Madet committed Nov 21, 2024
1 parent fa3911b commit 3e794ee
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 125 deletions.
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ django-auth-ldap = "^4.8.0"
djangorestframework = "^3.15.2"
django-vite = "^3.0.5"
django-cors-headers = "^4.5.0"
parameterized = "^0.9.0"

[tool.poetry.group.dev.dependencies]
black = "^24.8.0"
Expand Down
16 changes: 11 additions & 5 deletions tapir/coop/templates/coop/membership_resignation_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ <h5>{% translate "List of membership resignations" %} ({{ total_of_resigned_memb
</a>
{% endfor %}
</div>
<a class="{% tapir_button_link_to_action %}"
href="{% url 'coop:membership_resignation_create' %}">
<span class="material-icons">person_cancel</span>
{% translate "Resign new member" %}
</a>
{% blocktranslate asvar tooltip %}
Only the vorstand and the employees can create resignations.
{% endblocktranslate %}
<span data-bs-toggle="tooltip"
title="{% if not perms.resignation.manage %}{{ tooltip }}{% endif %}">
<a class="{% tapir_button_link_to_action %} {% if not perms.resignation.manage %}disabled{% endif %}"
href="{% url 'coop:membership_resignation_create' %}">
<span class="material-icons">person_cancel</span>
{% translate "Resign new member" %}
</a>
</span>
<button class="{% tapir_button_link_to_action %}"
type="button"
data-bs-toggle="collapse"
Expand Down
27 changes: 18 additions & 9 deletions tapir/coop/templates/coop/membershipresignation_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,25 @@ <h5 class="card-header">
</div>
</div>
<div class="card-footer d-flex justify-content-end gap-2">
<span class="{% tapir_button_custom 'danger' %}"
data-bs-toggle="modal"
data-bs-target="#confirmDeleteModal">
<span class="material-icons">cancel</span>Cancel resignation
{% blocktranslate asvar tooltip %}
Only the vorstand and the employees can edit resignations.
{% endblocktranslate %}
<span data-bs-toggle="tooltip"
title="{% if not perms.resignation.manage %}{{ tooltip }}{% endif %}">
<span class="{% tapir_button_custom 'danger' %} {% if not perms.resignation.manage %}disabled{% endif %}"
data-bs-toggle="modal"
data-bs-target="#confirmDeleteModal">
<span class="material-icons">cancel</span>Cancel resignation
</span>
</span>
<span data-bs-toggle="tooltip"
title="{% if not perms.resignation.manage %}{{ tooltip }}{% endif %}">
<a class="{% tapir_button_link_to_action %} {% if not perms.resignation.manage %}disabled{% endif %}"
href="{% url 'coop:membership_resignation_edit' object.pk %}">
<span class="material-icons">edit</span>
{% translate "Edit" %}
</a>
</span>
<a class="{% tapir_button_link_to_action %}"
href="{% url 'coop:membership_resignation_edit' object.pk %}">
<span class="material-icons">edit</span>
{% translate "Edit" %}
</a>
</div>
</div>
{% endblock content %}
34 changes: 17 additions & 17 deletions tapir/coop/tests/membership_resignation/test_create_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.core import mail
from django.urls import reverse

from tapir import settings
from tapir.coop.config import feature_flag_membership_resignation
from tapir.coop.emails.membershipresignation_confirmation_email import (
MembershipResignationConfirmation,
Expand All @@ -26,11 +27,12 @@
TapirFactoryTestBase,
mock_timezone_now,
TapirEmailTestMixin,
PermissionTestMixin,
)


class TestMembershipResignationCreateView(
FeatureFlagTestMixin, TapirEmailTestMixin, TapirFactoryTestBase
PermissionTestMixin, FeatureFlagTestMixin, TapirEmailTestMixin, TapirFactoryTestBase
):
NOW = datetime.datetime(year=2024, month=9, day=15)
TODAY = NOW.date()
Expand All @@ -40,19 +42,18 @@ def setUp(self) -> None:
self.given_feature_flag_value(feature_flag_membership_resignation, True)
mock_timezone_now(self, self.NOW)

def test_membershipResignationCreateView_loggedInAsNormalUser_accessDenied(self):
self.login_as_normal_user()
response = self.client.get(reverse("coop:membership_resignation_create"))
self.assertStatusCode(response, HTTPStatus.FORBIDDEN)
def get_allowed_groups(self):
return [
settings.GROUP_VORSTAND,
settings.GROUP_EMPLOYEES,
]

def test_membershipResignationCreateView_loggedInAsMemberOffice_accessGranted(self):
self.login_as_member_office_user()
response = self.client.get(reverse("coop:membership_resignation_create"))
self.assertStatusCode(response, HTTPStatus.OK)
def do_request(self):
return self.client.get(reverse("coop:membership_resignation_create"))

def test_membershipResignationCreateView_featureFlagDisabled_accessDenied(self):
self.given_feature_flag_value(feature_flag_membership_resignation, False)
self.login_as_member_office_user()
self.login_as_vorstand()
response = self.client.get(reverse("coop:membership_resignation_create"))
self.assertStatusCode(response, HTTPStatus.FORBIDDEN)

Expand Down Expand Up @@ -88,7 +89,7 @@ def test_membershipResignationCreateView_default_changesApplied(
mock_update_shifts_and_shares_and_pay_out_day: Mock,
mock_delete_shareowner_membershippauses: Mock,
):
actor = self.login_as_member_office_user()
actor = self.login_as_vorstand()
resignation = self.call_resignation_create_view(
MembershipResignation.ResignationType.GIFT_TO_COOP
)
Expand All @@ -99,7 +100,7 @@ def test_membershipResignationCreateView_default_changesApplied(
)

def test_membershipResignationCreateView_default_logEntryCreated(self):
actor = self.login_as_member_office_user()
actor = self.login_as_vorstand()
self.call_resignation_create_view(
MembershipResignation.ResignationType.GIFT_TO_COOP
)
Expand All @@ -111,7 +112,7 @@ def test_membershipResignationCreateView_default_logEntryCreated(self):
self.assertEqual(actor, log_entry.actor)

def test_membershipResignationCreateView_default_correctMailSent(self):
self.login_as_member_office_user()
self.login_as_vorstand()
member_to_resign = self.call_resignation_create_view(
MembershipResignation.ResignationType.GIFT_TO_COOP
)
Expand All @@ -127,9 +128,8 @@ def test_membershipResignationCreateView_default_correctMailSent(self):
def test_membershipResignationCreateView_resignationTypeTransfer_shareRecipientAlsoReceivesMails(
self,
):
self.login_as_member_office_user()
member_that_receives_shares = ShareOwnerFactory.create()
self.login_as_member_office_user()
self.login_as_vorstand()
resignation = self.call_resignation_create_view(
MembershipResignation.ResignationType.TRANSFER,
member_that_receives_shares,
Expand All @@ -153,7 +153,7 @@ def test_membershipResignationCreateView_resignationTypeTransfer_shareRecipientA
def test_membershipResignationCreateView_resignationTypeGiftToCoop_payOutDayIsSetCorrectly(
self,
):
self.login_as_member_office_user()
self.login_as_vorstand()
member_to_resign = self.call_resignation_create_view(
MembershipResignation.ResignationType.GIFT_TO_COOP
)
Expand All @@ -163,7 +163,7 @@ def test_membershipResignationCreateView_resignationTypeGiftToCoop_payOutDayIsSe
def test_membershipResignationCreateView_resignationTypeBuyBack_payOutDayIsSetCorrectly(
self,
):
self.login_as_member_office_user()
self.login_as_vorstand()
resignation = self.call_resignation_create_view(
MembershipResignation.ResignationType.BUY_BACK
)
Expand Down
38 changes: 20 additions & 18 deletions tapir/coop/tests/membership_resignation/test_delete_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from django.urls import reverse

from tapir import settings
from tapir.coop.config import feature_flag_membership_resignation
from tapir.coop.models import (
MembershipResignation,
Expand All @@ -15,35 +16,36 @@
from tapir.coop.tests.factories import (
MembershipResignationFactory,
)
from tapir.utils.tests_utils import FeatureFlagTestMixin, TapirFactoryTestBase
from tapir.utils.tests_utils import (
FeatureFlagTestMixin,
TapirFactoryTestBase,
PermissionTestMixin,
)


class TestMembershipResignationDeleteView(FeatureFlagTestMixin, TapirFactoryTestBase):
class TestMembershipResignationDeleteView(
PermissionTestMixin, FeatureFlagTestMixin, TapirFactoryTestBase
):
def setUp(self) -> None:
super().setUp()
self.given_feature_flag_value(feature_flag_membership_resignation, True)

def test_membershipResignationDeleteView_loggedInAsNormalUser_accessDenied(self):
self.login_as_normal_user()
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.post(
reverse("coop:membership_resignation_delete", args=[resignation.id]),
)
self.assertStatusCode(response, HTTPStatus.FORBIDDEN)
def get_allowed_groups(self):
return [
settings.GROUP_VORSTAND,
settings.GROUP_EMPLOYEES,
]

def test_membershipResignationDeleteView_loggedInAsMemberOffice_accessGranted(self):
self.login_as_member_office_user()
def do_request(self):
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.post(
return self.client.post(
reverse("coop:membership_resignation_delete", args=[resignation.id]),
follow=True,
)
self.assertStatusCode(response, HTTPStatus.FOUND)

def test_membershipResignationDeleteView_featureFlagDisabled_accessDenied(self):
self.given_feature_flag_value(feature_flag_membership_resignation, False)
self.login_as_member_office_user()
self.login_as_vorstand()
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.post(
Expand All @@ -56,7 +58,7 @@ def test_membershipResignationDeleteView_featureFlagDisabled_accessDenied(self):
def test_membershipResignationDeleteView_default_sharesEndDateSetToNone(
self, mock_on_resignation_deleted: Mock
):
self.login_as_member_office_user()
self.login_as_vorstand()
resignation: MembershipResignation = MembershipResignationFactory.create()
resignation.share_owner.share_ownerships.update(end_date=datetime.date.today())

Expand All @@ -69,7 +71,7 @@ def test_membershipResignationDeleteView_default_sharesEndDateSetToNone(
mock_on_resignation_deleted.assert_called_once_with(resignation)

def test_membershipResignationDeleteView_default_logEntryCreated(self):
actor = self.login_as_member_office_user()
actor = self.login_as_vorstand()
resignation: MembershipResignation = MembershipResignationFactory.create()
response = self.client.post(
reverse("coop:membership_resignation_delete", args=[resignation.id]),
Expand Down
35 changes: 17 additions & 18 deletions tapir/coop/tests/membership_resignation/test_detail_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@

from django.urls import reverse

from tapir import settings
from tapir.coop.config import feature_flag_membership_resignation
from tapir.coop.models import MembershipResignation
from tapir.coop.tests.factories import MembershipResignationFactory
from tapir.utils.tests_utils import FeatureFlagTestMixin, TapirFactoryTestBase
from tapir.utils.tests_utils import (
FeatureFlagTestMixin,
TapirFactoryTestBase,
PermissionTestMixin,
)


class TestMembershipResignationDetailView(FeatureFlagTestMixin, TapirFactoryTestBase):
class TestMembershipResignationDetailView(
PermissionTestMixin, FeatureFlagTestMixin, TapirFactoryTestBase
):

def test_membershipResignationDetailView_loggedInAsNormalUser_accessDenied(self):
self.given_feature_flag_value(feature_flag_membership_resignation, True)
self.login_as_normal_user()
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.get(
reverse("coop:membership_resignation_detail", args=[resignation.id])
)
def get_allowed_groups(self):
return [
settings.GROUP_VORSTAND,
settings.GROUP_EMPLOYEES,
settings.GROUP_MEMBER_OFFICE,
]

self.assertStatusCode(response, HTTPStatus.FORBIDDEN)

def test_membershipResignationDetailView_loggedInAsMemberOffice_accessGranted(self):
def do_request(self):
self.given_feature_flag_value(feature_flag_membership_resignation, True)
self.login_as_member_office_user()
resignation: MembershipResignation = MembershipResignationFactory.create()

response = self.client.get(
return self.client.get(
reverse("coop:membership_resignation_detail", args=[resignation.id])
)

self.assertStatusCode(response, HTTPStatus.OK)

def test_membershipResignationDetailView_featureFlagDisabled_accessDenied(self):
self.given_feature_flag_value(feature_flag_membership_resignation, False)
self.login_as_member_office_user()
Expand Down
Loading

0 comments on commit 3e794ee

Please sign in to comment.