From c80d7e32ef43608eb50e47cc2b5cc6a8b49ba4fe Mon Sep 17 00:00:00 2001 From: Vadym Markov Date: Mon, 26 Jul 2021 18:46:02 +0300 Subject: [PATCH] Add POST/Redirect/GET for Domains dashboard Currently, "Set Domain Context" and "Clear Domain Context" doesn't do PRG, so page reload after these actions produce browser popup about form re-submission. Proposed patch fixes it Change-Id: I80d11cbdd42224456ee3a354ebad556a318ba03a --- .../dashboards/identity/domains/tables.py | 4 ++++ .../dashboards/identity/domains/tests.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/openstack_dashboard/dashboards/identity/domains/tables.py b/openstack_dashboard/dashboards/identity/domains/tables.py index bd885a6951..e0588accc7 100644 --- a/openstack_dashboard/dashboards/identity/domains/tables.py +++ b/openstack_dashboard/dashboards/identity/domains/tables.py @@ -15,6 +15,7 @@ import logging from django.conf import settings +from django import shortcuts from django.template import defaultfilters as filters from django.urls import reverse from django.utils.http import urlencode @@ -246,9 +247,11 @@ class SetDomainContext(tables.Action): messages.success(request, _('Domain Context updated to Domain %s.') % domain.name) + return shortcuts.redirect(request.get_full_path()) except Exception: messages.error(request, _('Unable to set Domain Context.')) + return shortcuts.redirect(request.get_full_path()) class UnsetDomainContext(tables.Action): @@ -268,6 +271,7 @@ class UnsetDomainContext(tables.Action): request.session.pop("domain_context") request.session.pop("domain_context_name") messages.success(request, _('Domain Context cleared.')) + return shortcuts.redirect(request.get_full_path()) class DomainsTable(tables.DataTable): diff --git a/openstack_dashboard/dashboards/identity/domains/tests.py b/openstack_dashboard/dashboards/identity/domains/tests.py index af9ae709f3..b07a171300 100644 --- a/openstack_dashboard/dashboards/identity/domains/tests.py +++ b/openstack_dashboard/dashboards/identity/domains/tests.py @@ -153,15 +153,21 @@ class DomainsViewTests(test.BaseAdminViewTests): self.mock_domain_list.return_value = self.domains.list() formData = {'action': 'domains__set_domain_context__%s' % domain.id} - res = self.client.post(DOMAINS_INDEX_URL, formData) + res = self.client.post(DOMAINS_INDEX_URL, formData, follow=True) + self.assertRedirects(res, DOMAINS_INDEX_URL, status_code=302, + target_status_code=200, + fetch_redirect_response=True) self.assertTemplateUsed(res, constants.DOMAINS_INDEX_VIEW_TEMPLATE) self.assertCountEqual(res.context['table'].data, [domain, ]) self.assertContains(res, "another_test_domain:") formData = {'action': 'domains__clear_domain_context__%s' % domain.id} - res = self.client.post(DOMAINS_INDEX_URL, formData) + res = self.client.post(DOMAINS_INDEX_URL, formData, follow=True) + self.assertRedirects(res, DOMAINS_INDEX_URL, status_code=302, + target_status_code=200, + fetch_redirect_response=True) self.assertTemplateUsed(res, constants.DOMAINS_INDEX_VIEW_TEMPLATE) self.assertCountEqual(res.context['table'].data, self.domains.list()) self.assertNotContains(res, "test_domain:")