diff --git a/panoramix/bin/panoramix b/panoramix/bin/panoramix index 461341e8c..cc96fc4d0 100755 --- a/panoramix/bin/panoramix +++ b/panoramix/bin/panoramix @@ -7,20 +7,18 @@ import json from subprocess import Popen from flask.ext.script import Manager +from panoramix import app from flask.ext.migrate import MigrateCommand from panoramix import db +from flask.ext.appbuilder import Base from sqlalchemy import Column, Integer, String, Table, DateTime - -from panoramix import app -from panoramix import models - +from panoramix import models, utils config = app.config manager = Manager(app) manager.add_command('db', MigrateCommand) -from flask.ext.appbuilder import Base @manager.option( '-d', '--debug', action='store_true', @@ -45,6 +43,11 @@ def runserver(debug, port): print("Starting server with command: " + cmd) Popen(cmd, shell=True).wait() +@manager.command +def init(): + """Inits the Panoramix application""" + utils.init() + @manager.option( '-s', '--sample', action='store_true', help="Only load 1000 rows (faster, used for testing)") diff --git a/panoramix/utils.py b/panoramix/utils.py index 3fc164517..31517e8ce 100644 --- a/panoramix/utils.py +++ b/panoramix/utils.py @@ -5,6 +5,7 @@ from sqlalchemy.types import TypeDecorator, TEXT import json import parsedatetime import functools +from panoramix import db class memoized(object): @@ -78,7 +79,6 @@ def parse_human_timedelta(s): return d - dttm - class JSONEncodedDict(TypeDecorator): """Represents an immutable structure as a json-encoded string.""" impl = TEXT @@ -93,6 +93,7 @@ class JSONEncodedDict(TypeDecorator): value = json.loads(value) return value + def color(s): """ Get a consistent color from the same string using a hash function @@ -109,3 +110,20 @@ def color(s): h = hashlib.md5(s) i = int(h.hexdigest(), 16) return colors[i % len(colors)] + + +def init(): + """ + Inits the Panoramix application with security roles and such + """ + from panoramix import appbuilder + sm = appbuilder.sm + alpha = sm.add_role("Alpha") + from flask_appbuilder.security.sqla import models + perms = db.session.query(models.PermissionView).all() + for perm in perms: + if perm.view_menu.name not in ( + 'UserDBModelView', 'RoleModelView', 'ResetPasswordView', + 'Security'): + sm.add_permission_role(alpha, perm) + sm.add_role("Gamma") diff --git a/tests/core_tests.py b/tests/core_tests.py index 24848d8ba..49d10d4ae 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -4,9 +4,8 @@ import unittest import urllib2 os.environ['PANORAMIX_CONFIG'] = 'tests.panoramix_test_config' from flask.ext.testing import LiveServerTestCase, TestCase -from flask_login import login_user -from panoramix import app, appbuilder, db, models +from panoramix import app, db, models, utils BASE_DIR = app.config.get("BASE_DIR") cli = imp.load_source('cli', BASE_DIR + "/bin/panoramix") @@ -21,6 +20,9 @@ class LiveTest(TestCase): def setUp(self): pass + def test_init(self): + utils.init() + def test_load_examples(self): cli.load_examples(sample=True)