Skip to content

Commit

Permalink
Getting this thing to work
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Oct 4, 2015
1 parent e3cdf5b commit 71cf515
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
6 changes: 6 additions & 0 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ class SqlaTable(Model, Queryable, AuditMixinNullable):
def __repr__(self):
return self.table_name

@property
def perm(self):
return (
"[{self.database}].[{self.table_name}]"
"(id:{self.id})").format(self=self)

@property
def name(self):
return self.table_name
Expand Down
15 changes: 8 additions & 7 deletions panoramix/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date, datetime, timedelta
from datetime import datetime
from dateutil.parser import parse
import hashlib
from sqlalchemy.types import TypeDecorator, TEXT
Expand Down Expand Up @@ -117,10 +117,11 @@ def init():
Inits the Panoramix application with security roles and such
"""
from panoramix import appbuilder
from panoramix import models
sm = appbuilder.sm
alpha = sm.add_role("Alpha")
from flask_appbuilder.security.sqla import models
perms = db.session.query(models.PermissionView).all()
from flask_appbuilder.security.sqla import models as ab_models
perms = db.session.query(ab_models.PermissionView).all()
for perm in perms:
if perm.view_menu.name not in (
'UserDBModelView', 'RoleModelView', 'ResetPasswordView',
Expand All @@ -144,7 +145,7 @@ def init():
)):
sm.add_permission_role(gamma, perm)
session = db.session()
for i in range(100):
print(type(models.Table))
for table in session.query(models.Table).all():
print table
for table in session.query(models.SqlaTable).all():
sm.add_permission_view_menu('datasource_access', table.perm)
for druid_datasource in session.query(models.Datasource).all():
sm.add_permission_view_menu('datasource_access', druid_datasource.perm)
41 changes: 25 additions & 16 deletions panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import logging

from flask import request, redirect, flash, Response
from flask import request, redirect, flash, Response, g
from flask.ext.appbuilder import ModelView, CompactCRUDMixin, BaseView, expose
from flask.ext.appbuilder.actions import action
from flask.ext.appbuilder.models.sqla.interface import SQLAInterface
Expand Down Expand Up @@ -229,6 +229,29 @@ class Panoramix(BaseView):
@has_access
@expose("/datasource/<datasource_type>/<datasource_id>/")
def datasource(self, datasource_type, datasource_id):
if datasource_type == "table":
datasource = (
db.session
.query(models.SqlaTable)
.filter_by(id=datasource_id)
.first()
)
else:
datasource = (
db.session
.query(models.Datasource)
.filter_by(id=datasource_id)
.first()
)

if 'Gamma' in [r.name for r in g.user.roles]:
datasource_access = self.appbuilder.sm.has_access(
'datasource_access', datasource.perm)
if not datasource_access:
flash(
"You don't seem to have access to this datasource",
"danger")
return redirect('/')
action = request.args.get('action')
if action == 'save':
session = db.session()
Expand Down Expand Up @@ -263,22 +286,8 @@ def datasource(self, datasource_type, datasource_id):
session.add(obj)
session.commit()
flash("Slice <{}> has been added to the pie".format(slice_name), "info")
redirect(obj.slice_url)
return redirect(obj.slice_url)

if datasource_type == "table":
datasource = (
db.session
.query(models.SqlaTable)
.filter_by(id=datasource_id)
.first()
)
else:
datasource = (
db.session
.query(models.Datasource)
.filter_by(id=datasource_id)
.first()
)

if not datasource:
flash("The datasource seem to have been deleted", "alert")
Expand Down

0 comments on commit 71cf515

Please sign in to comment.