Browse Source

Merge "User email is optional and can be absent" into stable/grizzly

Jenkins 5 years ago
parent
commit
37b208a1a8

+ 2
- 1
openstack_dashboard/dashboards/admin/users/forms.py View File

@@ -113,7 +113,8 @@ class CreateUserForm(BaseUserForm):
113 113
 class UpdateUserForm(BaseUserForm):
114 114
     id = forms.CharField(label=_("ID"), widget=forms.HiddenInput)
115 115
     name = forms.CharField(label=_("User Name"))
116
-    email = forms.EmailField(label=_("Email"))
116
+    email = forms.EmailField(label=_("Email"),
117
+            required=False)
117 118
     password = forms.RegexField(label=_("Password"),
118 119
             widget=forms.PasswordInput(render_value=False),
119 120
             regex=validators.password_validator(),

+ 1
- 1
openstack_dashboard/dashboards/admin/users/tables.py View File

@@ -95,7 +95,7 @@ class UserFilterAction(tables.FilterAction):
95 95
         q = filter_string.lower()
96 96
         return [user for user in users
97 97
                 if q in user.name.lower()
98
-                or q in user.email.lower()]
98
+                or q in getattr(user, 'email', '').lower()]
99 99
 
100 100
 
101 101
 class UsersTable(tables.DataTable):

+ 25
- 11
openstack_dashboard/dashboards/admin/users/tests.py View File

@@ -166,22 +166,15 @@ class UsersViewTests(test.BaseAdminViewTests):
166 166
             res, "form", 'password',
167 167
             ['Password must be between 8 and 18 characters.'])
168 168
 
169
-    @test.create_stubs({api.keystone: ('user_get',
170
-                                       'tenant_list',
171
-                                       'user_update_tenant',
172
-                                       'user_update_password',
173
-                                       'user_update',
174
-                                       'roles_for_user', )})
175
-    def test_update(self):
176
-        user = self.users.get(id="1")
177
-
169
+    def _update(self, user):
170
+        email = getattr(user, 'email', '')
178 171
         api.keystone.user_get(IsA(http.HttpRequest), '1',
179 172
                      admin=True).AndReturn(user)
180 173
         api.keystone.tenant_list(IgnoreArg(),
181 174
                         admin=True).AndReturn(self.tenants.list())
182 175
         api.keystone.user_update(IsA(http.HttpRequest),
183 176
                                  user.id,
184
-                                 email=u'test@example.com',
177
+                                 email=email,
185 178
                                  name=u'test_user').AndReturn(None)
186 179
         api.keystone.user_update_tenant(IsA(http.HttpRequest),
187 180
                                user.id,
@@ -198,7 +191,7 @@ class UsersViewTests(test.BaseAdminViewTests):
198 191
         formData = {'method': 'UpdateUserForm',
199 192
                     'id': user.id,
200 193
                     'name': user.name,
201
-                    'email': user.email,
194
+                    'email': email,
202 195
                     'password': 'normalpwd',
203 196
                     'tenant_id': self.tenant.id,
204 197
                     'confirm_password': 'normalpwd'}
@@ -208,6 +201,27 @@ class UsersViewTests(test.BaseAdminViewTests):
208 201
         self.assertNoFormErrors(res)
209 202
         self.assertMessageCount(warning=1)
210 203
 
204
+    @test.create_stubs({api.keystone: ('user_get',
205
+                                       'tenant_list',
206
+                                       'user_update_tenant',
207
+                                       'user_update_password',
208
+                                       'user_update',
209
+                                       'roles_for_user', )})
210
+    def test_update(self):
211
+        user = self.users.get(id="1")
212
+        self._update(user)
213
+
214
+    @test.create_stubs({api.keystone: ('user_get',
215
+                                       'tenant_list',
216
+                                       'user_update_tenant',
217
+                                       'user_update_password',
218
+                                       'user_update',
219
+                                       'roles_for_user', )})
220
+    def test_update_with_no_email_attribute(self):
221
+        user = self.users.get(id="1")
222
+        del user.email
223
+        self._update(user)
224
+
211 225
     @test.create_stubs({api.keystone: ('user_get',
212 226
                                        'tenant_list',
213 227
                                        'user_update_tenant',

+ 1
- 1
openstack_dashboard/dashboards/admin/users/views.py View File

@@ -81,7 +81,7 @@ class UpdateView(forms.ModalFormView):
81 81
         return {'id': user.id,
82 82
                 'name': user.name,
83 83
                 'tenant_id': getattr(user, 'tenantId', None),
84
-                'email': user.email}
84
+                'email': getattr(user, 'email', None)}
85 85
 
86 86
 
87 87
 class CreateView(forms.ModalFormView):

Loading…
Cancel
Save