示例#1
0
    def get(self):
        """
        Retrieve a list of queries.

        :qparam number page_size: Number of queries to return
        :qparam number page: Page number to retrieve

        Responds with an array of :ref:`query <query-response-label>` objects.
        """

        search_term = request.args.get('q')

        if search_term:
            results = models.Query.search(search_term,
                                          self.current_user.group_ids,
                                          include_drafts=True,
                                          limit=None)
        else:
            results = models.Query.all_queries(self.current_user.group_ids,
                                               self.current_user.id)

        results = filter_by_tags(results, models.Query.tags)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(results,
                            page,
                            page_size,
                            QuerySerializer,
                            with_stats=True,
                            with_last_modified_by=False)
        return response
示例#2
0
    def get(self):
        """
        Retrieve a list of queries created by the current user.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number search: Full text search term

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        search_term = request.args.get('q', '')
        if search_term:
            results = models.Query.search_by_user(search_term,
                                                  self.current_user)
        else:
            results = models.Query.by_user(self.current_user)

        results = filter_by_tags(results, models.Query.tags)

        # order results according to passed order parameter
        ordered_results = order_results(results)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        return paginate(
            ordered_results,
            page,
            page_size,
            QuerySerializer,
            with_stats=True,
            with_last_modified_by=False,
        )
示例#3
0
    def get(self):
        """
        Lists all dashboards except archived and draft.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        """

        results = models.Dashboard.get_all(self.current_org)
        results = filter_by_tags(results, models.Dashboard.tags)

        ordered_results = order_results(results)

        page = request.args.get("page", 1, type=int)
        page_size = request.args.get("page_size", 25, type=int)

        response = paginate(
            ordered_results,
            page=page,
            page_size=page_size,
            serializer=DashboardSerializer,
        )

        self.record_event({"action": "list", "object_type": "dashboard"})

        return response
示例#4
0
    def get(self):
        search_term = request.args.get('q')

        if search_term:
            base_query = models.Dashboard.search(self.current_org,
                                                 self.current_user.group_ids,
                                                 self.current_user.id,
                                                 search_term)
            favorites = models.Dashboard.favorites(self.current_user,
                                                   base_query=base_query)
        else:
            favorites = models.Dashboard.favorites(self.current_user)

        favorites = filter_by_tags(favorites, models.Dashboard.tags)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(favorites, page, page_size, serialize_dashboard)

        self.record_event({
            'action': 'load_favorites',
            'object_type': 'dashboard',
            'params': {
                'q': search_term,
                'tags': request.args.getlist('tags'),
                'page': page
            }
        })

        return response
示例#5
0
    def get(self):
        search_term = request.args.get('q')

        if search_term:
            base_query = models.Dashboard.search(self.current_org, self.current_user.group_ids, self.current_user.id, search_term)
            favorites = models.Dashboard.favorites(self.current_user, base_query=base_query)
        else:
            favorites = models.Dashboard.favorites(self.current_user)

        favorites = filter_by_tags(favorites, models.Dashboard.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        favorites = order_results(favorites, fallback=not bool(search_term))

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(favorites, page, page_size, serialize_dashboard)

        self.record_event({
            'action': 'load_favorites',
            'object_type': 'dashboard',
            'params': {
                'q': search_term,
                'tags': request.args.getlist('tags'),
                'page': page
            }
        })

        return response
示例#6
0
    def get(self):
        search_term = request.args.get('q')

        if search_term:
            base_query = models.Query.search(search_term,
                                             self.current_user.group_ids,
                                             include_drafts=True,
                                             limit=None)
            favorites = models.Query.favorites(self.current_user,
                                               base_query=base_query)
        else:
            favorites = models.Query.favorites(self.current_user)

        favorites = filter_by_tags(favorites, models.Query.tags)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(favorites,
                            page,
                            page_size,
                            QuerySerializer,
                            with_stats=True,
                            with_last_modified_by=False)

        self.record_event({
            'action': 'load_favorites',
            'object_type': 'query',
            'params': {
                'q': search_term,
                'tags': request.args.getlist('tags'),
                'page': page
            }
        })

        return response
示例#7
0
    def get(self):
        page = request.args.get("page", 1, type=int)
        page_size = request.args.get("page_size", 25, type=int)

        groups = {group.id: group for group in models.Group.all(self.current_org)}

        def serialize_user(user):
            d = user.to_dict()
            user_groups = []
            for group_id in set(d["groups"]):
                group = groups.get(group_id)

                if group:
                    user_groups.append({"id": group.id, "name": group.name})

            d["groups"] = user_groups

            return d

        search_term = request.args.get("q", "")

        disabled = request.args.get("disabled", "false")  # get enabled users by default
        disabled = parse_boolean(disabled)

        pending = request.args.get(
            "pending", None
        )  # get both active and pending by default
        if pending is not None:
            pending = parse_boolean(pending)

        users = self.get_users(disabled, pending, search_term)

        return paginate(users, page, page_size, serialize_user)
示例#8
0
文件: users.py 项目: zhshw/redash
    def get(self):
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        groups = {
            group.id: group
            for group in models.Group.all(self.current_org)
        }

        def serialize_user(user):
            d = user.to_dict()
            user_groups = []
            for group_id in set(d['groups']):
                group = groups.get(group_id)

                if group:
                    user_groups.append({'id': group.id, 'name': group.name})

            d['groups'] = user_groups

            return d

        search_term = request.args.get('q', '')

        if request.args.get('disabled', None) is not None:
            users = models.User.all_disabled(self.current_org)
        else:
            users = models.User.all(self.current_org)

        if search_term:
            users = models.User.search(users, search_term)

        users = order_results(users)

        return paginate(users, page, page_size, serialize_user)
示例#9
0
    def get(self):
        search_term = request.args.get("q")
        if search_term:
            applications = models.Application.search(self.current_org,
                                                     search_term)
            self.record_event({
                "action": "search",
                "object_type": "application",
                "term": search_term
            })
        else:
            applications = models.Application.all(self.current_org)
            self.record_event({
                "action": "list",
                "object_id": "applications",
                "object_type": "application"
            })

        ordered_results = order_results(applications,
                                        fallback=not bool(search_term))

        page = request.args.get("page", 1, type=int)
        page_size = request.args.get("page_size", 25, type=int)

        response = paginate(
            ordered_results,
            page=page,
            page_size=page_size,
            serializer=ApplicationSerializer,
        )
        return response
示例#10
0
    def get(self):
        search_term = request.args.get('q')

        if search_term:
            base_query = models.Dashboard.search(self.current_org, self.current_user.group_ids, self.current_user.id, search_term)
            favorites = models.Dashboard.favorites(self.current_user, base_query=base_query)
        else:
            favorites = models.Dashboard.favorites(self.current_user)

        favorites = filter_by_tags(favorites, models.Dashboard.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        favorites = order_results(favorites, fallback=not bool(search_term))

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(favorites, page, page_size, serialize_dashboard)

        self.record_event({
            'action': 'load_favorites',
            'object_type': 'dashboard',
            'params': {
                'q': search_term,
                'tags': request.args.getlist('tags'),
                'page': page
            }
        })

        return response
示例#11
0
文件: users.py 项目: ariarijp/redash
    def get(self):
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        groups = {group.id: group for group in models.Group.all(self.current_org)}

        def serialize_user(user):
            d = user.to_dict()
            user_groups = []
            for group_id in set(d['groups']):
                group = groups.get(group_id)

                if group:
                    user_groups.append({'id': group.id, 'name': group.name})

            d['groups'] = user_groups

            return d

        search_term = request.args.get('q', '')

        disabled = request.args.get('disabled', 'false')  # get enabled users by default
        disabled = parse_boolean(disabled)

        pending = request.args.get('pending', None)  # get both active and pending by default
        if pending is not None:
            pending = parse_boolean(pending)

        users = self.get_users(disabled, pending, search_term)

        return paginate(users, page, page_size, serialize_user)
示例#12
0
    def get(self):
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        groups = {group.id: group for group in models.Group.all(self.current_org)}

        def serialize_user(user):
            d = user.to_dict()
            user_groups = []
            for group_id in set(d['groups']):
                group = groups.get(group_id)

                if group:
                    user_groups.append({'id': group.id, 'name': group.name})

            d['groups'] = user_groups

            return d

        search_term = request.args.get('q', '')

        disabled = request.args.get('disabled', 'false')  # get enabled users by default
        disabled = parse_boolean(disabled)

        pending = request.args.get('pending', None)  # get both active and pending by default
        if pending is not None:
            pending = parse_boolean(pending)

        users = self.get_users(disabled, pending, search_term)

        return paginate(users, page, page_size, serialize_user)
示例#13
0
    def get(self):
        """
        Retrieve a list of queries created by the current user.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number search: Full text search term

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        search_term = request.args.get("q", "")
        if search_term:
            results = models.Query.search_by_user(search_term, self.current_user)
        else:
            results = models.Query.by_user(self.current_user)

        results = filter_by_tags(results, models.Query.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_results = order_results(results, fallback=not bool(search_term))

        page = request.args.get("page", 1, type=int)
        page_size = request.args.get("page_size", 25, type=int)
        return paginate(
            ordered_results,
            page,
            page_size,
            QuerySerializer,
            with_stats=True,
            with_last_modified_by=False,
        )
示例#14
0
    def get(self):
        search_term = request.args.get('q')

        if search_term:
            base_query = models.Query.search(search_term, self.current_user.group_ids, include_drafts=True, limit=None)
            favorites = models.Query.favorites(self.current_user, base_query=base_query)
        else:
            favorites = models.Query.favorites(self.current_user)

        favorites = filter_by_tags(favorites, models.Query.tags)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(favorites, page, page_size, QuerySerializer, with_stats=True, with_last_modified_by=False)

        self.record_event({
            'action': 'load_favorites',
            'object_type': 'query',
            'params': {
                'q': search_term,
                'tags': request.args.getlist('tags'),
                'page': page
            }
        })

        return response
示例#15
0
    def get(self):
        search_term = request.args.get('q')

        if search_term:
            base_query = models.Dashboard.search(self.current_org, self.current_user.group_ids, self.current_user.id, search_term)
            favorites = models.Dashboard.favorites(self.current_user, base_query=base_query)
        else:
            favorites = models.Dashboard.favorites(self.current_user)

        favorites = filter_by_tags(favorites, models.Dashboard.tags)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(favorites, page, page_size, serialize_dashboard)

        self.record_event({
            'action': 'load_favorites',
            'object_type': 'dashboard',
            'params': {
                'q': search_term,
                'tags': request.args.getlist('tags'),
                'page': page
            }
        })

        return response
示例#16
0
    def get(self):
        """
        Retrieve a list of queries.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number q: Full text search term

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        # See if we want to do full-text search or just regular queries
        search_term = request.args.get('q', '')

        if search_term:
            results = models.Query.search(
                search_term,
                self.current_user.group_ids,
                self.current_user.id,
                include_drafts=True,
            )
        else:
            results = models.Query.all_queries(
                self.current_user.group_ids,
                self.current_user.id,
                drafts=True,
            )

        results = filter_by_tags(results, models.Query.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_results = order_results(results, fallback=bool(search_term))

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        response = paginate(
            ordered_results,
            page=page,
            page_size=page_size,
            serializer=QuerySerializer,
            with_stats=True,
            with_last_modified_by=False
        )

        if search_term:
            self.record_event({
                'action': 'search',
                'object_type': 'query',
                'term': search_term,
            })
        else:
            self.record_event({
                'action': 'list',
                'object_type': 'query',
            })

        return response
示例#17
0
文件: queries.py 项目: moritz9/redash
    def get(self):
        """
        Retrieve a list of queries created by the current user.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number search: Full text search term

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        search_term = request.args.get('q', '')
        if search_term:
            results = models.Query.search_by_user(search_term, self.current_user)
        else:
            results = models.Query.by_user(self.current_user)

        results = filter_by_tags(results, models.Query.tags)

        # order results according to passed order parameter
        ordered_results = order_results(results)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        return paginate(
            ordered_results,
            page,
            page_size,
            QuerySerializer,
            with_stats=True,
            with_last_modified_by=False,
        )
示例#18
0
 def get(self):
     results = models.Query.all_queries(self.current_user.groups)
     page = request.args.get('page', 1, type=int)
     page_size = request.args.get('page_size', 25, type=int)
     return paginate(
         results, page, page_size,
         lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
示例#19
0
    def get(self):
        """
        Lists all accessible dashboards.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number q: Full text search term

        Responds with an array of :ref:`dashboard <dashboard-response-label>`
        objects.
        """
        search_term = request.args.get('q')

        if search_term:
            results = models.Dashboard.search(
                self.current_org,
                self.current_user.group_ids,
                self.current_user.id,
                search_term,
            )
        else:
            results = models.Dashboard.all(
                self.current_org,
                self.current_user.group_ids,
                self.current_user.id,
            )

        results = filter_by_tags(results, models.Dashboard.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_results = order_results(results,
                                        fallback=not bool(search_term))

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        response = paginate(
            ordered_results,
            page=page,
            page_size=page_size,
            serializer=serialize_dashboard,
        )

        if search_term:
            self.record_event({
                'action': 'search',
                'object_type': 'dashboard',
                'term': search_term,
            })
        else:
            self.record_event({
                'action': 'list',
                'object_type': 'dashboard',
            })

        return response
示例#20
0
 def get(self):
     drafts = request.args.get('drafts') is not None
     results = models.Query.by_user(self.current_user, drafts)
     page = request.args.get('page', 1, type=int)
     page_size = request.args.get('page_size', 25, type=int)
     return paginate(
         results, page, page_size,
         lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
示例#21
0
    def get(self):
        """
        Lists all accessible dashboards.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number q: Full text search term

        Responds with an array of :ref:`dashboard <dashboard-response-label>`
        objects.
        """
        search_term = request.args.get('q')

        if search_term:
            results = models.Dashboard.search(
                self.current_org,
                self.current_user.group_ids,
                self.current_user.id,
                search_term,
            )
        else:
            results = models.Dashboard.all(
                self.current_org,
                self.current_user.group_ids,
                self.current_user.id,
            )

        results = filter_by_tags(results, models.Dashboard.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_results = order_results(results, fallback=not bool(search_term))

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        response = paginate(
            ordered_results,
            page=page,
            page_size=page_size,
            serializer=serialize_dashboard,
        )

        if search_term:
            self.record_event({
                'action': 'search',
                'object_type': 'dashboard',
                'term': search_term,
            })
        else:
            self.record_event({
                'action': 'list',
                'object_type': 'dashboard',
            })

        return response
示例#22
0
    def get(self):
        """
        Retrieve a list of queries.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number q: Full text search term

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        # See if we want to do full-text search or just regular queries
        search_term = request.args.get('q', '')

        if search_term:
            results = models.Query.search(
                search_term,
                self.current_user.group_ids,
                self.current_user.id,
                include_drafts=True,
            )
        else:
            results = models.Query.all_queries(
                self.current_user.group_ids,
                self.current_user.id,
                drafts=True,
            )

        results = filter_by_tags(results, models.Query.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_results = order_results(results, fallback=bool(search_term))

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        response = paginate(ordered_results,
                            page=page,
                            page_size=page_size,
                            serializer=QuerySerializer,
                            with_stats=True,
                            with_last_modified_by=False)

        if search_term:
            self.record_event({
                'action': 'search',
                'object_type': 'query',
                'term': search_term,
            })
        else:
            self.record_event({
                'action': 'list',
                'object_type': 'query',
            })

        return response
示例#23
0
    def get(self):
        """
        Retrieve a list of queries.

        :qparam number page_size: Number of queries to return
        :qparam number page: Page number to retrieve

        Responds with an array of :ref:`query <query-response-label>` objects.
        """

        results = models.Query.all_queries(self.current_user.group_ids, self.current_user.id)
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
示例#24
0
    def get(self):
        """
        Retrieve a list of queries.

        :qparam number page_size: Number of queries to return
        :qparam number page: Page number to retrieve

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        
        results = models.Query.all_queries(self.current_user.group_ids, self.current_user.id)
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
示例#25
0
    def get(self):
        """
        Retrieve a list of queries created by the current user.

        :qparam number page_size: Number of queries to return
        :qparam number page: Page number to retrieve

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        drafts = request.args.get('drafts') is not None
        results = models.Query.by_user(self.current_user)
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
示例#26
0
    def get(self):
        """
        Retrieve a list of queries created by the current user.

        :qparam number page_size: Number of queries to return
        :qparam number page: Page number to retrieve

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        drafts = request.args.get('drafts') is not None
        results = models.Query.by_user(self.current_user)
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
示例#27
0
    def get(self):
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        groups = {
            group.id: group
            for group in models.Group.all(self.current_org)
        }

        def serialize_user(user):
            d = user.to_dict()
            user_groups = []
            for group_id in set(d['groups']):
                group = groups.get(group_id)

                if group:
                    user_groups.append({'id': group.id, 'name': group.name})

            d['groups'] = user_groups

            return d

        search_term = request.args.get('q', '')

        if request.args.get('disabled', None) is not None:
            users = models.User.all_disabled(self.current_org)
        else:
            users = models.User.all(self.current_org)

        if search_term:
            users = models.User.search(users, search_term)
            self.record_event({
                'action': 'search',
                'object_type': 'user',
                'term': search_term,
            })
        else:
            self.record_event({
                'action': 'list',
                'object_type': 'user',
            })

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_users = order_results(users, fallback=bool(search_term))

        return paginate(ordered_users, page, page_size, serialize_user)
示例#28
0
    def get(self, query_id):
        """
        Retrieve a query.

        :param query_id: ID of query to fetch

        Responds with the :ref:`query <query-response-label>` contents.
        """
        q = get_object_or_404(models.Query.get_by_id_and_org, query_id,
                              self.current_org)

        search_term = request.args.get('q')
        if search_term:
            results = models.Query.search_by_user(search_term,
                                                  self.current_user)
        else:
            results = models.Query.by_user(self.current_user)
        results = filter_by_tags(results, models.Query.tags)
        ordered_results = order_results(results,
                                        fallback=not bool(search_term))
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(
            ordered_results,
            page,
            page_size,
            QuerySerializer,
            with_stats=True,
            with_last_modified_by=False,
        )
        ids = []
        for r in response['results']:
            ids.append(r['id'])

        if q.id not in ids:
            require_access(q, self.current_user, view_only)

        result = QuerySerializer(q, with_visualizations=True).serialize()

        result['can_edit'] = can_modify(q, self.current_user)

        self.record_event({
            'action': 'view',
            'object_id': query_id,
            'object_type': 'query',
        })

        return result
示例#29
0
文件: queries.py 项目: vatssur/redash
    def get(self):
        """
        Retrieve a list of queries.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number q: Full text search term

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        # See if we want to do full-text search or just regular queries
        search_term = request.args.get("q", "")

        queries = self.get_queries(search_term)

        results = filter_by_tags(queries, models.Query.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_results = order_results(results,
                                        fallback=not bool(search_term))

        page = request.args.get("page", 1, type=int)
        page_size = request.args.get("page_size", 25, type=int)

        response = paginate(
            ordered_results,
            page=page,
            page_size=page_size,
            serializer=QuerySerializer,
            with_stats=True,
            with_last_modified_by=False,
        )

        if search_term:
            self.record_event({
                "action": "search",
                "object_type": "query",
                "term": search_term
            })
        else:
            self.record_event({"action": "list", "object_type": "query"})

        return response
示例#30
0
    def get(self):
        search_term = request.args.get("q")

        if search_term:
            base_query = models.Query.search(
                search_term,
                self.current_user.group_ids,
                include_drafts=True,
                limit=None,
            )
            favorites = models.Query.favorites(self.current_user, base_query=base_query)
        else:
            favorites = models.Query.favorites(self.current_user)

        favorites = filter_by_tags(favorites, models.Query.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_favorites = order_results(favorites, fallback=not bool(search_term))

        page = request.args.get("page", 1, type=int)
        page_size = request.args.get("page_size", 25, type=int)
        response = paginate(
            ordered_favorites,
            page,
            page_size,
            QuerySerializer,
            with_stats=True,
            with_last_modified_by=False,
        )

        self.record_event(
            {
                "action": "load_favorites",
                "object_type": "query",
                "params": {
                    "q": search_term,
                    "tags": request.args.getlist("tags"),
                    "page": page,
                },
            }
        )

        return response
示例#31
0
    def get(self):
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        groups = {group.id: group for group in models.Group.all(self.current_org)}

        def serialize_user(user):
            d = user.to_dict()
            user_groups = []
            for group_id in set(d['groups']):
                group = groups.get(group_id)

                if group:
                    user_groups.append({'id': group.id, 'name': group.name})

            d['groups'] = user_groups

            return d

        search_term = request.args.get('q', '')

        if request.args.get('disabled', None) is not None:
            users = models.User.all_disabled(self.current_org)
        else:
            users = models.User.all(self.current_org)

        if search_term:
            users = models.User.search(users, search_term)
            self.record_event({
                'action': 'search',
                'object_type': 'user',
                'term': search_term,
            })
        else:
            self.record_event({
                'action': 'list',
                'object_type': 'user',
            })

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_users = order_results(users, fallback=bool(search_term))

        return paginate(ordered_users, page, page_size, serialize_user)
示例#32
0
    def get(self):
        """
        Lists all accessible dashboards.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number q: Full text search term

        Responds with an array of :ref:`dashboard <dashboard-response-label>`
        objects.
        """
        search_term = request.args.get('q')

        if search_term:
            results = models.Dashboard.search(
                self.current_org,
                self.current_user.group_ids,
                self.current_user.id,
                search_term,
                'include_drafts' in request.args,
            )
        else:
            results = models.Dashboard.all(
                self.current_org,
                self.current_user.group_ids,
                self.current_user.id,
            )

        results = filter_by_tags(results, models.Dashboard.tags)

        # order results according to passed order parameter
        ordered_results = order_results(results)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        response = paginate(
            ordered_results,
            page=page,
            page_size=page_size,
            serializer=serialize_dashboard,
        )

        return response
示例#33
0
    def get(self):
        """
        Lists all accessible dashboards.
        """
        search_term = request.args.get('q')

        if search_term:
            results = models.Dashboard.search(self.current_org, self.current_user.group_ids, self.current_user.id, search_term, 'include_drafts' in request.args)
        else:
            results = models.Dashboard.all(self.current_org, self.current_user.group_ids, self.current_user.id)

        results = filter_by_tags(results, models.Dashboard.tags)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(results, page, page_size, serialize_dashboard)

        return response
示例#34
0
    def get(self):
        """
        Retrieve a list of queries.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number q: Full text search term

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        # See if we want to do full-text search or just regular queries
        search_term = request.args.get('q', '')

        if search_term:
            results = models.Query.search(
                search_term,
                self.current_user.group_ids,
                self.current_user.id,
                include_drafts=True,
            )
        else:
            results = models.Query.all_queries(
                self.current_user.group_ids,
                self.current_user.id,
                drafts=True,
            )

        results = filter_by_tags(results, models.Query.tags)

        # order results according to passed order parameter
        ordered_results = order_results(results)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        response = paginate(ordered_results,
                            page=page,
                            page_size=page_size,
                            serializer=QuerySerializer,
                            with_stats=True,
                            with_last_modified_by=False)

        return response
示例#35
0
    def get(self):
        """
        Lists all accessible dashboards.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number q: Full text search term

        Responds with an array of :ref:`dashboard <dashboard-response-label>`
        objects.
        """
        search_term = request.args.get('q')

        if search_term:
            results = models.Dashboard.search(
                self.current_org,
                self.current_user.group_ids,
                self.current_user.id,
                search_term,
            )
        else:
            results = models.Dashboard.all(
                self.current_org,
                self.current_user.group_ids,
                self.current_user.id,
            )

        results = filter_by_tags(results, models.Dashboard.tags)

        # order results according to passed order parameter
        ordered_results = order_results(results)

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        response = paginate(
            ordered_results,
            page=page,
            page_size=page_size,
            serializer=serialize_dashboard,
        )

        return response
示例#36
0
def public_all_dashboards():
    """
    Lists all accessible public dashboards.
    """
    logger.info(
        "/api/public/all_dashboards - PublicDashboardListResource/get()")

    results = models.Dashboard.all_public()

    page = request.args.get('page', 1, type=int)
    page_size = request.args.get('page_size', 25, type=int)
    response = paginate(results, page, page_size, serialize_public_dashboard)
    # logging.debug("public_dashboards response: %s", response)

    # return json_response(response)
    headers = {}
    add_cors_headers(headers)
    data = json.dumps(response, cls=utils.JSONEncoder)
    return make_response(data, 200, headers)
示例#37
0
    def get(self):
        search_term = request.args.get('q')

        if search_term:
            base_query = models.Query.search(search_term,
                                             self.current_user.group_ids,
                                             include_drafts=True,
                                             limit=None)
            favorites = models.Query.favorites(self.current_user,
                                               base_query=base_query)
        else:
            favorites = models.Query.favorites(self.current_user)

        favorites = filter_by_tags(favorites, models.Query.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_favorites = order_results(favorites,
                                          fallback=bool(search_term))

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(
            ordered_favorites,
            page,
            page_size,
            QuerySerializer,
            with_stats=True,
            with_last_modified_by=False,
        )

        self.record_event({
            'action': 'load_favorites',
            'object_type': 'query',
            'params': {
                'q': search_term,
                'tags': request.args.getlist('tags'),
                'page': page
            }
        })

        return response
示例#38
0
def public_dashboards():
    """
    Lists all accessible public dashboards.
    """
    logger.info("/api/public/dashboards - PublicDashboardListResource/get()")
    langSlug = request.args.get('lang')
    # return all public dashboard of sepcific language and also those who does not set the language
    results = models.Dashboard.all_public(langSlug)

    page = request.args.get('page', 1, type=int)
    page_size = request.args.get('page_size', 25, type=int)
    response = paginate(results, page, page_size, serialize_public_dashboard)
    # logging.debug("public_dashboards response: %s", response)

    # return json_response(response)
    headers = {}
    add_cors_headers(headers)
    data = json.dumps(response, cls=utils.JSONEncoder)
    return make_response(data, 200, headers)
示例#39
0
    def get(self):
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        groups = {group.id: group for group in models.Group.all(self.current_org)}

        def serialize_user(user):
            d = user.to_dict()
            user_groups = []
            for group_id in set(d['groups']):
                group = groups.get(group_id)

                if group:
                    user_groups.append({'id': group.id, 'name': group.name})

            d['groups'] = user_groups

            return d

        search_term = request.args.get('q', '')

        if request.args.get('disabled', None) is not None:
            users = models.User.all_disabled(self.current_org)
        else:
            users = models.User.all(self.current_org)

        if search_term:
            users = models.User.search(users, search_term)
            self.record_event({
                'action': 'search',
                'object_type': 'user',
                'term': search_term,
            })
        else:
            self.record_event({
                'action': 'list',
                'object_type': 'user',
            })

        users = order_results(users)

        return paginate(users, page, page_size, serialize_user)
示例#40
0
    def get(self):
        search_term = request.args.get("q")

        if search_term:
            base_query = models.Dashboard.search(
                self.current_org,
                self.current_user.group_ids,
                self.current_user.id,
                search_term,
            )
            favorites = models.Dashboard.favorites(
                self.current_user, base_query=base_query
            )
        else:
            favorites = models.Dashboard.favorites(self.current_user)

        favorites = filter_by_tags(favorites, models.Dashboard.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        favorites = order_results(favorites, fallback=not bool(search_term))

        page = request.args.get("page", 1, type=int)
        page_size = request.args.get("page_size", 25, type=int)
        # TODO: we don't need to check for favorite status here
        response = paginate(favorites, page, page_size, DashboardSerializer)

        self.record_event(
            {
                "action": "load_favorites",
                "object_type": "dashboard",
                "params": {
                    "q": search_term,
                    "tags": request.args.getlist("tags"),
                    "page": page,
                },
            }
        )

        return response
示例#41
0
    def get(self):
        search_term = request.args.get('q')

        if search_term:
            base_query = models.Query.search(search_term, self.current_user.group_ids, include_drafts=True, limit=None)
            favorites = models.Query.favorites(self.current_user, base_query=base_query)
        else:
            favorites = models.Query.favorites(self.current_user)

        favorites = filter_by_tags(favorites, models.Query.tags)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_favorites = order_results(favorites, fallback=bool(search_term))

        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)
        response = paginate(
            ordered_favorites,
            page,
            page_size,
            QuerySerializer,
            with_stats=True,
            with_last_modified_by=False,
        )

        self.record_event({
            'action': 'load_favorites',
            'object_type': 'query',
            'params': {
                'q': search_term,
                'tags': request.args.getlist('tags'),
                'page': page
            }
        })

        return response
示例#42
0
    def get(self):
        page = request.args.get('page', 1, type=int)
        page_size = request.args.get('page_size', 25, type=int)

        return paginate(self.current_org.events, page, page_size,
                        serialize_event)
示例#43
0
 def test_raises_error_for_bad_page_size(self):
     self.assertRaises(BadRequest, lambda: paginate(self.query_set, 1, 251, lambda x: x))
     self.assertRaises(BadRequest, lambda: paginate(self.query_set, 1, -1, lambda x: x))
示例#44
0
 def get(self):
     page = request.args.get('page', 1, type=int)
     page_size = request.args.get('page_size', 25, type=int)
     return paginate(self.current_org.events, page, page_size, serialize_event)
示例#45
0
 def get(self):
     results = models.Query.all_queries(self.current_user.groups)
     page = request.args.get('page', 1, type=int)
     page_size = request.args.get('page_size', 25, type=int)
     return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
示例#46
0
 def test_returns_paginated_results(self):
     page = paginate(self.query_set, 1, 25, lambda x: x)
     self.assertEqual(page['page'], 1)
     self.assertEqual(page['page_size'], 25)
     self.assertEqual(page['count'], 102)
     self.assertEqual(page['results'], dummy_results.items)
示例#47
0
 def get(self):
     drafts = request.args.get('drafts') is not None
     results = models.Query.by_user(self.current_user, drafts)
     page = request.args.get('page', 1, type=int)
     page_size = request.args.get('page_size', 25, type=int)
     return paginate(results, page, page_size, lambda q: q.to_dict(with_stats=True, with_last_modified_by=False))
示例#48
0
 def test_raises_error_for_bad_page_size(self):
     self.assertRaises(
         BadRequest, lambda: paginate(self.query_set, 1, 251, lambda x: x))
     self.assertRaises(BadRequest,
                       lambda: paginate(self.query_set, 1, -1, lambda x: x))