Ejemplo n.º 1
0
from flask import render_template, request, redirect, url_for, flash
from flask_login import current_user, login_user, logout_user

from redash import models, settings
from redash.wsgi import app
from redash.handlers import org_scoped_rule
from redash.authentication.org_resolving import current_org
from redash.authentication.helper import get_login_url


@app.route(org_scoped_rule('/login'), methods=['GET', 'POST'])
def login(org_slug=None):
    index_url = url_for("index", org_slug=org_slug)
    next_path = request.args.get('next', index_url)

    if current_user.is_authenticated:
        return redirect(next_path)

    if not settings.PASSWORD_LOGIN_ENABLED:
        if settings.SAML_LOGIN_ENABLED:
            return redirect(url_for("saml_auth.sp_initiated", next=next_path))
        else:
            return redirect(url_for("google_oauth.authorize", next=next_path))

    if request.method == 'POST':
        try:
            user = models.User.get_by_email_and_org(request.form['email'], current_org.id)
            if user and user.verify_password(request.form['password']):
                remember = ('remember' in request.form)
                login_user(user, remember=remember)
                return redirect(next_path)
Ejemplo n.º 2
0
from flask import render_template, url_for
from flask.ext.restful import abort

from flask_login import login_required

from redash import models, settings
from redash.wsgi import app
from redash.utils import json_dumps
from redash.handlers import org_scoped_rule
from redash.authentication.org_resolving import current_org


@app.route(org_scoped_rule(
    '/embed/query/<query_id>/visualization/<visualization_id>'),
           methods=['GET'])
@login_required
def embed(query_id, visualization_id, org_slug=None):
    # TODO: add event for embed access
    query = models.Query.get_by_id_and_org(query_id, current_org)
    vis = query.visualizations.where(
        models.Visualization.id == visualization_id).first()
    qr = {}

    if vis is not None:
        vis = vis.to_dict()
        qr = query.latest_query_data
        if qr is None:
            abort(400, message="No Results for this query")
        else:
            qr = qr.to_dict()
    else:
Ejemplo n.º 3
0
def register_static_routes(rules):
    # Make sure that / is the first route considered as index.
    app.add_url_rule(org_scoped_rule("/"), "index", index)

    for rule in rules:
        app.add_url_rule(org_scoped_rule(rule), None, index)
Ejemplo n.º 4
0
from flask import render_template
from flask.ext.restful import abort

from flask_login import login_required

from redash import models, settings
from redash.wsgi import app
from redash.utils import json_dumps
from redash.handlers import org_scoped_rule
from redash.authentication.org_resolving import current_org


@app.route(org_scoped_rule('/embed/query/<query_id>/visualization/<visualization_id>'), methods=['GET'])
@login_required
def embed(query_id, visualization_id, org_slug=None):
    # TODO: add event for embed access
    query = models.Query.get_by_id_and_org(query_id, current_org)
    vis = query.visualizations.where(models.Visualization.id == visualization_id).first()
    qr = {}

    if vis is not None:
        vis = vis.to_dict()
        qr = query.latest_query_data
        if qr is None:
            abort(400, message="No Results for this query")
        else:
            qr = qr.to_dict()
    else:
        abort(404, message="Visualization not found.")

    client_config = {}
Ejemplo n.º 5
0
def register_static_routes(rules):
    # Make sure that / is the first route considered as index.
    app.add_url_rule(org_scoped_rule("/"), "index", index)

    for rule in rules:
        app.add_url_rule(org_scoped_rule(rule), None, index)
Ejemplo n.º 6
0
from funcy import project
from flask import render_template, url_for, request
from flask_login import login_required, current_user
from flask_restful import abort

from redash import models, settings
from redash import serializers
from redash.wsgi import app
from redash.utils import json_dumps
from redash.handlers import org_scoped_rule, base_href
from redash.permissions import require_access, view_only
from redash.authentication.org_resolving import current_org


@app.route(org_scoped_rule('/embed/query/<query_id>/visualization/<visualization_id>'), methods=['GET'])
@login_required
def embed(query_id, visualization_id, org_slug=None):
    # TODO: add event for embed access
    query = models.Query.get_by_id_and_org(query_id, current_org)
    require_access(query.groups, current_user, view_only)
    vis = query.visualizations.where(models.Visualization.id == visualization_id).first()
    qr = {}

    if vis is not None:
        vis = vis.to_dict()
        qr = query.latest_query_data
        if qr is None:
            abort(400, message="No Results for this query")
        else:
            qr = qr.to_dict()