def get(self, user):
        """Get a list of the user's roles."""
        page = request.values.get('page', 1, type=int)
        size = request.values.get('size', 10, type=int)
        if page * size >= self.max_result_window:
            raise MaxResultWindowRESTError()

        query_string = request.args.get('q')
        roles_query = db.session.query(Role).join(userrole).filter_by(
            user_id=user.id
        ).order_by(Role.name)
        total_query = db.session.query(
            func.count(Role.id)).join(userrole).filter_by(
                user_id=user.id
            )
        if query_string is not None:
            query_filter = Role.name.like('%{}%'.format(query_string))
            roles_query = roles_query.filter(query_filter)
            total_query = total_query.filter(query_filter)
        user_roles = roles_query.slice((page - 1) * size, page * size).all()
        total = total_query.scalar()

        result = self.make_response(
            roles=user_roles,
            total=total,
            links=paginated_query_links(
                'invenio_accounts_rest.user_roles_list',
                total, page, size,
                self.max_result_window,
                user_id=user.id),
            code=200,
        )

        return result
    def get(self):
        """Get accounts/users/?q=."""
        page = request.values.get('page', 1, type=int)
        size = request.values.get('size', 10, type=int)
        if page * size >= self.max_result_window:
            raise MaxResultWindowRESTError()

        if 'invenio-userprofiles' not in current_app.extensions:
            users_query = User.query
        else:
            users_query = User.query.options(orm.joinedload('profile'))

        total_query = db.session.query(func.count(User.id))

        query_string = request.args.get('q')
        if query_string is not None:
            query_filter = User.email.like(
                '%{}%'.format(query_string)
            ) | (cast(User.id, String) == query_string)
            users_query = users_query.filter(query_filter)
            total_query = total_query.filter(query_filter)

        users = users_query.order_by(User.email).slice(
            (page - 1) * size, page * size
        ).all()
        total = total_query.scalar()

        result = self.make_response(
            users=users,
            total=total,
            links=paginated_query_links('invenio_accounts_rest.users_list',
                                        total, page, size,
                                        self.max_result_window),
            code=200,
        )
        return result