Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 6
0
    def test_update_user_field_validation(self):
        user = self.users.get(id="1")
        self.mox.StubOutWithMock(api, 'tenant_list')
        self.mox.StubOutWithMock(api, 'user_get')
        self.mox.StubOutWithMock(api.keystone, 'user_update')
        self.mox.StubOutWithMock(api, 'user_update_tenant')
        self.mox.StubOutWithMock(api, 'user_update_password')

        api.keystone.user_update(IsA(http.HttpRequest),
                                 user.id,
                                 confirm_password=u'normalpwd',
                                 email=u'*****@*****.**',
                                 name=u'test_user').AndReturn(None)
        api.user_update_tenant(IsA(http.HttpRequest),
                               user.id,
                               self.tenant.id).AndReturn(None)
        api.user_update_password(IsA(http.HttpRequest),
                               user.id,
                               IgnoreArg()).AndReturn(None)
        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        api.user_get(IsA(http.HttpRequest), '1', admin=True).AndReturn(user)
        api.tenant_list(IgnoreArg(), admin=True).AndReturn(self.tenants.list())
        self.mox.ReplayAll()
        user.tenantId = 1

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

        # check successful update
        res = self.client.post(USER_UPDATE_URL, formData)
        self.assertNoFormErrors(res)

        # check password min-len verification
        formData['password'] = '******'
        formData['confirm_password'] = '******'

        res = self.client.post(USER_UPDATE_URL, formData)
        self.assertFormError(
            res, "form", 'password',
            ['Password must be between 8 and 18 characters.'])

        # check password max-len verification
        formData['password'] = '******'
        formData['confirm_password'] = '******'

        res = self.client.post(USER_UPDATE_URL, formData)
        self.assertFormError(
            res, "form", 'password',
            ['Password must be between 8 and 18 characters.'])
    def handle(self, request, data):
        failed, succeeded = [], []
        user = data.pop('id')
        password = data.pop('password')
        tenant = data.pop('tenant_id')
        # Discard the extra fields so we can pass kwargs to keystoneclient
        data.pop('method')
        data.pop('confirm_password', None)

        # 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)

        # 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:
            succeeded = map(force_unicode, succeeded)
            messages.success(
                request,
                _('Updated %(attributes)s for "%(user)s".') % {
                    "user": data["name"],
                    "attributes": ", ".join(succeeded)
                })
        if failed:
            failed = map(force_unicode, failed)
            messages.error(
                request,
                _('Unable to update %(attributes)s for "%(user)s".') % {
                    "user": data["name"],
                    "attributes": ", ".join(failed)
                })
        return shortcuts.redirect('horizon:syspanel:users:index')
    def handle(self, request, data):
        failed, succeeded = [], []
        user = data.pop('id')
        password = data.pop('password')
        tenant = data.pop('tenant_id')
        # Discard the extra fields so we can pass kwargs to keystoneclient
        data.pop('method')
        data.pop('confirm_password', None)

        # 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)

        # 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:
            succeeded = map(force_unicode, succeeded)
            messages.success(request,
                             _('Updated %(attributes)s for "%(user)s".')
                               % {"user": data["name"],
                                  "attributes": ", ".join(succeeded)})
        if failed:
            failed = map(force_unicode, failed)
            messages.error(request,
                           _('Unable to update %(attributes)s for "%(user)s".')
                             % {"user": data["name"],
                                "attributes": ", ".join(failed)})
        return shortcuts.redirect('horizon:syspanel:users:index')
Exemplo n.º 9
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')
        data.pop('method')

        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)

        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 shortcuts.redirect('horizon:syspanel:users:index')
Exemplo n.º 10
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')
        data.pop('method')

        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)

        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 shortcuts.redirect('horizon:syspanel:users:index')
Exemplo n.º 11
0
 def handle(self, request, data):
     updated = []
     if data['email']:
         updated.append('email')
         api.user_update_email(request, data['id'], data['email'])
     if data['password']:
         updated.append('password')
         api.user_update_password(request, data['id'], data['password'])
     if data['tenant_id']:
         updated.append('tenant')
         api.user_update_tenant(request, data['id'], data['tenant_id'])
     messages.success(request,
                      _('Updated %(attrib)s for %(user)s.') %
                      {"attrib": ', '.join(updated), "user": data['id']})
     return shortcuts.redirect('horizon:syspanel:users:index')
