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))
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)
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
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
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
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
def _find_permission(project): q = Permission.all() q = q.filter_by(project=project) q = q.filter_by(account=request.account) return q