Beispiel #1
0
    def test_update(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.user_update(IsA(http.HttpRequest),
                                 user.id,
                                 email=u'*****@*****.**',
                                 name=u'test_user').AndReturn(None)
        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)

        self.mox.ReplayAll()

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

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

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Beispiel #2
0
    def test_update(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), '1',
                     admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(),
                        admin=True).AndReturn(self.tenants.list())
        api.keystone.user_update(IsA(http.HttpRequest),
                                 user.id,
                                 email=u'*****@*****.**',
                                 name=u'test_user').AndReturn(None)
        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)

        self.mox.ReplayAll()

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

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

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Beispiel #3
0
    def test_update(self):
        user = self.users.get(id="1")

        api.user_get(IsA(http.HttpRequest), "1", admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.keystone.user_update(
            IsA(http.HttpRequest), user.id, email=u"*****@*****.**", name=u"test_user"
        ).AndReturn(None)
        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)

        self.mox.ReplayAll()

        formData = {
            "method": "UpdateUserForm",
            "id": user.id,
            "name": user.name,
            "email": user.email,
            "password": "******",
            "tenant_id": self.tenant.id,
            "confirm_password": "******",
        }

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

        self.assertNoFormErrors(res)
        self.assertMessageCount(warning=1)
Beispiel #4
0
    def handle(self, request, data):
        failed, succeeded = [], []
        user_is_editable = api.keystone_can_edit_user()
        user = data.pop('id')
        tenant = data.pop('tenant_id')

        if user_is_editable:
            password = data.pop('password')
            data.pop('confirm_password', None)

        if user_is_editable:
            # Update user details
            msg_bits = (_('name'), _('email'))
            try:
                api.keystone.user_update(request, user, **data)
                succeeded.extend(msg_bits)
            except:
                failed.extend(msg_bits)
                exceptions.handle(request, ignore=True)

        # Update default tenant
        msg_bits = (_('primary project'), )
        try:
            api.user_update_tenant(request, user, tenant)
            succeeded.extend(msg_bits)
        except:
            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
            if password:
                msg_bits = (_('password'), )
                try:
                    api.user_update_password(request, user, password)
                    succeeded.extend(msg_bits)
                except:
                    failed.extend(msg_bits)
                    exceptions.handle(request, ignore=True)

        if succeeded:
            messages.success(request, _('User has been updated successfully.'))
        if failed:
            failed = map(force_unicode, failed)
            messages.error(
                request,
                _('Unable to update %(attributes)s for the user.') %
                {"attributes": ", ".join(failed)})
        return True
Beispiel #5
0
    def handle(self, request, data):
        failed, succeeded = [], []
        user_is_editable = api.keystone_can_edit_user()
        user = data.pop('id')
        tenant = data.pop('tenant_id')

        if user_is_editable:
            password = data.pop('password')
            data.pop('confirm_password', None)

        if user_is_editable:
            # Update user details
            msg_bits = (_('name'), _('email'))
            try:
                api.keystone.user_update(request, user, **data)
                succeeded.extend(msg_bits)
            except:
                failed.extend(msg_bits)
                exceptions.handle(request, ignore=True)

        # Update default tenant
        msg_bits = (_('primary project'),)
        try:
            api.user_update_tenant(request, user, tenant)
            succeeded.extend(msg_bits)
        except:
            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
            if password:
                msg_bits = (_('password'),)
                try:
                    api.user_update_password(request, user, password)
                    succeeded.extend(msg_bits)
                except:
                    failed.extend(msg_bits)
                    exceptions.handle(request, ignore=True)

        if succeeded:
            messages.success(request, _('User has been updated successfully.'))
        if failed:
            failed = map(force_unicode, failed)
            messages.error(request,
                           _('Unable to update %(attributes)s for the user.')
                             % {"attributes": ", ".join(failed)})
        return True
 def _handle(self, request, data):
     self.user = self.clean()
     self.updated = []
     self.user_id = self.user['id']
     if self.is_create:
         self.orig_user = api.user_create(
             request, self.user['id'], self.user['email'], 
             self.user['password'], None, True)
         messages.success(request,
                          '%s was successfully created.'
                          % self.user_id)
     else:
         self.orig_user = api.user_get(request, self.user_id)
         if self.user['email'] != self.orig_user.email:
             self.updated.append('email')
             api.user_update_email(request, self.user['id'], self.user['email'])
         if self.user['password']:
             self.updated.append('password')
             api.user_update_password(request, self.user['id'], self.user['password'])