Exemple #1
0
def public_dashboard(token, org_slug=None):
    # TODO: verify object is a dashboard?
    if not isinstance(current_user, models.ApiUser):
        api_key = get_object_or_404(models.ApiKey.get_by_api_key, token)
        dashboard = api_key.object
    else:
        dashboard = current_user.object

    user = {'permissions': [], 'apiKey': current_user.id}

    headers = {
        'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate'
    }

    record_event(
        current_org, current_user, {
            'action': 'view',
            'object_id': dashboard.id,
            'object_type': 'dashboard',
            'public': True,
            'headless': 'embed' in request.args,
            'referer': request.headers.get('Referer')
        })

    response = render_template(
        "public.html",
        headless='embed' in request.args,
        user=json.dumps(user),
        seed_data=json_dumps(
            {'dashboard': serializers.public_dashboard(dashboard)}),
        client_config=json.dumps(settings.COMMON_CLIENT_CONFIG))

    return response, 200, headers
Exemple #2
0
def public_dashboard(token, org_slug=None):
    # TODO: verify object is a dashboard?
    if not isinstance(current_user, models.ApiUser):
        api_key = models.ApiKey.get_by_api_key(token)
        dashboard = api_key.object
    else:
        dashboard = current_user.object

    user = {
        'permissions': [],
        'apiKey': current_user.id
    }

    headers = {
        'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate'
    }

    response = render_template("public.html",
                               headless='embed' in request.args,
                               user=json.dumps(user),
                               seed_data=json_dumps({
                                 'dashboard': serializers.public_dashboard(dashboard)
                               }),
                               base_href=base_href(),
                               name=settings.NAME,
                               client_config=json.dumps(settings.COMMON_CLIENT_CONFIG),
                               analytics=settings.ANALYTICS)

    return response, 200, headers
Exemple #3
0
def public_dashboard(token, org_slug=None):
    # TODO: verify object is a dashboard?
    if not isinstance(current_user, models.ApiUser):
        api_key = models.ApiKey.get_by_api_key(token)
        dashboard = api_key.object
    else:
        dashboard = current_user.object

    user = {'permissions': [], 'apiKey': current_user.id}

    headers = {
        'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate'
    }

    response = render_template(
        "public.html",
        headless='embed' in request.args,
        user=json.dumps(user),
        seed_data=json_dumps(
            {'dashboard': serializers.public_dashboard(dashboard)}),
        base_href=base_href(),
        name=settings.NAME,
        client_config=json.dumps(settings.COMMON_CLIENT_CONFIG),
        analytics=settings.ANALYTICS)

    return response, 200, headers
Exemple #4
0
def public_dashboard(token, org_slug=None):
    # TODO: verify object is a dashboard?
    if not isinstance(current_user, models.ApiUser):
        api_key = models.ApiKey.get_by_api_key(token)
        dashboard = api_key.object
    else:
        dashboard = current_user.object

    user = {
        'permissions': [],
        'apiKey': current_user.id
    }

    headers = {
        'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate'
    }

    record_event(current_org, current_user, {
        'action': 'view',
        'object_id': dashboard.id,
        'object_type': 'dashboard',
        'public': True,
        'headless': 'embed' in request.args,
        'referer': request.headers.get('Referer')
    })

    response = render_template("public.html",
                               headless='embed' in request.args,
                               user=json.dumps(user),
                               seed_data=json_dumps({
                                 'dashboard': serializers.public_dashboard(dashboard)
                               }),
                               client_config=json.dumps(settings.COMMON_CLIENT_CONFIG))

    return response, 200, headers
Exemple #5
0
    def get(self, token):
        if not isinstance(self.current_user, models.ApiUser):
            api_key = get_object_or_404(models.ApiKey.get_by_api_key, token)
            dashboard = api_key.object
        else:
            dashboard = self.current_user.object

        return serializers.public_dashboard(dashboard)
