Ejemplo n.º 1
0
def get_role(req, id):
    ctx = Context()
    
    role = ctx.get_role(id)
    
    if role is None:
        raise Http404
    
    data = []
    data.append("'id': '%s'" % role.id)
    data.append("'description': '%s'" % role.description)
    data.append("'permissions': ['%s']" % "','".join([p.id.replace("'", "\\'")
                                                    for p in role.permissions]))
    
    return HttpResponse("{%s}" % ",".join(data), "text/plain")
Ejemplo n.º 2
0
def get_role(req, id):
    ctx = Context()

    role = ctx.get_role(id)

    if role is None:
        raise Http404

    data = []
    data.append("'id': '%s'" % role.id)
    data.append("'description': '%s'" % role.description)
    data.append(
        "'permissions': ['%s']" %
        "','".join([p.id.replace("'", "\\'") for p in role.permissions]))

    return HttpResponse("{%s}" % ",".join(data), "text/plain")
Ejemplo n.º 3
0
def edit_role(req, id):
    ctx = Context()
    role = ctx.get_role(id=id)
    if not role:
        raise Http404
    
    role.description = req.POST['description']
    role.permissions = []
    for id in (req.POST['permissions'].strip() and req.POST['permissions'].split(",") or []):
        role.permissions.append(ctx.get_permission(id))
    
    for i in xrange(len(ctx.roles)):
        if ctx.roles[i].id == id:
            ctx.roles[i] = role
            break
    
    ctx.write_xml()
    return HttpResponse("{'result': 'OK'}")
Ejemplo n.º 4
0
def edit_role(req, id):
    ctx = Context()
    role = ctx.get_role(id=id)
    if not role:
        raise Http404

    role.description = req.POST['description']
    role.permissions = []
    for id in (req.POST['permissions'].strip()
               and req.POST['permissions'].split(",") or []):
        role.permissions.append(ctx.get_permission(id))

    for i in xrange(len(ctx.roles)):
        if ctx.roles[i].id == id:
            ctx.roles[i] = role
            break

    ctx.write_xml()
    return HttpResponse("{'result': 'OK'}")
Ejemplo n.º 5
0
def edit_user(req, id):
    ctx = Context()
    user = ctx.get_user(id=id)
    if not user:
        raise Http404
    
    user.name = req.POST['name']
    user.roles = []
    for id in (req.POST['roles'].strip() and req.POST['roles'].split(",") or []):
        user.roles.append(ctx.get_role(id))
    user.superuser = (req.POST['superuser'] == "yes")
    
    if req.POST['password'].strip():
        password = req.POST['password']
    
    for i in xrange(len(ctx.users)):
        if ctx.users[i].login == id:
            ctx.users[i] = user
            break
    
    ctx.write_xml()
    return HttpResponse("{'result': 'OK'}")
Ejemplo n.º 6
0
def edit_user(req, id):
    ctx = Context()
    user = ctx.get_user(id=id)
    if not user:
        raise Http404

    user.name = req.POST['name']
    user.roles = []
    for id in (req.POST['roles'].strip() and req.POST['roles'].split(",")
               or []):
        user.roles.append(ctx.get_role(id))
    user.superuser = (req.POST['superuser'] == "yes")

    if req.POST['password'].strip():
        password = req.POST['password']

    for i in xrange(len(ctx.users)):
        if ctx.users[i].login == id:
            ctx.users[i] = user
            break

    ctx.write_xml()
    return HttpResponse("{'result': 'OK'}")