Skip to content

Commit

Permalink
DEFIVELO-221 Redirect planning to availability and reverse
Browse files Browse the repository at this point in the history
  • Loading branch information
OdyX committed Jul 8, 2021
1 parent 9c83480 commit d15bbd8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apps/challenge/tests/test_seasons.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ def test_access_to_myseason_availabilities(self):
self.assertEqual(
response.status_code, 200, urls["season-availabilities-update"]
)
elif state[0] == DV_SEASON_STATE_RUNNING:
# When possible, we redirect to planning
self.assertEqual(
response.status_code, 302, urls["season-availabilities-update"]
)
else:
self.assertEqual(
response.status_code, 403, urls["season-availabilities-update"]
Expand Down Expand Up @@ -211,6 +216,9 @@ def test_access_to_myseason_availabilities(self):
)
response = self.client.get(url, follow=True)
self.assertEqual(response.status_code, 200, url)
elif state[0] == DV_SEASON_STATE_OPEN:
# When possible, we redirect to availabilities
self.assertEqual(response.status_code, 302, urls["season-planning"])
else:
self.assertEqual(response.status_code, 403, urls["season-planning"])

Expand Down
48 changes: 48 additions & 0 deletions apps/challenge/views/season.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.messages import warning as warning_message
from django.contrib.messages.views import SuccessMessageMixin
from django.contrib.sites.models import Site
from django.core.exceptions import PermissionDenied
Expand Down Expand Up @@ -982,6 +983,30 @@ def dispatch(self, request, *args, **kwargs):
},
)
)

"""
DEFIVELO-221 If we're in the wrong state, redirect to the other URL; move from planning to availability
"""
if (
self.request.user.profile.is_paid_staff
and not self.season.staff_can_see_planning
and self.season.staff_can_update_availability
):
warning_message(
request,
_(
"Le planning n'est pas encore disponible; mets plutôt à jour tes disponibilités."
),
)
return HttpResponseRedirect(
reverse_lazy(
"season-availabilities-update",
kwargs={
"pk": self.season.pk,
"helperpk": self.request.user.pk,
},
)
)
except KeyError:
pass
return super().dispatch(request, *args, **kwargs)
Expand Down Expand Up @@ -1025,6 +1050,29 @@ def dispatch(self, request, *args, **kwargs):
},
)
)
"""
DEFIVELO-221 If we're in the wrong state, redirect to the other URL; move from planning to availability
"""
if (
self.request.user.profile.is_paid_staff
and not self.season.staff_can_update_availability
and self.season.staff_can_see_planning
):
warning_message(
request,
_(
"Il n'est pas possible de mettre à jour tes disponibilités; voici le planning."
),
)
return HttpResponseRedirect(
reverse_lazy(
"season-planning",
kwargs={
"pk": self.season.pk,
"helperpk": self.request.user.pk,
},
)
)
except KeyError:
pass
return super().dispatch(request, *args, **kwargs)
Expand Down

0 comments on commit d15bbd8

Please sign in to comment.