Ejemplo n.º 1
0
def user_update(request, user, **data):
    manager = keystoneclient(request, admin=True).users
    error = None

    if not keystone_can_edit_user():
        raise ClientException(
            405, _("Identity service does not allow "
                   "editing user data."))

    # The v2 API updates user model, password and default project separately
    if VERSIONS.active < 3:
        password = data.pop('password')
        project = data.pop('project')

        # Update user details
        try:
            user = manager.update(user, **data)
        except:
            error = exceptions.handle(request, ignore=True)

        # Update default tenant
        try:
            user_update_tenant(request, user, project)
            user.tenantId = project
        except:
            error = exceptions.handle(request, ignore=True)

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

        # If present, update password
        # FIXME(gabriel): password change should be its own form + view
        if password:
            try:
                user_update_password(request, user, password)
                if user == request.user.id:
                    logout(request)
            except:
                error = exceptions.handle(request, ignore=True)

        if error is not None:
            raise error

    # v3 API is so much simpler...
    else:
        if not data['password']:
            data.pop('password')
        user = manager.update(user, **data)

    return VERSIONS.upgrade_v2_user(user)
Ejemplo n.º 2
0
 def delete(self, request, obj_id):
     domain = self.table.get_object_by_id(obj_id)
     if domain.enabled:
         msg = _('Domain "%s" must be disabled before it can be deleted.') \
             % domain.name
         messages.error(request, msg)
         raise ClientException(409, msg)
     else:
         LOG.info('Deleting domain "%s".' % obj_id)
         api.keystone.domain_delete(request, obj_id)