Пример #1
0
def do_update_user():
    current_user = UserGroup(current_usergroup_id())
    if current_user.privilege < 1:
        return redirect("users")

    u_id = request.form.get("u_id")
    name = request.form.get("name")
    password = request.form.get("password")
    privilege = request.form.get("privilege")

    usergroup = UserGroup(u_id)

    if name != usergroup.name:
        cur = bean.get_db().cursor()
        res = cur.execute("SELECT * FROM usergroup WHERE name = ?",
                          [name]).fetchone()

        if res is not None:
            return redirect("edit_user?u_id={}".format(u_id))

        usergroup.name = name

    if len(password) > 0:
        auth.update_password(usergroup, password)

    usergroup.privilege = privilege

    return redirect("users")
Пример #2
0
def do_remove_user():
    current_user = UserGroup(current_usergroup_id())
    if current_user.privilege < 1:
        return redirect("users")

    u_id = request.form.get("u_id")
    usergroup = UserGroup(u_id)
    remove_usergroup(usergroup)

    return redirect("users")
Пример #3
0
def do_revoke_access():
    u_id = request.args.get("u_id")
    t_id = request.args.get("t_id")

    template = Template(t_id)
    current_usergroup = UserGroup(current_usergroup_id())
    if template.owner != current_usergroup.id and current_usergroup.privilege < 1:
        return redirect("template_detail?id={}".format(t_id))

    revoke_access(UserGroup(u_id), template)

    return redirect("template_detail?id={}".format(t_id))
Пример #4
0
def show_edit_user():
    usergroup = UserGroup(request.args.get("u_id"))

    current_user = UserGroup(current_usergroup_id())
    if current_user.privilege < 1:
        return redirect("users")

    return render_template("edit_user.html",
                           current_username=current_username(),
                           page="users",
                           id=usergroup.id,
                           name=usergroup.name,
                           privilege=usergroup.privilege)
Пример #5
0
def usergroups_by_template(template_id):
    cur = bean.get_db()
    result = cur.execute(
        "SELECT usergroup_id AS u_id "
        "FROM template_usergroup "
        "WHERE template_id = ?", [template_id])
    return set([UserGroup(r["u_id"]) for r in result])
Пример #6
0
def show_new_user():
    current_user = UserGroup(current_usergroup_id())
    if current_user.privilege < 1:
        return redirect("users")

    return render_template("new_user.html",
                           current_username=current_username(),
                           page="users")
Пример #7
0
def usergroup_by_auth_token(auth_token):
    cursor = get_db()

    try:
        row = cursor.execute("SELECT * FROM session WHERE auth_token = ?", [auth_token]).fetchone()

    except:
        return None

    return UserGroup(row["usergroup_id"])
Пример #8
0
def do_duplicate_template():
    t_id = request.args.get("id")
    template_to_duplicate = Template(t_id)

    current_user = UserGroup(current_usergroup_id())
    if current_user.privilege < 1 and current_user.id is not template_to_duplicate.owner:
        return redirect("templates")

    template_result = duplicate_template(template_to_duplicate)

    return redirect("template_detail?id={}".format(template_result.id))
Пример #9
0
def usergroup_by_name(name):
    cursor = get_db()

    row = cursor.execute("SELECT * FROM usergroup WHERE name = ?", [name]).fetchone()

    if row is None:
        return None

    cursor.commit()

    return UserGroup(row["id"])
Пример #10
0
def new_template(name, path, owner):
    cur = bean.get_db().cursor()
    cur.execute(
        "INSERT INTO template (name, path, date_added, date_last_used, owner) VALUES (?, ?, ?, ?, ?)",
        [name, path, util.today(), "", owner])

    template = Template(cur.lastrowid)

    owner_usergroup = UserGroup(owner)
    grant_access(owner_usergroup, template)

    return template
Пример #11
0
def do_delete_template():
    t_id = request.form.get("t_id")

    template_to_delete = Template(t_id)

    current_user = UserGroup(current_usergroup_id())
    if current_user.privilege < 1 and current_user.id is not template_to_delete.owner:
        return redirect("templates")

    delete_template(template_to_delete)

    return redirect("templates")
Пример #12
0
def do_register_user():
    username = request.form.get("username")
    password = request.form.get("password")
    privilege = request.form.get("privilege")

    current_user = UserGroup(current_usergroup_id())
    if current_user.privilege < 1:
        return redirect("users")

    new_user = auth.register_usergroup(username, password)
    new_user.privilege = privilege

    return redirect("users")
Пример #13
0
 def usergroups(self):
     #print(self.id, type(self.id))
     results = bean.get_db().execute(
         "SELECT * FROM template_usergroup WHERE template_id = (?)",
         [self.id])
     return [UserGroup(result["id"]) for result in results]
Пример #14
0
def current_username():
    return UserGroup(current_usergroup_id()).name
Пример #15
0
def do_logout():
    usergroup = UserGroup(current_usergroup_id())
    remove_session_by_usergroup(usergroup)

    return redirect("login")