Beispiel #1
0
def perm(app, db, request):
    app.config['PERM_DB'] = db
    app.config['PERM_USER_GETTER'] = lambda id: {'id': id, 'nickname': 'User%d' % id}
    app.config['PERM_USERS_GETTER'] = lambda: [
        app.config['PERM_USER_GETTER'](id) for id in range(20)
    ]
    g.user = {'id': 1, 'nickname': 'User1', 'is_allowed': True}
    app.config['PERM_CURRENT_USER_GETTER'] = lambda: g.user
    app.config['PERM_CURRENT_USER_ACCESS_VALIDATOR'] = lambda: g.user['is_allowed']
    app.config['PERM_URL_PREFIX'] = '/perm'
    perm = Perm()
    perm.app = app
    perm.init_app(app)
    db.create_all()
    return perm
Beispiel #2
0
def perm(app, request):
    def user_loader(id):
        return User(id=id, nickname='User%d' % id)

    def current_user_loader():
        return user_loader(1)

    def users_loader(**kwargs):
        return [user_loader(id) for id in range(20)]

    app.config['PERM_URL_PREFIX'] = '/perm'
    app.config['PERM_ADMIN_USERNAME'] = '******'
    app.config['PERM_ADMIN_PASSWORD'] = '******'

    perm = Perm()
    perm.app = app
    perm.init_app(app)
    perm.user_loader(user_loader)
    perm.current_user_loader(current_user_loader)
    perm.users_loader(users_loader)

    db.create_all()

    return perm
Beispiel #3
0
def perm(app, request):
    def user_loader(id):
        return User(id=id, nickname='User%d'%id)

    def current_user_loader():
        return user_loader(1)

    def users_loader(**kwargs):
        return [user_loader(id) for id in range(20)]

    app.config['PERM_URL_PREFIX'] = '/perm'
    app.config['PERM_ADMIN_USERNAME'] = '******'
    app.config['PERM_ADMIN_PASSWORD'] = '******'

    perm = Perm()
    perm.app = app
    perm.init_app(app)
    perm.user_loader(user_loader)
    perm.current_user_loader(current_user_loader)
    perm.users_loader(users_loader)

    db.create_all()

    return perm
Beispiel #4
0
from flask_perm import Perm
from flask_script import Manager

app = Flask(__name__)
manager = Manager(app)
db = SQLAlchemy()
perm = Perm()
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'secret key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/flask_perm.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['PERM_ADMIN_ECHO'] = True

db.app = app
db.init_app(app)
perm.app = app
perm.init_app(app)
perm.register_commands(manager)


class User(namedtuple('User', 'id nickname')):
    pass


@app.before_request
def before_request():
    g.user = User(**{'id': 1, 'nickname': 'user1'})


@perm.user_loader
def load_user(user_id):
Beispiel #5
0
from flask_perm import Perm
from flask_script import Manager

app = Flask(__name__)
manager = Manager(app)
db = SQLAlchemy()
perm = Perm()
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'secret key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/flask_perm.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['PERM_ADMIN_ECHO'] = True

db.app = app
db.init_app(app)
perm.app = app
perm.init_app(app)
perm.register_commands(manager)

class User(namedtuple('User', 'id nickname')):
    pass

@app.before_request
def before_request():
    g.user = User(**{'id': 1, 'nickname': 'user1'})

@perm.user_loader
def load_user(user_id):
    return User(**{'id': user_id, 'nickname': 'user%d' % user_id})

@perm.users_loader