Example #1
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_manage(project))
    query = Permission.all()
    query = query.filter_by(project=project)
    pager = Pager(query)
    conv = lambda es: [permissions.to_rest_index(e) for e in es]
    return jsonify(pager.to_dict(conv))
Example #2
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_manage(project))
    query = Permission.all()
    query = query.filter_by(project=project)
    pager = Pager(query, slug=slug)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Example #3
0
def index(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_manage(project))
    query = Permission.all()
    query = query.filter_by(project=project)
    pager = Pager(query, slug=slug)
    validate_cache(keys=pager.cache_keys())
    return jsonify(pager, index=True)
Example #4
0
File: authz.py Project: 4bic/grano
def permissions():
    """ Cache the full matrix of which projects this user has access to. """
    if not hasattr(request, "permissions"):
        matrix = {"reader": set(), "editor": set(), "admin": set()}
        q = db.session.query(Project.id)
        q = q.filter(Project.private == False)
        matrix["reader"].update([id for id, in q.all()])

        if logged_in():
            q = Permission.all()
            q = q.filter_by(account=request.account)
            for perm in q.all():
                if perm.reader:
                    matrix["reader"].add(perm.project_id)
                if perm.editor:
                    matrix["editor"].add(perm.project_id)
                if perm.admin:
                    matrix["admin"].add(perm.project_id)
        request.permissions = matrix
    return request.permissions
Example #5
0
def permissions():
    """ Cache the full matrix of which projects this user has access to. """
    if not hasattr(request, 'permissions'):
        matrix = {'reader': set(), 'editor': set(), 'admin': set()}
        q = db.session.query(Project.id)
        q = q.filter(Project.private == False)
        matrix['reader'].update([id for id, in q.all()])

        if logged_in():
            q = Permission.all()
            q = q.filter_by(account=request.account)
            for perm in q.all():
                if perm.reader:
                    matrix['reader'].add(perm.project_id)
                if perm.editor:
                    matrix['editor'].add(perm.project_id)
                if perm.admin:
                    matrix['admin'].add(perm.project_id)
        request.permissions = matrix
    return request.permissions
Example #6
0
def save(data, permission=None):
    validator = PermissionValidator()
    data = validator.deserialize(data)

    if permission is None:
        q = Permission.all()
        q = q.filter(Permission.project == data["project"])
        q = q.filter(Permission.account == data["account"])
        permission = q.first()

    if permission is None:
        permission = Permission()
        permission.project = data.get("project")
        permission.account = data.get("account")

    permission.reader = data["reader"] or data["editor"] or data["admin"]
    permission.editor = data["editor"] or data["admin"]
    permission.admin = data["admin"]

    db.session.add(permission)
    db.session.flush()
    return permission
Example #7
0
def save(data, permission=None):
    validator = PermissionValidator()
    data = validator.deserialize(data)

    if permission is None:
        q = Permission.all()
        q = q.filter(Permission.project == data['project'])
        q = q.filter(Permission.account == data['account'])
        permission = q.first()

    if permission is None:
        permission = Permission()
        permission.project = data.get('project')
        permission.account = data.get('account')

    permission.reader = data['reader'] or data['editor'] or data['admin']
    permission.editor = data['editor'] or data['admin']
    permission.admin = data['admin']

    db.session.add(permission)
    db.session.flush()
    return permission
Example #8
0
def save(data, permission=None):
    validator = PermissionValidator()
    data = validator.deserialize(data)

    if permission is None:
        q = Permission.all()
        q = q.filter(Permission.project == data['project'])
        q = q.filter(Permission.account == data['account'])
        permission = q.first()

    if permission is None:
        permission = Permission()
        permission.project = data.get('project')
        permission.account = data.get('account')

    permission.reader = data['reader'] or data['editor'] or data['admin']
    permission.editor = data['editor'] or data['admin']
    permission.admin = data['admin']

    db.session.add(permission)
    db.session.flush()
    return permission
Example #9
0
def _find_permission(project):
    q = Permission.all()
    q = q.filter_by(project=project)
    q = q.filter_by(account=request.account)
    return q