Browse Source

Merge "Fixing updating user with no default project" into stable/mitaka

Jenkins 3 years ago
parent
commit
2eb320bd31

+ 7
- 1
openstack_dashboard/dashboards/identity/users/forms.py View File

@@ -68,6 +68,7 @@ class BaseUserForm(forms.SelfHandlingForm):
68 68
         # the user has access to.
69 69
         user_id = kwargs['initial'].get('id', None)
70 70
         domain_id = kwargs['initial'].get('domain_id', None)
71
+        default_project_id = kwargs['initial'].get('project', None)
71 72
 
72 73
         try:
73 74
             if api.keystone.VERSIONS.active >= 3:
@@ -82,7 +83,9 @@ class BaseUserForm(forms.SelfHandlingForm):
82 83
                     project_choices.append((project.id, project.name))
83 84
             if not project_choices:
84 85
                 project_choices.insert(0, ('', _("No available projects")))
85
-            elif len(project_choices) > 1:
86
+            # TODO(david-lyle): if keystoneclient is fixed to allow unsetting
87
+            # the default project, then this condition should be removed.
88
+            elif len(project_choices) > 1 and default_project_id is None:
86 89
                 project_choices.insert(0, ('', _("Select a project")))
87 90
             self.fields['project'].choices = project_choices
88 91
 
@@ -227,6 +230,9 @@ class UpdateUserForm(BaseUserForm):
227 230
         data.pop('domain_id')
228 231
         data.pop('domain_name')
229 232
 
233
+        if not PROJECT_REQUIRED and 'project' not in self.changed_data:
234
+            data.pop('project')
235
+
230 236
         if 'description' not in self.changed_data:
231 237
             data.pop('description')
232 238
         try:

+ 47
- 3
openstack_dashboard/dashboards/identity/users/tests.py View File

@@ -359,8 +359,7 @@ class UsersViewTests(test.BaseAdminViewTests):
359 359
         api.keystone.user_update(IsA(http.HttpRequest),
360 360
                                  user.id,
361 361
                                  email=user.email,
362
-                                 name=user.name,
363
-                                 project=self.tenant.id).AndReturn(None)
362
+                                 name=user.name).AndReturn(None)
364 363
 
365 364
         self.mox.ReplayAll()
366 365
 
@@ -375,6 +374,52 @@ class UsersViewTests(test.BaseAdminViewTests):
375 374
 
376 375
         self.assertNoFormErrors(res)
377 376
 
377
+    @test.create_stubs({api.keystone: ('user_get',
378
+                                       'domain_get',
379
+                                       'tenant_list',
380
+                                       'user_update_tenant',
381
+                                       'user_update_password',
382
+                                       'user_update',
383
+                                       'roles_for_user', )})
384
+    def test_update_default_project(self):
385
+        user = self.users.get(id="1")
386
+        domain_id = user.domain_id
387
+        domain = self.domains.get(id=domain_id)
388
+        new_project_id = self.tenants.get(id="3").id
389
+
390
+        api.keystone.user_get(IsA(http.HttpRequest), '1',
391
+                              admin=True).AndReturn(user)
392
+        api.keystone.domain_get(IsA(http.HttpRequest),
393
+                                domain_id).AndReturn(domain)
394
+
395
+        if api.keystone.VERSIONS.active >= 3:
396
+            api.keystone.tenant_list(
397
+                IgnoreArg(), domain=domain.id).AndReturn(
398
+                [self.tenants.list(), False])
399
+        else:
400
+            api.keystone.tenant_list(
401
+                IgnoreArg(), user=user.id).AndReturn(
402
+                [self.tenants.list(), False])
403
+
404
+        api.keystone.user_update(IsA(http.HttpRequest),
405
+                                 user.id,
406
+                                 email=user.email,
407
+                                 name=user.name,
408
+                                 project=new_project_id).AndReturn(None)
409
+
410
+        self.mox.ReplayAll()
411
+
412
+        formData = {'method': 'UpdateUserForm',
413
+                    'id': user.id,
414
+                    'name': user.name,
415
+                    'description': user.description,
416
+                    'email': user.email,
417
+                    'project': new_project_id}
418
+
419
+        res = self.client.post(USER_UPDATE_URL, formData)
420
+
421
+        self.assertNoFormErrors(res)
422
+
378 423
     @test.create_stubs({api.keystone: ('user_get',
379 424
                                        'domain_get',
380 425
                                        'tenant_list',
@@ -808,7 +853,6 @@ class UsersViewTests(test.BaseAdminViewTests):
808 853
                                  user.id,
809 854
                                  email=user.email,
810 855
                                  name=user.name,
811
-                                 project=self.tenant.id,
812 856
                                  description='changed').AndReturn(None)
813 857
 
814 858
         self.mox.ReplayAll()

Loading…
Cancel
Save