Exemple #6
0
    def test_success(self):
        d1 = self.factory.create_dashboard()
        access_token = self.factory.create_access_token()
        rv = self.make_request(
            "get",
            "/api/dashboards/embed/{}?access_token={}".format(d1.id, access_token),
        )
        self.assertEqual(rv.status_code, 200)

        expected = public_dashboard(d1)
        actual = json_loads(rv.data)

        self.assertResponseEqual(expected, actual)
Exemple #7
0
    def get(self, token):
        """
        Retrieve a public dashboard.

        :param token: An API key for a public dashboard.
        :>json array widgets: An array of arrays of :ref:`public widgets <public-widget-label>`, corresponding to the rows and columns the widgets are displayed in
        """
        if not isinstance(self.current_user, models.ApiUser):
            api_key = get_object_or_404(models.ApiKey.get_by_api_key, token)
            dashboard = api_key.object
        else:
            dashboard = self.current_user.object

        return serializers.public_dashboard(dashboard)
Exemple #8
0
    def get(self, token):
        """
        Retrieve a public dashboard.

        :param token: An API key for a public dashboard.
        :>json array widgets: An array of arrays of :ref:`public widgets <public-widget-label>`, corresponding to the rows and columns the widgets are displayed in
        """
        if not isinstance(self.current_user, models.ApiUser):
            api_key = get_object_or_404(models.ApiKey.get_by_api_key, token)
            dashboard = api_key.object
        else:
            dashboard = self.current_user.object

        return serializers.public_dashboard(dashboard)
Exemple #9
0
    def get(self, token):
        """
        Retrieve a public dashboard.

        :param token: An API key for a public dashboard.
        :>json array widgets: An array of arrays of :ref:`public widgets <public-widget-label>`, corresponding to the rows and columns the widgets are displayed in
        """

        api_key = get_object_or_404(models.ApiKey.get_by_api_key, token)
        dashboard = api_key.object

        if dashboard is None:
            abort(404)

        return serializers.public_dashboard(dashboard)
Exemple #10
0
    def get(self, token):
        """
        Retrieve a public dashboard.

        :param token: An API key for a public dashboard.
        :>json array widgets: An array of arrays of :ref:`public widgets <public-widget-label>`, corresponding to the rows and columns the widgets are displayed in
        """
        if self.current_org.get_setting("disable_public_urls"):
            abort(400, message="Public URLs are disabled.")

        if not isinstance(self.current_user, models.ApiUser):
            api_key = get_object_or_404(models.ApiKey.get_by_api_key, token)
            dashboard = api_key.object
        else:
            dashboard = self.current_user.object

        return public_dashboard(dashboard)
Exemple #11
0
    def get(self, token):
        """
        Retrieve a public dashboard.

        :param token: An API key for a public dashboard.
        :>json array widgets: An array of arrays of :ref:`public widgets <public-widget-label>`, corresponding to the rows and columns the widgets are displayed in
        """
        if settings.FEATURE_DISABLE_PUBLIC_DASHBOARDS:
            logging.info("Disabled public dashboards.")
            abort(403, message="The feature is disabled due to security reasons.")

        if not isinstance(self.current_user, models.ApiUser):
            api_key = get_object_or_404(models.ApiKey.get_by_api_key, token)
            dashboard = api_key.object
        else:
            dashboard = self.current_user.object

        return serializers.public_dashboard(dashboard)
Exemple #12
0
    def get(self, dashboard_id):
        """
        Retrieve a embed dashboard.

        :qparam number id: Id of dashboard to retrieve
        :>json array widgets: An array of arrays of :ref:`embed widgets <public-widget-label>`, corresponding to the rows and columns the widgets are displayed in
        """
        if self.current_org.get_setting("disable_embed_urls"):
            abort(400, message="Embed URLs are disabled.")

        if request.args.get("legacy") is not None:
            fn = models.Dashboard.get_by_slug_and_org
        else:
            fn = models.Dashboard.get_by_id_and_org

        dashboard = get_object_or_404(fn, dashboard_id, self.current_org)
    
        return public_dashboard(dashboard)