-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2648] handle legacy case detail URLs with redirect
The case detail URL now contains a reference to the ZGW api group to be used to fetch the case. It is quite likely there are various hard-coded URLs in the wild (especially in notification emails) that point to the old case detail URLs. This commit adds a redirect handler for the now-deprecated case detail URL and tries to handle the request gracefully, depending on the case.
- Loading branch information
1 parent
1edaef7
commit f698c20
Showing
4 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/open_inwoner/openzaak/tests/test_case_detail_redirects.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from django.contrib.messages import get_messages | ||
from django.test import TestCase, override_settings | ||
from django.urls import reverse | ||
|
||
from open_inwoner.openzaak.models import ZGWApiGroupConfig | ||
from open_inwoner.openzaak.tests.factories import ZGWApiGroupConfigFactory | ||
|
||
|
||
@override_settings( | ||
ROOT_URLCONF="open_inwoner.cms.tests.urls", | ||
) | ||
class LegacyCaseDetailUrlRedirectTest(TestCase): | ||
def setUp(self): | ||
self.url_patterns = [ | ||
"case_detail", | ||
] | ||
|
||
def test_legacy_url_redirects_to_only_api_group_prefix(self): | ||
first = ZGWApiGroupConfigFactory() | ||
|
||
object_id = "test_object_id" | ||
legacy_handler_url = reverse( | ||
"cases:legacy_case_detail", | ||
kwargs={"object_id": object_id}, | ||
) | ||
target_url = reverse( | ||
"cases:case_detail", | ||
kwargs={"api_group_id": first.id, "object_id": object_id}, | ||
) | ||
|
||
response = self.client.get(legacy_handler_url) | ||
self.assertEqual(ZGWApiGroupConfig.objects.count(), 1) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response["Location"], target_url) | ||
|
||
def test_legacy_url_redirects_to_case_list_if_multiple_api_groups(self): | ||
ZGWApiGroupConfigFactory(), ZGWApiGroupConfigFactory() | ||
|
||
object_id = "test_object_id" | ||
legacy_handler_url = reverse( | ||
"cases:legacy_case_detail", | ||
kwargs={"object_id": object_id}, | ||
) | ||
target_url = reverse("cases:index") | ||
|
||
response = self.client.get(legacy_handler_url) | ||
messages = [str(m) for m in get_messages(response.wsgi_request)] | ||
|
||
self.assertEqual(ZGWApiGroupConfig.objects.count(), 2) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response["Location"], reverse("cases:index")) | ||
self.assertEqual( | ||
messages, | ||
[ | ||
"The link you clicked on has expired. Please find your case in the" | ||
" list below." | ||
], | ||
) | ||
|
||
def test_legacy_url_redirect_returns_404_on_missing_api_groups(self): | ||
object_id = "test_object_id" | ||
legacy_handler_url = reverse( | ||
"cases:legacy_case_detail", | ||
kwargs={"object_id": object_id}, | ||
) | ||
|
||
legacy_handler_url = reverse( | ||
"cases:legacy_case_detail", | ||
kwargs={"object_id": object_id}, | ||
) | ||
|
||
response = self.client.get(legacy_handler_url) | ||
self.assertEqual(ZGWApiGroupConfig.objects.count(), 0) | ||
self.assertEqual(response.status_code, 404) |