示例#1
0
def create():
    item = Role()
    form = FormRole()
    form.parent_id.choices = [(role.id, role.name) for role in Role.all()]
    headline = localize("administration", "roles.create_headline")
    message = localize("administration", "roles.create_success")
    return create_form(item, form, headline, message, "/roles")
示例#2
0
def lookup(route, role_id):
    '''
    Tries to look up the entry in the Rules table whose route matches route.
    If no rule is found a ValueError is raised. Otherwise the function finds
    the rule that applies to the given role most directly and returns it.
    If there is a rule for the given role that is returned.
    If not the function tries to find a rule for the parent, grandparent, ...
    If there is not found a matching still the function returns None.
    '''
    Log.debug(__name__, route)
    items = Rule.all()
    # Try to match the route directly. This will collect the correct results for
    # all actions that are explicitly defined (f.i. /mailbox/[^/]+/reply) and for
    # the create, delete, update and find actions of an object folder.
    rules = [item for item in items if \
             re.match(re.sub("/$", "/?", item.route) + "$", route)]
    # If there was no rule found assume this is an object view action.
    # Try to remove the object identifier (f.i. /mailbox/mail123 becomes
    # /mailbox/) and to match again.
    if not rules:
        route = re.sub("(?<=.)/[^/]+$", "/", route)
        rules = [item for item in items if re.match(item.route + "$", route)]
    # If there still was no matching rule found raise a ValueError.
    if not rules: raise ValueError()
    role = Role.get(role_id)
    while (role):
        for item in rules:
            if Role.get(item.role_id) == role: return item
        role = Role.get(role.parent_id)
    return None
示例#3
0
def update(identifier):
    item = Role.get(int(identifier))
    if not item: return mismatch()
    form = FormRole(obj=item)
    form.parent_id.choices = [(role.id, role.name) for role in Role.all()]
    headline = localize("administration", "roles.update_headline")
    message = localize("administration", "roles.update_success")
    return update_form(item, form, headline, message, "/roles")
示例#4
0
 def installUsers():
     if User.get(1): return
     Log.debug(Installer.__name__, "Installing users...")
     items = [
         #    role          email                   name
         #    password      key
         User(Role.get(2), None, "Gast", None, ""),
         User(Role.get(5), "*****@*****.**", "Administrator", "pwd", ""),
         User(Role.get(3), "*****@*****.**", "Benutzer", "pwd", ""),
         User(Role.get(3), "*****@*****.**", "Test Benutzer", "pwd", ""),
     ]
     for item in items:
         item.create()
示例#5
0
def delete(identifier):
    item = Role.get(int(identifier))
    if not item: return mismatch()
    headline = localize("administration", "roles.delete_headline")
    text = localize("administration", "roles.delete_description") % (item.name)
    message = localize("administration", "roles.delete_success")
    return delete_form(item, headline, text, message, "/roles")
示例#6
0
def register_unlock(key):
    user = User.unique(User.generated == key)
    if not user: flash(localize("administration", "client.no_account"))
    user.generated = ""
    user.role = Role.get(3)
    user.update()
    g.session.user_id = user.id
    g.session.update()
    flash(localize("administration", "client.unlock_success") % (user.name))
    return redirect("/")
示例#7
0
 def confirm():
     if User.find(User.email == form.email.data):
         flash(localize("administration", "client.email_taken"))
         return redirect(request.path)
     if User.find(User.name == form.name.data):
         flash(localize("administration", "client.name_taken"))
         return redirect(request.path)
     key = randomkey(24, form.name.data)
     # TODO: Encrypt here.
     password = form.password.data
     user = User(Role.get(4), form.email.data, form.name.data, password,
                 key)
     user.create()
     # TODO: Write beautiful mail.
     link = "http://localhost:5000/register/" + key
     mailservice.send([form.email.data], "TITLE", link)
     flash(localize("administration", "client.register_success"))
     return redirect("/")
示例#8
0
 def installRoles():
     if Role.get(1): return
     Log.debug(Installer.__name__, "Installing roles...")
     items = [
         #    parent name
         #    description
         Role(None, "Root", "Applies to everyone."),
         Role(1, "Guest", "Applies to clients who aren't logged in."),
         Role(1, "User", "Applies to all logged in users."),
         Role(
             3, "Locked",
             "Applies to clients who haven't activated their account yet."),
         Role(3, "Administrator", "Has the most extensive permissions."),
     ]
     for item in items:
         item.create()
示例#9
0
def entries():
    items = Role.all()
    actions = menubar("role", g.role.id)
    for item in items:
        item.actions = contextmenu("role", g.role.id)
    return render("core/role_list.html", items=items, actions=actions)