Perms are kept from getting duped, created on save
This commit is contained in:
parent
b4c8d7a81e
commit
6ea178eced
|
|
@ -64,7 +64,7 @@ function initializeDatasourceView() {
|
|||
}
|
||||
})
|
||||
add_filter();
|
||||
$("#druidify").click(druidify);
|
||||
$(".druidify").click(druidify);
|
||||
|
||||
function create_choices(term, data) {
|
||||
var filtered = $(data).filter(function() {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,16 @@
|
|||
<h3>
|
||||
{{ datasource.name }}
|
||||
{% if datasource.description %}
|
||||
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="bottom" title="{{ datasource.description }}"></i>
|
||||
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="bottom" title="{{ datasource.description }}"></i>
|
||||
{% endif %}
|
||||
<a href="/{{ datasource.baselink }}/edit/{{ datasource.id }}">
|
||||
<i class="fa fa-edit"></i>
|
||||
</a>
|
||||
<div class="btn-group pull-right" role="group" >
|
||||
<a class="btn btn-default" href="/{{ datasource.baselink }}/edit/{{ datasource.id }}" data-toggle="tooltip" title="Edit datasource">
|
||||
<i class="fa fa-edit"></i>
|
||||
</a>
|
||||
<button type="button" class="btn btn-default druidify" data-toggle="tooltip" title="Druidify!">
|
||||
<i class="fa fa-bolt"></i>
|
||||
</button>
|
||||
</div>
|
||||
</h3>
|
||||
|
||||
<hr>
|
||||
|
|
@ -68,7 +73,7 @@
|
|||
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
||||
</button>
|
||||
<hr>
|
||||
<button type="button" class="btn btn-primary" id="druidify">
|
||||
<button type="button" class="btn btn-primary druidify">
|
||||
<i class="fa fa-bolt"></i>
|
||||
Druidify!
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -63,6 +63,12 @@ def dttm_from_timtuple(d):
|
|||
d.tm_year, d.tm_mon, d.tm_mday, d.tm_hour, d.tm_min, d.tm_sec)
|
||||
|
||||
|
||||
def merge_perm(sm, permission_name, view_menu_name):
|
||||
pv = sm.find_permission_view_menu(permission_name, view_menu_name)
|
||||
if not pv:
|
||||
sm.add_permission_view_menu(permission_name, view_menu_name)
|
||||
|
||||
|
||||
def parse_human_timedelta(s):
|
||||
"""
|
||||
Use the parsedatetime lib to return ``datetime.datetime`` from human
|
||||
|
|
@ -118,9 +124,12 @@ def init():
|
|||
"""
|
||||
from panoramix import appbuilder
|
||||
from panoramix import models
|
||||
from flask_appbuilder.security.sqla import models as ab_models
|
||||
sm = appbuilder.sm
|
||||
alpha = sm.add_role("Alpha")
|
||||
from flask_appbuilder.security.sqla import models as ab_models
|
||||
|
||||
merge_perm(sm, 'all_datasource_access', 'all_datasource_access')
|
||||
|
||||
perms = db.session.query(ab_models.PermissionView).all()
|
||||
for perm in perms:
|
||||
if perm.view_menu.name not in (
|
||||
|
|
@ -142,10 +151,13 @@ def init():
|
|||
'can_save',
|
||||
'can_download',
|
||||
'muldelete',
|
||||
'all_datasource_access',
|
||||
)):
|
||||
sm.add_permission_role(gamma, perm)
|
||||
session = db.session()
|
||||
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)
|
||||
table_perms = [
|
||||
table.perm for table in session.query(models.SqlaTable).all()]
|
||||
table_perms += [
|
||||
table.perm for table in session.query(models.Datasource).all()]
|
||||
for table_perm in table_perms:
|
||||
merge_perm(sm, 'datasource_access', table.perm)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from pydruid.client import doublesum
|
|||
from sqlalchemy import create_engine
|
||||
from wtforms.validators import ValidationError
|
||||
|
||||
from panoramix import appbuilder, db, models, viz, utils, app
|
||||
from panoramix import appbuilder, db, models, viz, utils, app, sm
|
||||
|
||||
config = app.config
|
||||
|
||||
|
|
@ -124,10 +124,17 @@ class TableView(PanoramixModelView, DeleteMixin):
|
|||
related_views = [TableColumnInlineView, SqlMetricInlineView]
|
||||
|
||||
def post_add(self, table):
|
||||
table.fetch_metadata()
|
||||
try:
|
||||
table.fetch_metadata()
|
||||
except Exception as e:
|
||||
flash(
|
||||
"Table [{}] doesn't seem to exist, "
|
||||
"couldn't fetch metadata".format(table.table_name),
|
||||
"danger")
|
||||
utils.merge_perm(sm, 'datasource_access', table.perm)
|
||||
|
||||
def post_update(self, table):
|
||||
table.fetch_metadata()
|
||||
self.post_add(table)
|
||||
|
||||
appbuilder.add_view(
|
||||
TableView,
|
||||
|
|
@ -203,10 +210,10 @@ class DatasourceModelView(PanoramixModelView, DeleteMixin):
|
|||
|
||||
def post_add(self, datasource):
|
||||
datasource.generate_metrics()
|
||||
utils.merge_perm(sm, 'datasource_access', table.perm)
|
||||
|
||||
def post_update(self, datasource):
|
||||
datasource.generate_metrics()
|
||||
|
||||
self.post_add(datasource)
|
||||
|
||||
appbuilder.add_view(
|
||||
DatasourceModelView,
|
||||
|
|
@ -244,10 +251,11 @@ class Panoramix(BaseView):
|
|||
.first()
|
||||
)
|
||||
|
||||
if 'Gamma' in [r.name for r in g.user.roles]:
|
||||
all_datasource_access = self.appbuilder.sm.has_access(
|
||||
'all_datasource_access', 'all_datasource_access')
|
||||
datasource_access = self.appbuilder.sm.has_access(
|
||||
'datasource_access', datasource.perm)
|
||||
if not datasource_access:
|
||||
if not all_datasource_access or not datasource_access:
|
||||
flash(
|
||||
"You don't seem to have access to this datasource",
|
||||
"danger")
|
||||
|
|
|
|||
Loading…
Reference in New Issue