forked from dcolish/Cockerel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/dcolish/Cockerel
- Loading branch information
Showing
56 changed files
with
225 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Cockerel TODO List for Winter Break | ||
|
||
* Features | ||
** Choose between simplifying radically or finishing users | ||
** Add config object for setting basic server options (command line options too?) | ||
** Clean up editor interface and display output correctly | ||
|
||
* Testing | ||
** Setup automated test runner | ||
** Develop more tests | ||
|
||
* Packaging | ||
** Debianize the whole thang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from util import login_required, permissions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" | ||
Permissions | ||
=========== | ||
Will specify what roles or attributes are needed to be held by an Identity for | ||
it to access a resource. The resource can be anything within the application. | ||
However, it should be restricted to page endpoints. Privileges which will be | ||
integrated later will restrict the access to data in a more fine grained manner | ||
""" | ||
from flaskext.principal import ( | ||
identity_loaded, | ||
Permission, | ||
RoleNeed, | ||
UserNeed, | ||
) | ||
|
||
|
||
def permission(*roles): | ||
perm = Permission(RoleNeed('none')) | ||
for x in roles: | ||
perm = perm.union(x) | ||
return perm | ||
|
||
|
||
class Permissions(dict): | ||
def __getattr__(self, attr): | ||
try: | ||
return self[attr] | ||
except: | ||
return super(self, dict).attr | ||
|
||
def __setattr__(self, attr, value): | ||
self[attr] = value | ||
|
||
permissions = Permissions() | ||
|
||
permissions.read = Permission(RoleNeed('read')) | ||
permissions.insert = Permission(RoleNeed('insert')) | ||
permissions.modify = Permission(RoleNeed('modify')) | ||
permissions.delete = Permission(RoleNeed('delete')) | ||
permissions.full_access = permission(permissions.delete, permissions.insert, | ||
permissions.modify, permissions.read) | ||
|
||
|
||
@identity_loaded.connect | ||
def set_owned_by(sender, identity): | ||
permissions.owned_by = Permission(UserNeed(identity.user)) | ||
permissions.modify_own_content = permission(permissions.owned_by, | ||
permissions.full_access) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
Security | ||
======== | ||
Inflate and set the users Identity. Works with `permission.Permissions` since | ||
all roles will be added to an Identity and then checked before routing. | ||
""" | ||
|
||
from flask import g, session | ||
from flaskext.principal import Identity | ||
|
||
|
||
from .permissions import principals | ||
from cockerel.models.schema import User | ||
|
||
|
||
def check_user(): | ||
g.identity = Identity(User.query.filter_by( | ||
username=session.get('username'))) | ||
|
||
|
||
@principals.identity_saver | ||
def set_user(identity): | ||
g.identity = identity | ||
session['username'] = identity.username |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# | ||
from admin import LoginForm, SignupForm | ||
|
||
from classes import AddEditClassForm | ||
|
||
from lessons import EditLessonForm |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# # | ||
# from flaskext.sqlalchemy import SQLAlchemy | ||
from flaskext.sqlalchemy import SQLAlchemy | ||
|
||
# from webapp import | ||
db = SQLAlchemy() | ||
|
||
# db = SQLAlchemy(app) | ||
__all__ = ['db'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from base import new_app | ||
|
||
__all__ = ['new_app'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
cockerel.webapp | ||
--------------- | ||
Main instance of the webapp. All modules will be loaded from this file. To | ||
add a new module you must import it here and register it. | ||
""" | ||
import logging | ||
import os | ||
|
||
from flask import g | ||
|
||
from flaskext.markdown import Markdown | ||
|
||
from cockerel.models import db | ||
|
||
from cockerel.webapp import ( | ||
admin, | ||
classes, | ||
frontend, | ||
lessons, | ||
prover, | ||
) | ||
from cockerel.webapp.prover import ProverExtension | ||
|
||
|
||
def update_config(app): | ||
"""syncronizes the config with the g global request object""" | ||
g.config = app.config | ||
|
||
|
||
def register_modules(app, mod_list): | ||
for x in mod_list: | ||
app.register_module(x) | ||
|
||
|
||
def new_app(app, serialize=False): | ||
logging.basicConfig(level=logging.DEBUG) | ||
md = Markdown(app, extensions=['tables']) | ||
md.register_extension(ProverExtension) | ||
register_modules(app, [admin, classes, frontend, lessons, prover]) | ||
app.secret_key = os.urandom(24) | ||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' | ||
app.config['COQD_HOST'] = 'localhost' | ||
app.config['COQD_PORT'] = 8003 | ||
if serialize: | ||
app.config['serialize'] = serialize | ||
|
||
# XXX:dc: kind of a hack but I want to keep the db and the app seperate | ||
db.init_app(app) | ||
db.app = app | ||
|
||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,12 @@ | ||
""" | ||
cockerel.webapp | ||
--------------- | ||
Main instance of the webapp. All modules will be loaded from this file. To | ||
add a new module you must import it here and register it. | ||
""" | ||
import logging | ||
import os | ||
# | ||
from flask import Flask | ||
|
||
from flask import Flask, g | ||
from flaskext.sqlalchemy import SQLAlchemy | ||
from flaskext.markdown import Markdown | ||
from admin import admin | ||
from frontend import frontend | ||
from classes import classes | ||
from lessons import lessons | ||
from prover import prover | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
HOST = "localhost" | ||
app = Flask(__name__) | ||
db = SQLAlchemy(app) | ||
md = Markdown(app, extensions=['tables']) | ||
|
||
from .views.prover.mdx_prover import ProverExtension | ||
md.register_extension(ProverExtension) | ||
|
||
from .views.admin import admin | ||
from .views.classes import classes | ||
from .views.frontend import frontend | ||
from .views.lessons import lessons | ||
from .views.prover.prover import prover | ||
from .utils import register_modules | ||
|
||
register_modules(app, [admin, classes, frontend, lessons, prover]) | ||
|
||
app.secret_key = os.urandom(24) | ||
|
||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' | ||
app.config['COQD_HOST'] = 'localhost' | ||
app.config['COQD_PORT'] = 8003 | ||
|
||
# see if the db exists, if not make it and initialize | ||
if not os.path.exists(app.config.get('SQLALCHEMY_DATABASE_URI')): | ||
db.create_all() | ||
|
||
|
||
def update_config(): | ||
"""syncronizes the config with the g global request object""" | ||
g.config = app.config | ||
|
||
app.before_request(update_config) | ||
|
||
|
||
def new_app(serialize): | ||
if serialize: | ||
app.config['serialize'] = serialize | ||
return app | ||
__all__ = ['admin', 'app', 'frontend', 'classes', 'lessons', 'prover'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# | ||
|
||
from .admin import admin | ||
|
||
__all__ = ['admin'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .classes import classes | ||
|
||
__all__ = ['classes'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from lessons import lessons | ||
|
||
__all__ = ['lessons'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from prover import prover | ||
from mdx_prover import ProverExtension | ||
|
||
__all__ = ['prover', 'ProverExtension'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.