From cbd63f27e4ab100fe42c6a9f50b2340b8de9d113 Mon Sep 17 00:00:00 2001 From: Canh Truong Date: Fri, 12 Jun 2015 10:39:22 +0700 Subject: [PATCH] Add description field in the user table In the user table, description column is missing when using keystone V3 This patch add the 'Description'column in User table. This also change to add 'Description' field the user_create and user_update form. Change-Id: I90bb7a644f8f29ae0055c6c2ffc688a9b709f300 Closes-Bug: #1463247 --- openstack_dashboard/api/keystone.py | 4 ++-- .../dashboards/identity/users/forms.py | 20 +++++++++++++++++-- .../dashboards/identity/users/tables.py | 9 +++++++++ .../dashboards/identity/users/tests.py | 19 ++++++++++++------ .../test/test_data/keystone_data.py | 5 +++++ 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/openstack_dashboard/api/keystone.py b/openstack_dashboard/api/keystone.py index 2b5eb5ba42..a72861e306 100644 --- a/openstack_dashboard/api/keystone.py +++ b/openstack_dashboard/api/keystone.py @@ -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, - enabled=None, domain=None): + enabled=None, domain=None, description=None): manager = keystoneclient(request, admin=True).users try: if VERSIONS.active < 3: @@ -321,7 +321,7 @@ def user_create(request, name=None, email=None, password=None, project=None, else: return manager.create(name, password=password, email=email, project=project, enabled=enabled, - domain=domain) + domain=domain, description=description) except keystone_exceptions.Conflict: raise exceptions.Conflict() diff --git a/openstack_dashboard/dashboards/identity/users/forms.py b/openstack_dashboard/dashboards/identity/users/forms.py index 817121eaa8..d1bb88d493 100644 --- a/openstack_dashboard/dashboards/identity/users/forms.py +++ b/openstack_dashboard/dashboards/identity/users/forms.py @@ -34,7 +34,6 @@ from horizon.utils import validators from openstack_dashboard import api - LOG = logging.getLogger(__name__) PROJECT_REQUIRED = api.keystone.VERSIONS.active < 3 @@ -95,6 +94,10 @@ class CreateUserForm(PasswordMixin, BaseUserForm): required=False, widget=forms.HiddenInput()) 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( label=_("Email"), required=False) @@ -108,7 +111,8 @@ class CreateUserForm(PasswordMixin, BaseUserForm): roles = kwargs.pop('roles') super(CreateUserForm, self).__init__(*args, **kwargs) # 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"] # Starting from 1.7 Django uses OrderedDict for fields and keyOrder # no longer works for it @@ -125,6 +129,9 @@ class CreateUserForm(PasswordMixin, BaseUserForm): readonlyInput = forms.TextInput(attrs={'readonly': 'readonly'}) self.fields["domain_id"].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 # password and confirm_password strings. @@ -133,11 +140,13 @@ class CreateUserForm(PasswordMixin, BaseUserForm): domain = api.keystone.get_default_domain(self.request) try: LOG.info('Creating user with name "%s"' % data['name']) + desc = data["description"] if "email" in data: data['email'] = data['email'] or None new_user = api.keystone.user_create(request, name=data['name'], email=data['email'], + description=desc, password=data['password'], project=data['project'], enabled=True, @@ -179,6 +188,10 @@ class UpdateUserForm(BaseUserForm): widget=forms.HiddenInput()) id = forms.CharField(label=_("ID"), widget=forms.HiddenInput) 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( label=_("Email"), required=False) @@ -196,6 +209,9 @@ class UpdateUserForm(BaseUserForm): readonlyInput = forms.TextInput(attrs={'readonly': 'readonly'}) self.fields["domain_id"].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): user = data.pop('id') diff --git a/openstack_dashboard/dashboards/identity/users/tables.py b/openstack_dashboard/dashboards/identity/users/tables.py index d5c41120b3..8452b7c464 100644 --- a/openstack_dashboard/dashboards/identity/users/tables.py +++ b/openstack_dashboard/dashboards/identity/users/tables.py @@ -24,6 +24,7 @@ from openstack_dashboard import policy ENABLE = 0 DISABLE = 1 +KEYSTONE_V2_ENABLED = api.keystone.VERSIONS.active < 3 class CreateUserLink(tables.LinkAction): @@ -196,6 +197,7 @@ class UpdateCell(tables.UpdateAction): request, user_obj, name=user_obj.name, + description=user_obj.description, email=user_obj.email, enabled=user_obj.enabled, project=user_obj.project_id, @@ -221,6 +223,13 @@ class UsersTable(tables.DataTable): verbose_name=_('User Name'), form_field=forms.CharField(), 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'), form_field=forms.CharField(required=False), update_action=UpdateCell, diff --git a/openstack_dashboard/dashboards/identity/users/tests.py b/openstack_dashboard/dashboards/identity/users/tests.py index 6331371761..b017274346 100644 --- a/openstack_dashboard/dashboards/identity/users/tests.py +++ b/openstack_dashboard/dashboards/identity/users/tests.py @@ -98,6 +98,7 @@ class UsersViewTests(test.BaseAdminViewTests): .AndReturn([self.tenants.list(), False]) api.keystone.user_create(IgnoreArg(), name=user.name, + description=user.description, email=user.email, password=user.password, project=self.tenant.id, @@ -114,6 +115,7 @@ class UsersViewTests(test.BaseAdminViewTests): formData = {'method': 'CreateUserForm', 'domain_id': domain_id, 'name': user.name, + 'description': user.description, 'email': user.email, 'password': user.password, 'project': self.tenant.id, @@ -150,6 +152,7 @@ class UsersViewTests(test.BaseAdminViewTests): .AndReturn([self.tenants.list(), False]) api.keystone.user_create(IgnoreArg(), name=user.name, + description=user.description, email=user.email, password=user.password, project=self.tenant.id, @@ -165,6 +168,7 @@ class UsersViewTests(test.BaseAdminViewTests): formData = {'method': 'CreateUserForm', 'domain_id': domain_id, 'name': user.name, + 'description': user.description, 'email': "", 'password': user.password, 'project': self.tenant.id, @@ -288,7 +292,6 @@ class UsersViewTests(test.BaseAdminViewTests): user = self.users.get(id="1") domain_id = user.domain_id domain = self.domains.get(id=domain_id) - email = getattr(user, 'email', '') api.keystone.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user) @@ -300,16 +303,18 @@ class UsersViewTests(test.BaseAdminViewTests): .AndReturn([self.tenants.list(), False]) api.keystone.user_update(IsA(http.HttpRequest), user.id, - email=email, - name=u'test_user', - project=self.tenant.id).AndReturn(None) + email=user.email, + name=user.name, + project=self.tenant.id, + description=user.description).AndReturn(None) self.mox.ReplayAll() formData = {'method': 'UpdateUserForm', 'id': user.id, 'name': user.name, - 'email': email, + 'description': user.description, + 'email': user.email, 'project': self.tenant.id} res = self.client.post(USER_UPDATE_URL, formData) @@ -339,13 +344,15 @@ class UsersViewTests(test.BaseAdminViewTests): user.id, email=user.email, name=user.name, - project=self.tenant.id).AndReturn(None) + project=self.tenant.id, + description=user.description).AndReturn(None) self.mox.ReplayAll() formData = {'method': 'UpdateUserForm', 'id': user.id, 'name': user.name, + 'description': user.description, 'email': "", 'project': self.tenant.id} diff --git a/openstack_dashboard/test/test_data/keystone_data.py b/openstack_dashboard/test/test_data/keystone_data.py index 82450384f3..a342a04787 100644 --- a/openstack_dashboard/test/test_data/keystone_data.py +++ b/openstack_dashboard/test/test_data/keystone_data.py @@ -185,6 +185,7 @@ def data(TEST): user_dict = {'id': "1", 'name': 'test_user', + 'description': 'test_decription', 'email': 'test@example.com', 'password': 'password', 'token': 'test_token', @@ -194,6 +195,7 @@ def data(TEST): user = users.User(None, user_dict) user_dict = {'id': "2", 'name': 'user_two', + 'description': 'test_decription', 'email': 'two@example.com', 'password': 'password', 'token': 'test_token', @@ -203,6 +205,7 @@ def data(TEST): user2 = users.User(None, user_dict) user_dict = {'id': "3", 'name': 'user_three', + 'description': 'test_decription', 'email': 'three@example.com', 'password': 'password', 'token': 'test_token', @@ -212,6 +215,7 @@ def data(TEST): user3 = users.User(None, user_dict) user_dict = {'id': "4", 'name': 'user_four', + 'description': 'test_decription', 'email': 'four@example.com', 'password': 'password', 'token': 'test_token', @@ -221,6 +225,7 @@ def data(TEST): user4 = users.User(None, user_dict) user_dict = {'id': "5", 'name': 'user_five', + 'description': 'test_decription', 'email': None, 'password': 'password', 'token': 'test_token',