Skip to content

Commit

Permalink
Automate Panoramix role creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Oct 4, 2015
1 parent 8eb0c0a commit c2049f8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
13 changes: 8 additions & 5 deletions panoramix/bin/panoramix
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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)")
Expand Down
20 changes: 19 additions & 1 deletion panoramix/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import parsedatetime
import functools
from panoramix import db


class memoized(object):
Expand Down Expand Up @@ -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
Expand All @@ -93,6 +93,7 @@ def process_result_value(self, value, dialect):
value = json.loads(value)
return value


def color(s):
"""
Get a consistent color from the same string using a hash function
Expand All @@ -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")
6 changes: 4 additions & 2 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
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")

Expand All @@ -21,6 +20,9 @@ def create_app(self):
def setUp(self):
pass

def test_init(self):
utils.init()

def test_load_examples(self):
cli.load_examples(sample=True)

Expand Down

0 comments on commit c2049f8

Please sign in to comment.