Browse Source

Merge "Add support for a domain dropdown menu at login"

Jenkins 1 year ago
parent
commit
a1e421e0b7
2 changed files with 42 additions and 5 deletions
  1. 16
    5
      openstack_auth/forms.py
  2. 26
    0
      openstack_auth/tests/tests.py

+ 16
- 5
openstack_auth/forms.py View File

@@ -61,11 +61,22 @@ class Login(django_auth_forms.AuthenticationForm):
61 61
                    'OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT',
62 62
                    False):
63 63
             last_domain = self.request.COOKIES.get('login_domain', None)
64
-            self.fields['domain'] = forms.CharField(
65
-                initial=last_domain,
66
-                label=_("Domain"),
67
-                required=True,
68
-                widget=forms.TextInput(attrs={"autofocus": "autofocus"}))
64
+            if getattr(settings,
65
+                       'OPENSTACK_KEYSTONE_DOMAIN_DROPDOWN',
66
+                       False):
67
+                self.fields['domain'] = forms.ChoiceField(
68
+                    label=_("Domain"),
69
+                    initial=last_domain,
70
+                    required=True,
71
+                    choices=getattr(settings,
72
+                                    'OPENSTACK_KEYSTONE_DOMAIN_CHOICES',
73
+                                    ()))
74
+            else:
75
+                self.fields['domain'] = forms.CharField(
76
+                    initial=last_domain,
77
+                    label=_("Domain"),
78
+                    required=True,
79
+                    widget=forms.TextInput(attrs={"autofocus": "autofocus"}))
69 80
             self.fields['username'].widget = forms.widgets.TextInput()
70 81
             fields_ordering = ['domain', 'username', 'password', 'region']
71 82
         self.fields['region'].choices = self.get_region_choices()

+ 26
- 0
openstack_auth/tests/tests.py View File

@@ -1091,6 +1091,32 @@ class OpenStackAuthTestsV3(OpenStackAuthTestsMixin,
1091 1091
             token=unscoped.auth_token)
1092 1092
         self.assertEqual(project_list, expected_projects)
1093 1093
 
1094
+    def test_login_form_multidomain(self):
1095
+        override = self.settings(OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT=True)
1096
+        override.enable()
1097
+        self.addCleanup(override.disable)
1098
+
1099
+        url = reverse('login')
1100
+        response = self.client.get(url)
1101
+        self.assertEqual(response.status_code, 200)
1102
+        self.assertContains(response, 'name="domain" type="text"')
1103
+
1104
+    def test_login_form_multidomain_dropdown(self):
1105
+        override = self.settings(OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT=True,
1106
+                                 OPENSTACK_KEYSTONE_DOMAIN_DROPDOWN=True,
1107
+                                 OPENSTACK_KEYSTONE_DOMAIN_CHOICES=(
1108
+                                     ('Default', 'Default'),)
1109
+                                 )
1110
+        override.enable()
1111
+        self.addCleanup(override.disable)
1112
+
1113
+        url = reverse('login')
1114
+        response = self.client.get(url)
1115
+        self.assertEqual(response.status_code, 200)
1116
+        self.assertContains(response, 'select id="id_domain" name="domain"')
1117
+        self.assertContains(response, 'option value="Default"')
1118
+        settings.OPENSTACK_KEYSTONE_DOMAIN_DROPDOWN = False
1119
+
1094 1120
 
1095 1121
 class OpenStackAuthTestsWebSSO(OpenStackAuthTestsMixin,
1096 1122
                                OpenStackAuthFederatedTestsMixin,

Loading…
Cancel
Save