def groupremove(id, group): if ("admin" not in current_user.get_authgroups()) and ("admin-%s" % group not in current_user.get_authgroups()): flash("You do not have the right to do that.", "danger") return redirect("/groups/admin") id = str(id) group = str(group) ldaptools.modgroup(id, MOD_DELETE, group) flash("Membership of %s removed for %s" % (group, id), "success") return redirect("/groups/list/"+group)
def groupmkadmin(id, group): if ("admin" not in current_user.get_authgroups()) and ("admin-%s" % group not in current_user.get_authgroups()): flash("You do not have the right to do that.", "danger") return redirect("/groups/admin") id = str(id) group = str(group) try: ldaptools.modgroup(id, MOD_ADD, "admin-%s" % group) flash("Membership of admin-%s added for %s" % (group, id), "success") except: flash("That user is already in that group.", "danger") return redirect("/groups/list/"+group)
def groupdeny(id, group): if ("admin" not in current_user.get_authgroups()) and ("admin-%s" % group not in current_user.get_authgroups()): flash("You do not have the right to do that.", "danger") return redirect("/groups/admin") try: id = str(id) group = str(group) ldaptools.modgroup(id, MOD_DELETE, group+"-pending") flash("Membership of %s denied for %s" % (group, id), "success") return redirect("/groups/admin") except: flash("Membership application not found", "danger") return redirect("/groups/admin")
def group_apply(group): originalgroup = group group = str(group) assert(group in app.config["groups"]["closedgroups"]+app.config["groups"]["opengroups"]) join = True if group in app.config["groups"]["closedgroups"]: group = group+"-pending" join = False if current_user.accountStatus[0]=="Ineligible": if group not in app.config["groups"]["publicgroups"]: flash("You cannot join that group.", "danger") return redirect("/groups") ldaptools.modgroup(current_user.get_id() , MOD_ADD, group) if join: flash("Joined %s group" % group, "success") else: flash("Applied for %s group" % originalgroup, "success") return redirect("/groups")
def admin_user(uid, action, value=None): user = ldaptools.getuser(uid) validActions = ['activate', 'disable', 'delete', 'addgroup', 'delgroup'] if not user: flash("'%s' is not a valid username" % uid, "danger") return redirect("/admin") if action not in validActions: flash("'%s' is not a valid action to perform to %s" % (action, uid), "danger") return redirect("/admin/user/%s" % uid) currentStatus = user.accountStatus[0] if action == "activate" and currentStatus == "inactive": result = ldaptools.modattr(uid, MOD_REPLACE, "accountStatus", "romeo") assert(result) flash("Successfully re-activated %s" % uid, "success") return redirect("/admin/user/%s" % uid) elif action == "disable" and currentStatus == "romeo": result = ldaptools.modattr(uid, MOD_REPLACE, "accountStatus", "inactive") assert(result) flash("Successfully disabled %s" % uid, "success") return redirect("/admin/user/%s" % uid) elif action == "delete": if ldaptools.deleteuser(uid): flash("Deleted %s" % uid, "success") return redirect("/admin") else: flash("SOMETHING BAD HAPPENED OH GOD PANIC", "danger") return redirect("/admin") elif action == "addgroup" and value and value not in user.get_authgroups(): ldaptools.modgroup(uid, MOD_ADD, str(value)) flash("%s added to %s" % (uid, value), "success") return redirect("/admin/user/%s" % uid) elif action == "delgroup" and value and value in user.get_authgroups(): ldaptools.modgroup(uid, MOD_DELETE, str(value)) flash("%s removed from %s" % (uid, value), "success") return redirect("/admin/user/%s" % uid) flash("Unable to perform that action, maybe it's an invalid action due to the user's current state", "danger") return redirect("/admin/user/%s" % uid)
def group_remove(group): group = str(group) ldaptools.modgroup(current_user.get_id() , MOD_DELETE, group) flash("Removed %s group" % group, "success") return redirect("/groups")