Exemplo n.º 12
0
 def handle(self, request, data):
     updated = []
     if data["email"]:
         updated.append("email")
         api.user_update_email(request, data["id"], data["email"])
     if data["password"]:
         updated.append("password")
         api.user_update_password(request, data["id"], data["password"])
     if data["tenant_id"]:
         updated.append("tenant")
         api.user_update_tenant(request, data["id"], data["tenant_id"])
     messages.success(
         request, _("Updated %(attrib)s for %(user)s.") % {"attrib": ", ".join(updated), "user": data["id"]}
     )
     return shortcuts.redirect("horizon:syspanel:users:index")
Exemplo n.º 13
0
def index(request):
    form = UpdatePassword(request=request)
    if request.method == 'POST':
        form = UpdatePassword(request=request, data=request.POST)
        if form.is_valid():
            if api.keystone_can_edit_user():
                api.user_update_password(
                    request,
                    request.user.id,
                    form.cleaned_data['new_password'],
                    admin=True
                )
                request.user_logout()
                return shortcuts.redirect('/auth/login')
    return shortcuts.render(request, 'password/settings.html', {
        'form': form,
    })
Exemplo n.º 14
0
 def handle(self, request, data):
     updated = []
     if data['email']:
         updated.append('email')
         api.user_update_email(request, data['id'], data['email'])
     if data['password']:
         updated.append('password')
         api.user_update_password(request, data['id'], data['password'])
     if data['tenant_id']:
         updated.append('tenant')
         api.user_update_tenant(request, data['id'], data['tenant_id'])
     messages.success(
         request,
         _('Updated %(attrib)s for %(user)s.') % {
             "attrib": ', '.join(updated),
             "user": data['id']
         })
     return shortcuts.redirect('horizon:syspanel:users:index')
Exemplo n.º 15
0
def update(request, user_id):
    if request.method == "POST":
        tenants = api.tenant_list(request)
        form = UserUpdateForm(request.POST, tenant_list=tenants)
        if form.is_valid():
            user = form.clean()
            updated = []
            if user['email']:
                updated.append('email')
                api.user_update_email(request, user['id'], user['email'])
            if user['password']:
                updated.append('password')
                api.user_update_password(request, user['id'], user['password'])
            if user['tenant_id']:
                updated.append('tenant')
                api.user_update_tenant(request, user['id'], user['tenant_id'])
            messages.success(request,
                             _('Updated %(attrib)s for %(user)s.') %
                             {"attrib": ', '.join(updated), "user": user_id})
            return shortcuts.redirect('horizon:syspanel:users:index')
        else:
            # TODO add better error management
            messages.error(request,
                           _('Unable to update user, please try again.'))

            return shortcuts.render(request,
                                    'syspanel/users/update.html', {
                                        'form': form,
                                        'user_id': user_id})

    else:
        user = api.user_get(request, user_id)
        tenants = api.tenant_list(request)
        form = UserUpdateForm(tenant_list=tenants,
                              initial={'id': user_id,
                                       'tenant_id': getattr(user,
                                                            'tenantId',
                                                            None),
                                       'email': getattr(user, 'email', '')})
        return shortcuts.render(request,
                                'syspanel/users/update.html', {
                                    'form': form,
                                    'user_id': user_id})
Exemplo n.º 16
0
    def test_user_update_password(self):
        keystoneclient = self.stub_keystoneclient()
        keystoneclient.users = self.mox.CreateMockAnything()
        keystoneclient.users.update_password(TEST_USERNAME,
                                          TEST_PASSWORD).AndReturn(TEST_RETURN)

        self.mox.ReplayAll()

        ret_val = api.user_update_password(self.request, TEST_USERNAME,
                                           TEST_PASSWORD)

        self.assertIsInstance(ret_val, api.User)
        self.assertEqual(ret_val._apiresource, TEST_RETURN)