Skip to content

Commit

Permalink
Warn user if no role assigned in default Project
Browse files Browse the repository at this point in the history
Fixes Bug #1011461

When the default project settings is updated, the
form will show a warning if there are no roles assigned
for the default project. This will prompt the user to
assignd the role using Project >> Modify users.

Change-Id: I3abf3d154e3c0decd918e15f04eaef84b4aaa748
  • Loading branch information
lin-hua-cheng committed Jul 31, 2012
1 parent 6b3545e commit 3c4b00c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
9 changes: 9 additions & 0 deletions horizon/dashboards/syspanel/users/forms.py
Expand Up @@ -162,6 +162,15 @@ def handle(self, request, data):
failed.append(msg_bits)
exceptions.handle(request, ignore=True)

# Check for existing roles
# Show a warning if no role exists for the tenant
user_roles = api.keystone.roles_for_user(request, user, tenant)
if not user_roles:
messages.warning(request,
_('The user %s has no role defined for' +
' that project.')
% data.get('name', None))

if user_is_editable:
# If present, update password
# FIXME(gabriel): password change should be its own form and view
Expand Down
19 changes: 15 additions & 4 deletions horizon/dashboards/syspanel/users/tests.py
Expand Up @@ -159,7 +159,8 @@ def test_create_validation_for_password_too_long(self):
'tenant_list',
'user_update_tenant',
'user_update_password'),
api.keystone: ('user_update',)})
api.keystone: ('user_update',
'roles_for_user', )})
def test_update(self):
user = self.users.get(id="1")

Expand All @@ -174,6 +175,9 @@ def test_update(self):
api.user_update_tenant(IsA(http.HttpRequest),
user.id,
self.tenant.id).AndReturn(None)
api.keystone.roles_for_user(IsA(http.HttpRequest),
user.id,
self.tenant.id).AndReturn(None)
api.user_update_password(IsA(http.HttpRequest),
user.id,
IgnoreArg()).AndReturn(None)
Expand All @@ -191,11 +195,13 @@ def test_update(self):
res = self.client.post(USER_UPDATE_URL, formData)

self.assertNoFormErrors(res)
self.assertMessageCount(warning=1)

@test.create_stubs({api: ('user_get',
'tenant_list',
'user_update_tenant',
'keystone_can_edit_user')})
'keystone_can_edit_user'),
api.keystone: ('roles_for_user', )})
def test_update_with_keystone_can_edit_user_false(self):
user = self.users.get(id="1")

Expand All @@ -208,16 +214,21 @@ def test_update_with_keystone_can_edit_user_false(self):
api.user_update_tenant(IsA(http.HttpRequest),
user.id,
self.tenant.id).AndReturn(None)
api.keystone.roles_for_user(IsA(http.HttpRequest),
user.id,
self.tenant.id).AndReturn(None)

self.mox.ReplayAll()

formData = {'method': 'UpdateUserForm',
'tenant_id': self.tenant.id,
'id': user.id}
'id': user.id,
'name': user.name,
'tenant_id': self.tenant.id, }

res = self.client.post(USER_UPDATE_URL, formData)

self.assertNoFormErrors(res)
self.assertMessageCount(warning=1)

@test.create_stubs({api: ('user_get', 'tenant_list')})
def test_update_validation_for_password_too_short(self):
Expand Down

0 comments on commit 3c4b00c

Please sign in to comment.