components/openstack/horizon/patches/05-launchpad-1260439.patch
changeset 1949 97e85b2096e5
equal deleted inserted replaced
1948:2d1537e7942d 1949:97e85b2096e5
       
     1 This proposed upstream patch addresses
       
     2 
       
     3 	18720708 Error: Unable to add userto primary project when adding user
       
     4 		 via Horizon
       
     5 
       
     6 and is tracked under Launchpad bug 1260439. Although it's been
       
     7 addressed in the Juno trunk, the patch below is still not yet released
       
     8 for Havana.  It has been modified to apply cleanly into our current
       
     9 Havana implementation
       
    10 
       
    11 commit f5ded29d9a73db4c225cbfb664e7d85e5aa0996b
       
    12 Author: Matthias Runge <[email protected]>
       
    13 Date:   Fri May 23 11:36:54 2014 +0200
       
    14 
       
    15     Prevent error message when creating a user
       
    16     
       
    17     keystone changed behaviour and didn't add the user
       
    18     to the specified role. Now it does; this patch
       
    19     prevents an exception popping up without breaking
       
    20     with previous versions.
       
    21     
       
    22     Change-Id: I115a5126b70ae3c7733aa065bf55104f88cc42e5
       
    23     Closes-Bug: #1260439
       
    24 
       
    25 --- horizon-2013.2.3/openstack_dashboard/dashboards/admin/users/forms.py.~1~	2014-04-03 11:45:53.000000000 -0700
       
    26 +++ horizon-2013.2.3/openstack_dashboard/dashboards/admin/users/forms.py	2014-06-11 12:54:51.517905246 -0700
       
    27 @@ -122,15 +122,21 @@
       
    28                               _('User "%s" was successfully created.')
       
    29                               % data['name'])
       
    30              if data['role_id']:
       
    31 -                try:
       
    32 -                    api.keystone.add_tenant_user_role(request,
       
    33 -                                                      data['project'],
       
    34 -                                                      new_user.id,
       
    35 -                                                      data['role_id'])
       
    36 -                except Exception:
       
    37 -                    exceptions.handle(request,
       
    38 -                                      _('Unable to add user '
       
    39 -                                        'to primary project.'))
       
    40 +                roles = api.keystone.roles_for_user(request,
       
    41 +                                        new_user.id,
       
    42 +                                        data['project']) or []
       
    43 +                assigned = [role for role in roles if role.id == str(
       
    44 +                    data['role_id'])]
       
    45 +                if not assigned:
       
    46 +                    try:
       
    47 +                        api.keystone.add_tenant_user_role(request,
       
    48 +                                                        data['project'],
       
    49 +                                                        new_user.id,
       
    50 +                                                        data['role_id'])
       
    51 +                    except Exception:
       
    52 +                        exceptions.handle(request,
       
    53 +                                        _('Unable to add user '
       
    54 +                                            'to primary project.'))
       
    55              return new_user
       
    56          except Exception:
       
    57              exceptions.handle(request, _('Unable to create user.'))
       
    58 --- horizon-2013.2.3/openstack_dashboard/dashboards/admin/users/tests.py.~1~	2014-04-03 11:45:53.000000000 -0700
       
    59 +++ horizon-2013.2.3/openstack_dashboard/dashboards/admin/users/tests.py	2014-06-11 13:44:29.437187509 -0700
       
    60 @@ -81,6 +81,7 @@
       
    61                                         'tenant_list',
       
    62                                         'add_tenant_user_role',
       
    63                                         'get_default_role',
       
    64 +                                       'roles_for_user',
       
    65                                         'role_list')})
       
    66      def test_create(self):
       
    67          user = self.users.get(id="1")
       
    68 @@ -102,6 +103,7 @@
       
    69                                   domain=domain_id).AndReturn(user)
       
    70          api.keystone.role_list(IgnoreArg()).AndReturn(self.roles.list())
       
    71          api.keystone.get_default_role(IgnoreArg()).AndReturn(role)
       
    72 +        api.keystone.roles_for_user(IgnoreArg(), user.id, self.tenant.id)
       
    73          api.keystone.add_tenant_user_role(IgnoreArg(), self.tenant.id,
       
    74                                            user.id, role.id)
       
    75