User email is optional and can be absent
cherry-picked fromfaf5b2aead
cherry-picked from19566878b2
Change-Id: Idff0f7c33bcaee29c7d1e7be415eb6b5b29b5b1a Related-Bug: #1260423
This commit is contained in:
parent
117ac2f22c
commit
3212dd0373
@ -113,7 +113,8 @@ class CreateUserForm(BaseUserForm):
|
|||||||
class UpdateUserForm(BaseUserForm):
|
class UpdateUserForm(BaseUserForm):
|
||||||
id = forms.CharField(label=_("ID"), widget=forms.HiddenInput)
|
id = forms.CharField(label=_("ID"), widget=forms.HiddenInput)
|
||||||
name = forms.CharField(label=_("User Name"))
|
name = forms.CharField(label=_("User Name"))
|
||||||
email = forms.EmailField(label=_("Email"))
|
email = forms.EmailField(label=_("Email"),
|
||||||
|
required=False)
|
||||||
password = forms.RegexField(label=_("Password"),
|
password = forms.RegexField(label=_("Password"),
|
||||||
widget=forms.PasswordInput(render_value=False),
|
widget=forms.PasswordInput(render_value=False),
|
||||||
regex=validators.password_validator(),
|
regex=validators.password_validator(),
|
||||||
|
@ -95,7 +95,7 @@ class UserFilterAction(tables.FilterAction):
|
|||||||
q = filter_string.lower()
|
q = filter_string.lower()
|
||||||
return [user for user in users
|
return [user for user in users
|
||||||
if q in user.name.lower()
|
if q in user.name.lower()
|
||||||
or q in user.email.lower()]
|
or q in getattr(user, 'email', '').lower()]
|
||||||
|
|
||||||
|
|
||||||
class UsersTable(tables.DataTable):
|
class UsersTable(tables.DataTable):
|
||||||
|
@ -166,22 +166,15 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
res, "form", 'password',
|
res, "form", 'password',
|
||||||
['Password must be between 8 and 18 characters.'])
|
['Password must be between 8 and 18 characters.'])
|
||||||
|
|
||||||
@test.create_stubs({api.keystone: ('user_get',
|
def _update(self, user):
|
||||||
'tenant_list',
|
email = getattr(user, 'email', '')
|
||||||
'user_update_tenant',
|
|
||||||
'user_update_password',
|
|
||||||
'user_update',
|
|
||||||
'roles_for_user', )})
|
|
||||||
def test_update(self):
|
|
||||||
user = self.users.get(id="1")
|
|
||||||
|
|
||||||
api.keystone.user_get(IsA(http.HttpRequest), '1',
|
api.keystone.user_get(IsA(http.HttpRequest), '1',
|
||||||
admin=True).AndReturn(user)
|
admin=True).AndReturn(user)
|
||||||
api.keystone.tenant_list(IgnoreArg(),
|
api.keystone.tenant_list(IgnoreArg(),
|
||||||
admin=True).AndReturn(self.tenants.list())
|
admin=True).AndReturn(self.tenants.list())
|
||||||
api.keystone.user_update(IsA(http.HttpRequest),
|
api.keystone.user_update(IsA(http.HttpRequest),
|
||||||
user.id,
|
user.id,
|
||||||
email=u'test@example.com',
|
email=email,
|
||||||
name=u'test_user').AndReturn(None)
|
name=u'test_user').AndReturn(None)
|
||||||
api.keystone.user_update_tenant(IsA(http.HttpRequest),
|
api.keystone.user_update_tenant(IsA(http.HttpRequest),
|
||||||
user.id,
|
user.id,
|
||||||
@ -198,7 +191,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
formData = {'method': 'UpdateUserForm',
|
formData = {'method': 'UpdateUserForm',
|
||||||
'id': user.id,
|
'id': user.id,
|
||||||
'name': user.name,
|
'name': user.name,
|
||||||
'email': user.email,
|
'email': email,
|
||||||
'password': 'normalpwd',
|
'password': 'normalpwd',
|
||||||
'tenant_id': self.tenant.id,
|
'tenant_id': self.tenant.id,
|
||||||
'confirm_password': 'normalpwd'}
|
'confirm_password': 'normalpwd'}
|
||||||
@ -208,6 +201,27 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
self.assertNoFormErrors(res)
|
self.assertNoFormErrors(res)
|
||||||
self.assertMessageCount(warning=1)
|
self.assertMessageCount(warning=1)
|
||||||
|
|
||||||
|
@test.create_stubs({api.keystone: ('user_get',
|
||||||
|
'tenant_list',
|
||||||
|
'user_update_tenant',
|
||||||
|
'user_update_password',
|
||||||
|
'user_update',
|
||||||
|
'roles_for_user', )})
|
||||||
|
def test_update(self):
|
||||||
|
user = self.users.get(id="1")
|
||||||
|
self._update(user)
|
||||||
|
|
||||||
|
@test.create_stubs({api.keystone: ('user_get',
|
||||||
|
'tenant_list',
|
||||||
|
'user_update_tenant',
|
||||||
|
'user_update_password',
|
||||||
|
'user_update',
|
||||||
|
'roles_for_user', )})
|
||||||
|
def test_update_with_no_email_attribute(self):
|
||||||
|
user = self.users.get(id="1")
|
||||||
|
del user.email
|
||||||
|
self._update(user)
|
||||||
|
|
||||||
@test.create_stubs({api.keystone: ('user_get',
|
@test.create_stubs({api.keystone: ('user_get',
|
||||||
'tenant_list',
|
'tenant_list',
|
||||||
'user_update_tenant',
|
'user_update_tenant',
|
||||||
|
@ -81,7 +81,7 @@ class UpdateView(forms.ModalFormView):
|
|||||||
return {'id': user.id,
|
return {'id': user.id,
|
||||||
'name': user.name,
|
'name': user.name,
|
||||||
'tenant_id': getattr(user, 'tenantId', None),
|
'tenant_id': getattr(user, 'tenantId', None),
|
||||||
'email': user.email}
|
'email': getattr(user, 'email', None)}
|
||||||
|
|
||||||
|
|
||||||
class CreateView(forms.ModalFormView):
|
class CreateView(forms.ModalFormView):
|
||||||
|
Loading…
Reference in New Issue
Block a user