Merge "Add description field in the user table"
This commit is contained in:
commit
fbad227f33
@ -312,7 +312,7 @@ def user_list(request, project=None, domain=None, group=None, filters=None):
|
|||||||
|
|
||||||
|
|
||||||
def user_create(request, name=None, email=None, password=None, project=None,
|
def user_create(request, name=None, email=None, password=None, project=None,
|
||||||
enabled=None, domain=None):
|
enabled=None, domain=None, description=None):
|
||||||
manager = keystoneclient(request, admin=True).users
|
manager = keystoneclient(request, admin=True).users
|
||||||
try:
|
try:
|
||||||
if VERSIONS.active < 3:
|
if VERSIONS.active < 3:
|
||||||
@ -321,7 +321,7 @@ def user_create(request, name=None, email=None, password=None, project=None,
|
|||||||
else:
|
else:
|
||||||
return manager.create(name, password=password, email=email,
|
return manager.create(name, password=password, email=email,
|
||||||
project=project, enabled=enabled,
|
project=project, enabled=enabled,
|
||||||
domain=domain)
|
domain=domain, description=description)
|
||||||
except keystone_exceptions.Conflict:
|
except keystone_exceptions.Conflict:
|
||||||
raise exceptions.Conflict()
|
raise exceptions.Conflict()
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ from horizon.utils import validators
|
|||||||
|
|
||||||
from openstack_dashboard import api
|
from openstack_dashboard import api
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
PROJECT_REQUIRED = api.keystone.VERSIONS.active < 3
|
PROJECT_REQUIRED = api.keystone.VERSIONS.active < 3
|
||||||
|
|
||||||
@ -95,6 +94,10 @@ class CreateUserForm(PasswordMixin, BaseUserForm):
|
|||||||
required=False,
|
required=False,
|
||||||
widget=forms.HiddenInput())
|
widget=forms.HiddenInput())
|
||||||
name = forms.CharField(max_length=255, label=_("User Name"))
|
name = forms.CharField(max_length=255, label=_("User Name"))
|
||||||
|
description = forms.CharField(widget=forms.widgets.Textarea(
|
||||||
|
attrs={'rows': 4}),
|
||||||
|
label=_("Description"),
|
||||||
|
required=False)
|
||||||
email = forms.EmailField(
|
email = forms.EmailField(
|
||||||
label=_("Email"),
|
label=_("Email"),
|
||||||
required=False)
|
required=False)
|
||||||
@ -108,7 +111,8 @@ class CreateUserForm(PasswordMixin, BaseUserForm):
|
|||||||
roles = kwargs.pop('roles')
|
roles = kwargs.pop('roles')
|
||||||
super(CreateUserForm, self).__init__(*args, **kwargs)
|
super(CreateUserForm, self).__init__(*args, **kwargs)
|
||||||
# Reorder form fields from multiple inheritance
|
# Reorder form fields from multiple inheritance
|
||||||
ordering = ["domain_id", "domain_name", "name", "email", "password",
|
ordering = ["domain_id", "domain_name", "name",
|
||||||
|
"description", "email", "password",
|
||||||
"confirm_password", "project", "role_id"]
|
"confirm_password", "project", "role_id"]
|
||||||
# Starting from 1.7 Django uses OrderedDict for fields and keyOrder
|
# Starting from 1.7 Django uses OrderedDict for fields and keyOrder
|
||||||
# no longer works for it
|
# no longer works for it
|
||||||
@ -125,6 +129,9 @@ class CreateUserForm(PasswordMixin, BaseUserForm):
|
|||||||
readonlyInput = forms.TextInput(attrs={'readonly': 'readonly'})
|
readonlyInput = forms.TextInput(attrs={'readonly': 'readonly'})
|
||||||
self.fields["domain_id"].widget = readonlyInput
|
self.fields["domain_id"].widget = readonlyInput
|
||||||
self.fields["domain_name"].widget = readonlyInput
|
self.fields["domain_name"].widget = readonlyInput
|
||||||
|
# For keystone V2.0, hide description field
|
||||||
|
else:
|
||||||
|
self.fields["description"].widget = forms.HiddenInput()
|
||||||
|
|
||||||
# We have to protect the entire "data" dict because it contains the
|
# We have to protect the entire "data" dict because it contains the
|
||||||
# password and confirm_password strings.
|
# password and confirm_password strings.
|
||||||
@ -133,11 +140,13 @@ class CreateUserForm(PasswordMixin, BaseUserForm):
|
|||||||
domain = api.keystone.get_default_domain(self.request)
|
domain = api.keystone.get_default_domain(self.request)
|
||||||
try:
|
try:
|
||||||
LOG.info('Creating user with name "%s"' % data['name'])
|
LOG.info('Creating user with name "%s"' % data['name'])
|
||||||
|
desc = data["description"]
|
||||||
if "email" in data:
|
if "email" in data:
|
||||||
data['email'] = data['email'] or None
|
data['email'] = data['email'] or None
|
||||||
new_user = api.keystone.user_create(request,
|
new_user = api.keystone.user_create(request,
|
||||||
name=data['name'],
|
name=data['name'],
|
||||||
email=data['email'],
|
email=data['email'],
|
||||||
|
description=desc,
|
||||||
password=data['password'],
|
password=data['password'],
|
||||||
project=data['project'],
|
project=data['project'],
|
||||||
enabled=True,
|
enabled=True,
|
||||||
@ -179,6 +188,10 @@ class UpdateUserForm(BaseUserForm):
|
|||||||
widget=forms.HiddenInput())
|
widget=forms.HiddenInput())
|
||||||
id = forms.CharField(label=_("ID"), widget=forms.HiddenInput)
|
id = forms.CharField(label=_("ID"), widget=forms.HiddenInput)
|
||||||
name = forms.CharField(max_length=255, label=_("User Name"))
|
name = forms.CharField(max_length=255, label=_("User Name"))
|
||||||
|
description = forms.CharField(widget=forms.widgets.Textarea(
|
||||||
|
attrs={'rows': 4}),
|
||||||
|
label=_("Description"),
|
||||||
|
required=False)
|
||||||
email = forms.EmailField(
|
email = forms.EmailField(
|
||||||
label=_("Email"),
|
label=_("Email"),
|
||||||
required=False)
|
required=False)
|
||||||
@ -196,6 +209,9 @@ class UpdateUserForm(BaseUserForm):
|
|||||||
readonlyInput = forms.TextInput(attrs={'readonly': 'readonly'})
|
readonlyInput = forms.TextInput(attrs={'readonly': 'readonly'})
|
||||||
self.fields["domain_id"].widget = readonlyInput
|
self.fields["domain_id"].widget = readonlyInput
|
||||||
self.fields["domain_name"].widget = readonlyInput
|
self.fields["domain_name"].widget = readonlyInput
|
||||||
|
# For keystone V2.0, hide description field
|
||||||
|
else:
|
||||||
|
self.fields["description"].widget = forms.HiddenInput()
|
||||||
|
|
||||||
def handle(self, request, data):
|
def handle(self, request, data):
|
||||||
user = data.pop('id')
|
user = data.pop('id')
|
||||||
|
@ -24,6 +24,7 @@ from openstack_dashboard import policy
|
|||||||
|
|
||||||
ENABLE = 0
|
ENABLE = 0
|
||||||
DISABLE = 1
|
DISABLE = 1
|
||||||
|
KEYSTONE_V2_ENABLED = api.keystone.VERSIONS.active < 3
|
||||||
|
|
||||||
|
|
||||||
class CreateUserLink(tables.LinkAction):
|
class CreateUserLink(tables.LinkAction):
|
||||||
@ -196,6 +197,7 @@ class UpdateCell(tables.UpdateAction):
|
|||||||
request,
|
request,
|
||||||
user_obj,
|
user_obj,
|
||||||
name=user_obj.name,
|
name=user_obj.name,
|
||||||
|
description=user_obj.description,
|
||||||
email=user_obj.email,
|
email=user_obj.email,
|
||||||
enabled=user_obj.enabled,
|
enabled=user_obj.enabled,
|
||||||
project=user_obj.project_id,
|
project=user_obj.project_id,
|
||||||
@ -221,6 +223,13 @@ class UsersTable(tables.DataTable):
|
|||||||
verbose_name=_('User Name'),
|
verbose_name=_('User Name'),
|
||||||
form_field=forms.CharField(),
|
form_field=forms.CharField(),
|
||||||
update_action=UpdateCell)
|
update_action=UpdateCell)
|
||||||
|
description = tables.Column(lambda obj: getattr(obj, 'description', None),
|
||||||
|
verbose_name=_('Description'),
|
||||||
|
hidden=KEYSTONE_V2_ENABLED,
|
||||||
|
form_field=forms.CharField(
|
||||||
|
widget=forms.Textarea(attrs={'rows': 4}),
|
||||||
|
required=False),
|
||||||
|
update_action=UpdateCell)
|
||||||
email = tables.Column('email', verbose_name=_('Email'),
|
email = tables.Column('email', verbose_name=_('Email'),
|
||||||
form_field=forms.CharField(required=False),
|
form_field=forms.CharField(required=False),
|
||||||
update_action=UpdateCell,
|
update_action=UpdateCell,
|
||||||
|
@ -98,6 +98,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
.AndReturn([self.tenants.list(), False])
|
.AndReturn([self.tenants.list(), False])
|
||||||
api.keystone.user_create(IgnoreArg(),
|
api.keystone.user_create(IgnoreArg(),
|
||||||
name=user.name,
|
name=user.name,
|
||||||
|
description=user.description,
|
||||||
email=user.email,
|
email=user.email,
|
||||||
password=user.password,
|
password=user.password,
|
||||||
project=self.tenant.id,
|
project=self.tenant.id,
|
||||||
@ -114,6 +115,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
formData = {'method': 'CreateUserForm',
|
formData = {'method': 'CreateUserForm',
|
||||||
'domain_id': domain_id,
|
'domain_id': domain_id,
|
||||||
'name': user.name,
|
'name': user.name,
|
||||||
|
'description': user.description,
|
||||||
'email': user.email,
|
'email': user.email,
|
||||||
'password': user.password,
|
'password': user.password,
|
||||||
'project': self.tenant.id,
|
'project': self.tenant.id,
|
||||||
@ -150,6 +152,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
.AndReturn([self.tenants.list(), False])
|
.AndReturn([self.tenants.list(), False])
|
||||||
api.keystone.user_create(IgnoreArg(),
|
api.keystone.user_create(IgnoreArg(),
|
||||||
name=user.name,
|
name=user.name,
|
||||||
|
description=user.description,
|
||||||
email=user.email,
|
email=user.email,
|
||||||
password=user.password,
|
password=user.password,
|
||||||
project=self.tenant.id,
|
project=self.tenant.id,
|
||||||
@ -165,6 +168,7 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
formData = {'method': 'CreateUserForm',
|
formData = {'method': 'CreateUserForm',
|
||||||
'domain_id': domain_id,
|
'domain_id': domain_id,
|
||||||
'name': user.name,
|
'name': user.name,
|
||||||
|
'description': user.description,
|
||||||
'email': "",
|
'email': "",
|
||||||
'password': user.password,
|
'password': user.password,
|
||||||
'project': self.tenant.id,
|
'project': self.tenant.id,
|
||||||
@ -288,7 +292,6 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
user = self.users.get(id="1")
|
user = self.users.get(id="1")
|
||||||
domain_id = user.domain_id
|
domain_id = user.domain_id
|
||||||
domain = self.domains.get(id=domain_id)
|
domain = self.domains.get(id=domain_id)
|
||||||
email = getattr(user, 'email', '')
|
|
||||||
|
|
||||||
api.keystone.user_get(IsA(http.HttpRequest), '1',
|
api.keystone.user_get(IsA(http.HttpRequest), '1',
|
||||||
admin=True).AndReturn(user)
|
admin=True).AndReturn(user)
|
||||||
@ -300,16 +303,18 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
.AndReturn([self.tenants.list(), False])
|
.AndReturn([self.tenants.list(), False])
|
||||||
api.keystone.user_update(IsA(http.HttpRequest),
|
api.keystone.user_update(IsA(http.HttpRequest),
|
||||||
user.id,
|
user.id,
|
||||||
email=email,
|
email=user.email,
|
||||||
name=u'test_user',
|
name=user.name,
|
||||||
project=self.tenant.id).AndReturn(None)
|
project=self.tenant.id,
|
||||||
|
description=user.description).AndReturn(None)
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
formData = {'method': 'UpdateUserForm',
|
formData = {'method': 'UpdateUserForm',
|
||||||
'id': user.id,
|
'id': user.id,
|
||||||
'name': user.name,
|
'name': user.name,
|
||||||
'email': email,
|
'description': user.description,
|
||||||
|
'email': user.email,
|
||||||
'project': self.tenant.id}
|
'project': self.tenant.id}
|
||||||
|
|
||||||
res = self.client.post(USER_UPDATE_URL, formData)
|
res = self.client.post(USER_UPDATE_URL, formData)
|
||||||
@ -339,13 +344,15 @@ class UsersViewTests(test.BaseAdminViewTests):
|
|||||||
user.id,
|
user.id,
|
||||||
email=user.email,
|
email=user.email,
|
||||||
name=user.name,
|
name=user.name,
|
||||||
project=self.tenant.id).AndReturn(None)
|
project=self.tenant.id,
|
||||||
|
description=user.description).AndReturn(None)
|
||||||
|
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
formData = {'method': 'UpdateUserForm',
|
formData = {'method': 'UpdateUserForm',
|
||||||
'id': user.id,
|
'id': user.id,
|
||||||
'name': user.name,
|
'name': user.name,
|
||||||
|
'description': user.description,
|
||||||
'email': "",
|
'email': "",
|
||||||
'project': self.tenant.id}
|
'project': self.tenant.id}
|
||||||
|
|
||||||
|
@ -185,6 +185,7 @@ def data(TEST):
|
|||||||
|
|
||||||
user_dict = {'id': "1",
|
user_dict = {'id': "1",
|
||||||
'name': 'test_user',
|
'name': 'test_user',
|
||||||
|
'description': 'test_decription',
|
||||||
'email': 'test@example.com',
|
'email': 'test@example.com',
|
||||||
'password': 'password',
|
'password': 'password',
|
||||||
'token': 'test_token',
|
'token': 'test_token',
|
||||||
@ -194,6 +195,7 @@ def data(TEST):
|
|||||||
user = users.User(None, user_dict)
|
user = users.User(None, user_dict)
|
||||||
user_dict = {'id': "2",
|
user_dict = {'id': "2",
|
||||||
'name': 'user_two',
|
'name': 'user_two',
|
||||||
|
'description': 'test_decription',
|
||||||
'email': 'two@example.com',
|
'email': 'two@example.com',
|
||||||
'password': 'password',
|
'password': 'password',
|
||||||
'token': 'test_token',
|
'token': 'test_token',
|
||||||
@ -203,6 +205,7 @@ def data(TEST):
|
|||||||
user2 = users.User(None, user_dict)
|
user2 = users.User(None, user_dict)
|
||||||
user_dict = {'id': "3",
|
user_dict = {'id': "3",
|
||||||
'name': 'user_three',
|
'name': 'user_three',
|
||||||
|
'description': 'test_decription',
|
||||||
'email': 'three@example.com',
|
'email': 'three@example.com',
|
||||||
'password': 'password',
|
'password': 'password',
|
||||||
'token': 'test_token',
|
'token': 'test_token',
|
||||||
@ -212,6 +215,7 @@ def data(TEST):
|
|||||||
user3 = users.User(None, user_dict)
|
user3 = users.User(None, user_dict)
|
||||||
user_dict = {'id': "4",
|
user_dict = {'id': "4",
|
||||||
'name': 'user_four',
|
'name': 'user_four',
|
||||||
|
'description': 'test_decription',
|
||||||
'email': 'four@example.com',
|
'email': 'four@example.com',
|
||||||
'password': 'password',
|
'password': 'password',
|
||||||
'token': 'test_token',
|
'token': 'test_token',
|
||||||
@ -221,6 +225,7 @@ def data(TEST):
|
|||||||
user4 = users.User(None, user_dict)
|
user4 = users.User(None, user_dict)
|
||||||
user_dict = {'id': "5",
|
user_dict = {'id': "5",
|
||||||
'name': 'user_five',
|
'name': 'user_five',
|
||||||
|
'description': 'test_decription',
|
||||||
'email': None,
|
'email': None,
|
||||||
'password': 'password',
|
'password': 'password',
|
||||||
'token': 'test_token',
|
'token': 'test_token',
|
||||||
|
Loading…
Reference in New Issue
Block a user