Esempio n. 1
0
def test_Allows_identity_loader_func(member):
    allows = Allows()

    @allows.identity_loader
    def ident():
        return member

    assert allows._identity_loader is ident and allows._identity_loader() is member
Esempio n. 2
0
def test_Allows_init_app(app):
    allows = Allows()
    assert app.extensions == {}

    allows.init_app(app)
    assert hasattr(app, 'extensions') and allows is app.extensions['allows']
Esempio n. 3
0
                    query_class_name = query_class.__name__
                    model.query_class = type(
                        "Whooshee{}".format(query_class_name), (query_class, self.query), {}
                    )
                else:
                    model.query_class = self.query
            else:
                model.query_class = self.query

        if self.app:
            wh.app = self.app
        return wh


# Permissions Manager
allows = Allows(throws=AuthorizationRequired)

# Database
db = SQLAlchemy()

# Whooshee (Full Text Search)
whooshee = FlaskBBWhooshee()

# Login
login_manager = LoginManager()

# Mail
mail = Mail()

# Caching
cache = Cache()
Esempio n. 4
0
# from application.schedule import clock
from marshmallow_sqlalchemy import ModelSchema, field_for


class AnonymousUser(AnonymousUserMixin):
    id = '00000001'

    def get_id(self):
        return '00000001'


login_manager = LoginManager()
login_manager.anonymous_u00ser = AnonymousUser
mail = Mail()

allows = Allows()

admin = Admin(name='SHUhelper Violet', template_mode='bootstrap3')

cache = Cache()

redis_store = FlaskRedis(decode_responses=True)

db = SQLAlchemy()
db.UUID = UUID
ma = Marshmallow()
ma.field_for = field_for
celery = Celery()

# plugin_manager = PluginManager()
Esempio n. 5
0
def test_Permission_provide_ident(app, member, ismember):
    Allows(app=app)

    p = Permission(ismember, identity=member)

    assert p.identity is member
Esempio n. 6
0
# Cache
cache = Cache()

# Login
login_manager = LoginManager()

# Rate Limiting
limiter = Limiter(auto_check=True, key_func=get_remote_address)

# CORS
cors = CORS()

# Session
session = Session()

# Flask-Allows
allows = Allows(identity_loader=lambda: g.user)

# Flask-RESTful
api = Api()

# Flask-Debugtoolbar
toolbar = DebugToolbarExtension()

# Flask-Babel
babel = Babel()

# Flask-Gzip
gzip = Gzip(compress_level=9)
Esempio n. 7
0
def test_Allows_init_app(app):
    allows = Allows()
    assert app.extensions == {}

    allows.init_app(app)
    assert hasattr(app, 'extensions') and allows is app.extensions['allows']
Esempio n. 8
0
def test_Allows_fulfill_false(member, never, request):
    allows = Allows(identity_loader=lambda: member)
    assert not allows.fulfill([never])
Esempio n. 9
0
def test_Allows_fulfill_ident_override(member, guest, spy):
    allows = Allows(identity_loader=lambda: guest)
    allows.fulfill([spy], identity=member)
    assert spy.called_with['user'] is member
Esempio n. 10
0
def test_Allows_fulfill_false(member, never, request):
    allows = Allows(identity_loader=lambda: member)
    assert not allows.fulfill([never])
Esempio n. 11
0
def test_Allows_defaults():
    allows = Allows()
    assert allows._identity_loader is None and allows.throws is Forbidden
Esempio n. 12
0
def test_Allows_fulfill_true(member, always, request):
    allows = Allows(identity_loader=lambda: member)
    assert allows.fulfill([always])
    assert always.called_with == {'user': member, 'request': request}
Esempio n. 13
0
def test_Allows_custom_throws():
    myforbid = Forbidden()
    allows = Allows(throws=myforbid)

    assert allows.throws is myforbid
Esempio n. 14
0
def test_Allows_identity_loader_on_init(member):
    ident = lambda: member  # noqa
    allows = Allows(identity_loader=ident)
    assert allows._identity_loader is ident
Esempio n. 15
0
"""Backend for a proteomics database."""
from flask import Flask, jsonify, make_response, render_template
from ctesi.ldap import LDAPUserDatastore, LDAPLoginForm
from http import HTTPStatus
from redis import StrictRedis
from flask_sqlalchemy import SQLAlchemy
from flask_security import Security
from flask_migrate import Migrate
from flask_login import current_user
from flask_allows import Allows
from celery import Celery
import config.config as config

app = Flask(__name__)
app.config.from_object(config.config)
allows = Allows(app=app, identity_loader=lambda: current_user)

db = SQLAlchemy(app)
migrate = Migrate(app, db)

celery = Celery()
celery.config_from_object(config.CeleryConfig)

redis = StrictRedis(host='redis')

# Register blueprints
from ctesi.views import home, users, api_blueprint
app.register_blueprint(home)
app.register_blueprint(users)
app.register_blueprint(api_blueprint, url_prefix='/api')
Esempio n. 16
0
def test_Allows_fulfill_true(member, always, request):
    allows = Allows(identity_loader=lambda: member)
    assert allows.fulfill([always])
    assert always.called_with == {'user': member, 'request': request}
Esempio n. 17
0
from flask import redirect, url_for, request
from flask_login import LoginManager, current_user, login_url
from flask_allows import Allows

from .. import models

allows = Allows(identity_loader=lambda: current_user)


def is_admin(ident, request):
    return 'admin' in ident.roles


def is_developer(ident, request):
    return 'developer' in ident.roles


def is_staff(ident, request):
    return 'staff' in ident.roles


def init_acl(app):
    # initial login manager
    login_manager = LoginManager(app)

    @login_manager.user_loader
    def load_user(user_id):
        user = models.User.objects.with_id(user_id)
        return user
        # if user_id not in session:
        #     return User()
Esempio n. 18
0
def test_Allows_fulfill_ident_override(member, guest, spy):
    allows = Allows(identity_loader=lambda: guest)
    allows.fulfill([spy], identity=member)
    assert spy.called_with['user'] is member
Esempio n. 19
0
def test_Allows_config_with_app(app):
    allows = Allows(app)
    assert hasattr(app, 'extensions') and allows is app.extensions['allows']