Beispiel #1
0
def register_extensions(app):
    babel.init_app(app)
    bootstrap.init_app(app)
    AdminLTE(app)
    mail.init_app(app)
    sqla.init_app(app)
    login_manager.init_app(app)

    # Flask potion do not initialize with current Flask app, so the below line
    # is the work-around for potion to init_app correctly.
    api.app = app
    api.decorators = [login_required]
    api.default_manager = principals(PgsPotionManager)
    api.init_app(app)
Beispiel #2
0
@identity_loaded.connect_via(app)
def on_identity_loaded(sender, identity):

    if not isinstance(identity, AnonymousIdentity):
        identity.provides.add(UserNeed(identity.id))

        if current_user.is_editor:
            identity.provides.add(RoleNeed('editor'))

        if current_user.is_admin:
            identity.provides.add(RoleNeed('admin'))


api = Api(app,
          decorators=[login_required],
          default_manager=principals(SQLAlchemyManager))


class UserResource(ModelResource):
    class Meta:
        model = User


class ArticleResource(ModelResource):
    class Schema:
        author = fields.ToOne('user')

    class Meta:
        model = Article
        read_only_fields = ['author']
        permissions = {'create': 'editor', 'update': ['user:author', 'admin']}
 class Meta:
     manager = principals(SQLAlchemyManager)
 def test_role(self):
     with self.assertRaises(RuntimeError):
         principals(MemoryManager)
@identity_loaded.connect_via(app)
def on_identity_loaded(sender, identity):

    if not isinstance(identity, AnonymousIdentity):
        identity.provides.add(UserNeed(identity.id))

        if current_user.is_editor:
            identity.provides.add(RoleNeed('editor'))

        if current_user.is_admin:
            identity.provides.add(RoleNeed('admin'))


api = Api(app,
          decorators=[login_required],
          default_manager=principals(SQLAlchemyManager))


class UserResource(ModelResource):
    class Meta:
        model = User


class ArticleResource(ModelResource):
    class Schema:
        author = fields.ToOne('user')

    class Meta:
        model = Article
        read_only_fields = ['author']
        permissions = {
 def test_role(self):
     with self.assertRaises(RuntimeError):
         manager = principals(MemoryManager)