Exemple #1
0
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)