Skip to content
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
8 changes: 7 additions & 1 deletion itou/www/employee_record_views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ def get_prefix(self, request, *args, **kwargs):

def check_wizard_state(self, *args, **kwargs):
step_url = kwargs.get("step", None)
if step_url != self.steps.current and step_url != "done":
if step_url is None:
# let the wizard redirect at the correct place
return
if step_url == "done" and self.steps.current == self.steps.last:
# it's okay, we can go to "done" step : the wizard will redirect to self.steps.last if needed
return
if step_url != self.steps.current:
# The user is accessing the wrong step (e.g. he tried to go back to the last step after finishing)
return HttpResponseRedirect(reverse("employee_record_views:add", kwargs={"step": self.steps.current}))

Expand Down
9 changes: 8 additions & 1 deletion tests/www/employee_record_views/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def test_wizard(snapshot, client):
)
assertRedirects(response, choose_approval_url)

# Force step 2 even if the user tries to skip it
response = client.get(end_url)
assertRedirects(response, choose_approval_url)

# Submit data for the "choose-approval" step
soup = parse_response_to_soup(client.get(choose_approval_url), selector="#main .s-section")
assert soup.find(id="id_choose-approval-approval").option["value"] == str(approval.pk)
Expand All @@ -77,12 +81,15 @@ def test_wizard(snapshot, client):

assertRedirects(response, end_url, fetch_redirect_response=False)
# get end_url to clear the wizard data
client.get(end_url)
client.get(end_url, follow=True)

# Don't crash when going back to last step
response = client.get(choose_approval_url)
assertRedirects(response, choose_employee_url)

response = client.get(end_url)
assertRedirects(response, choose_employee_url)


def test_done_step_when_the_employee_record_need_to_be_created(client):
company = CompanyFactory(with_membership=True)
Expand Down