diff --git a/website/announcements/tests/test_services.py b/website/announcements/tests/test_services.py index 8d7e3529..5e9938a3 100644 --- a/website/announcements/tests/test_services.py +++ b/website/announcements/tests/test_services.py @@ -6,22 +6,22 @@ class OrderServicesTests(TestCase): def test_sanitize_closed_announcements_none(self): - self.assertEquals([], sanitize_closed_announcements(None)) + self.assertEqual([], sanitize_closed_announcements(None)) def test_sanitize_closed_announcements_non_string(self): - self.assertEquals([], sanitize_closed_announcements(5)) + self.assertEqual([], sanitize_closed_announcements(5)) def test_sanitize_closed_announcements_non_json(self): - self.assertEquals([], sanitize_closed_announcements("this,is,not,json")) + self.assertEqual([], sanitize_closed_announcements("this,is,not,json")) def test_sanitize_closed_announcements_non_list(self): - self.assertEquals([], sanitize_closed_announcements("{}")) + self.assertEqual([], sanitize_closed_announcements("{}")) def test_sanitize_closed_announcements_list_of_ints(self): - self.assertEquals([1, 8, 4], sanitize_closed_announcements("[1, 8, 4]")) + self.assertEqual([1, 8, 4], sanitize_closed_announcements("[1, 8, 4]")) def test_sanitize_closed_announcements_list_of_different_types(self): - self.assertEquals( + self.assertEqual( [1, 8, 4], sanitize_closed_announcements('[1, "bla", 8, 4, 123.4, {"a": "b"}, ["This is also a list"]]') ) diff --git a/website/orders/api/v1/views.py b/website/orders/api/v1/views.py index 5046aaea..3b6484a9 100644 --- a/website/orders/api/v1/views.py +++ b/website/orders/api/v1/views.py @@ -21,7 +21,6 @@ from orders.models import Order, Shift, Product, OrderVenue from orders.services import ( user_can_manage_shifts_in_venue, - user_can_manage_shift, add_scanned_order, user_gets_prioritized_orders, ) @@ -62,7 +61,7 @@ def get_serializer_context(self): def perform_create(self, serializer): """Create an order, either as ordering users or as managers.""" shift = self.kwargs.get("shift") - if user_can_manage_shift(self.request.user, shift): + if user_can_manage_shifts_in_venue(self.request.user, shift.venue): # Save the order as it was passed to the API as the user has permission to save orders for all users in # the shift. order = serializer.save(shift=shift, user=self.request.user) @@ -117,7 +116,7 @@ class OrderRetrieveUpdateDestroyAPIView(LoggedRetrieveUpdateDestroyAPIView): def put(self, request, *args, **kwargs): """PUT is only available for shift managers.""" shift = self.kwargs.get("shift") - if user_can_manage_shift(request.user, shift): + if user_can_manage_shifts_in_venue(request.user, shift.venue): return super().put(request, *args, **kwargs) else: self.permission_denied(request) @@ -126,7 +125,7 @@ def update(self, request, *args, **kwargs): """Update an order.""" instance = self.get_object() shift = self.kwargs.get("shift") - if user_can_manage_shift(self.request.user, shift): + if user_can_manage_shifts_in_venue(request.user, shift.venue): # All changeable order fields can be changed by the user. return super().update(request, *args, **kwargs) else: @@ -155,7 +154,7 @@ def update(self, request, *args, **kwargs): def destroy(self, request, *args, **kwargs): """Destroy an order.""" shift = kwargs.get("shift") - if not user_can_manage_shift(request.user, shift): + if not user_can_manage_shifts_in_venue(request.user, shift.venue): self.permission_denied(request) return super().destroy(request, *args, **kwargs) @@ -230,7 +229,7 @@ class ShiftRetrieveUpdateAPIView(LoggedRetrieveUpdateAPIView): def update(self, request, *args, **kwargs): """Update a shift.""" shift = get_object_or_404(Shift, pk=kwargs.get("pk")) - if not user_can_manage_shift(request.user, shift): + if not user_can_manage_shifts_in_venue(request.user, shift.venue): self.permission_denied(request) return super().update(request, *args, **kwargs) @@ -282,7 +281,7 @@ def post(self, request, **kwargs): except Product.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) - if not user_can_manage_shift(request.user, shift): + if not user_can_manage_shifts_in_venue(request.user, shift.venue): raise PermissionDenied order = add_scanned_order(product, shift) diff --git a/website/orders/services.py b/website/orders/services.py index acf21bfa..1b1362bc 100644 --- a/website/orders/services.py +++ b/website/orders/services.py @@ -13,11 +13,6 @@ logger = logging.getLogger(__name__) -def user_can_manage_shift(user, shift): - """Return if the user can manage this shift.""" - return user_can_manage_shifts_in_venue(user, shift.venue) and user in shift.assignees.all() - - def user_can_manage_shifts_in_venue(user, venue): """Return if the user can manage this shift.""" return user.has_perm("orders.can_manage_shift_in_venue", venue) diff --git a/website/orders/templates/orders/join_shift.html b/website/orders/templates/orders/join_shift.html index 21fc3dbf..e4aa07ce 100644 --- a/website/orders/templates/orders/join_shift.html +++ b/website/orders/templates/orders/join_shift.html @@ -9,12 +9,12 @@
-

Join {{ shift.venue.venue.name }} shift #{{ shift.pk }}

+

Join/Manage {{ shift.venue.venue.name }} shift #{{ shift.pk }}

{% bootstrap_messages %}

Do you want to join this shift as a baker (add yourself to the baker list)?

{% csrf_token %} - {% bootstrap_button button_type="submit" name="confirm" value="Yes" content="Yes" button_class="btn-success" extra_classes="mt-4 w-100" %} - {% bootstrap_button button_type="submit" name="confirm" value="No" content="No" button_class="btn-danger" extra_classes="mt-4 w-100" %} + {% bootstrap_button button_type="submit" name="confirm" value="Yes" content="Yes, add me to the baker list" button_class="btn-success" extra_classes="mt-4 w-100" %} + {% bootstrap_button button_type="submit" name="confirm" value="No" content="No, I only want to manage" button_class="btn-danger" extra_classes="mt-4 w-100" %}
diff --git a/website/orders/templates/orders/shift_overview.html b/website/orders/templates/orders/shift_overview.html index 06fc5319..f090ed74 100644 --- a/website/orders/templates/orders/shift_overview.html +++ b/website/orders/templates/orders/shift_overview.html @@ -9,7 +9,7 @@ {% block footer %} {% if can_manage_shift and user not in shift.assignees.all %} -