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

Start May Small Update #803

Merged
merged 16 commits into from
May 1, 2024
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

## Neste versjon

## Versjon 2024.05.01
- ⚡**Påmelding**. En bruker som har betalt for en påmelding på et arrangement kan ikke lenger melde seg av.

## Versjon 2024.04.16
- ✨ **Brukerbio**. Bruker kan nå opprette bio.

Expand Down
11 changes: 9 additions & 2 deletions app/content/util/registration_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from datetime import datetime, timedelta


def get_payment_expiredate():
return datetime.now() + timedelta(hours=12)
def get_payment_expiredate(event=None):
if not event:
return datetime.now() + timedelta(hours=12)

return datetime.now() + timedelta(
hours=event.paid_information.paytime.hour,
minutes=event.paid_information.paytime.minute,
seconds=event.paid_information.paytime.second,
)
17 changes: 17 additions & 0 deletions app/content/views/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from app.content.util.event_utils import start_payment_countdown
from app.payment.enums import OrderStatus
from app.payment.models.order import Order
from app.payment.util.order_utils import has_paid_order


class RegistrationViewSet(APIRegistrationErrorsMixin, BaseViewSet):
Expand Down Expand Up @@ -121,11 +122,27 @@ def destroy(self, request, *args, **kwargs):

def _unregister(self, registration):
self._log_on_destroy(registration)

if self._registration_is_paid(registration):
return Response(
{
"detail": "Du kan ikke melde deg av et arrangement du har betalt for."
},
status=status.HTTP_400_BAD_REQUEST,
)

registration.delete()
return Response(
{"detail": "Du har blitt meldt av arrangementet"}, status=status.HTTP_200_OK
)

def _registration_is_paid(self, registration):
event = registration.event
if event.is_paid_event:
orders = event.orders.filter(user=registration.user)
return has_paid_order(orders)
return False

def _admin_unregister(self, registration):
self._log_on_destroy(registration)
registration.admin_unregister()
Expand Down
38 changes: 38 additions & 0 deletions app/tests/content/test_registration_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from app.forms.enums import EventFormType
from app.forms.tests.form_factories import EventFormFactory, SubmissionFactory
from app.group.factories import GroupFactory
from app.payment.enums import OrderStatus
from app.util.test_utils import add_user_to_group_with_name, get_api_client
from app.util.utils import now

Expand Down Expand Up @@ -1031,3 +1032,40 @@ def test_add_registration_to_event_as_member(member, event):
response = client.post(url, data)

assert response.status_code == status.HTTP_403_FORBIDDEN


@pytest.mark.django_db
@pytest.mark.parametrize(
("order_status", "status_code"),
[
(OrderStatus.SALE, status.HTTP_400_BAD_REQUEST),
(OrderStatus.CAPTURE, status.HTTP_400_BAD_REQUEST),
(OrderStatus.RESERVED, status.HTTP_400_BAD_REQUEST),
(OrderStatus.CANCEL, status.HTTP_200_OK),
(OrderStatus.INITIATE, status.HTTP_200_OK),
(OrderStatus.REFUND, status.HTTP_200_OK),
(OrderStatus.VOID, status.HTTP_200_OK),
],
)
def test_delete_registration_with_paid_order_as_self(
member, event, order, paid_event, order_status, status_code
):
"""
A member should not be able to delete their registration if they have a paid order.
"""

order.status = order_status
order.event = event
order.user = member
order.save()

paid_event.event = event
paid_event.save()

registration = RegistrationFactory(user=member, event=event)
client = get_api_client(user=member)

url = _get_registration_detail_url(registration)
response = client.delete(url)

assert response.status_code == status_code
Loading