ajout des features connexion/deconnexions manuelles

This commit is contained in:
Romain Beuque 2013-10-06 23:51:45 +02:00
parent 855a97b733
commit 809384a70b
2 changed files with 87 additions and 0 deletions

View File

@ -107,6 +107,8 @@ class MemberModificationController(AuthenticatedRestController):
def __init__(self, new_show):
self.show = new_show
self.disable = MemberDisableController()
self.enable = MemberEnableController()
#end def
""" Affiche les détails éditables du membre et de la chambre """
@ -209,6 +211,71 @@ class MemberModificationController(AuthenticatedRestController):
redirect("/edit/member/" + residence + "/" + member_uid)
#end def
""" Controller REST de gestion de la deconnexion. """
class MemberDisableController(AuthenticatedRestController):
require_group = groups_enum.admin
""" Gestion des requêtes post sur ce controller """
@expose()
def post(self, residence, member_uid):
residence_dn = Residences.get_dn_by_name(self.user, residence)
# Récupération du membre et de la machine
# Note : on cherche la machine seulement sur le membre (member.dn)
member = Member.get_by_uid(self.user, residence_dn, member_uid)
if member is None:
raise Exception('membre inconnu')
#end if
dhcps = Machine.get_dhcps(self.user, member.dn)
machine_membre_tag = "machine_membre" # FIXME move to config
for dhcp_item in dhcps:
if dhcp_item.uid.first() == machine_membre_tag:
dhcp_item.uid.replace(machine_membre_tag, machine_membre_tag + "_disabled")
self.user.ldap_bind.save(dhcp_item)
#end if
#end for
# On redirige sur la page d'édition du membre
redirect("/edit/member/" + residence + "/" + member_uid)
#end def
""" Controller REST de gestion de la reconnexion. """
class MemberEnableController(AuthenticatedRestController):
require_group = groups_enum.admin
""" Gestion des requêtes post sur ce controller """
@expose()
def post(self, residence, member_uid):
residence_dn = Residences.get_dn_by_name(self.user, residence)
# Récupération du membre et de la machine
# Note : on cherche la machine seulement sur le membre (member.dn)
member = Member.get_by_uid(self.user, residence_dn, member_uid)
if member is None:
raise Exception('membre inconnu')
#end if
dhcps = Machine.get_dhcps(self.user, member.dn)
machine_membre_tag = "machine_membre" # FIXME move to config
machine_membre_disabled = machine_membre_tag + "_disabled" # FIXME move to config
for dhcp_item in dhcps:
if dhcp_item.uid.first() == machine_membre_disabled:
dhcp_item.uid.replace(machine_membre_disabled, machine_membre_tag)
self.user.ldap_bind.save(dhcp_item)
#end if
#end for
# On redirige sur la page d'édition du membre
redirect("/edit/member/" + residence + "/" + member_uid)
#end def
""" Controller de gestion des machines """
class MachineController(AuthenticatedBaseController):
require_group = groups_enum.admin

View File

@ -51,5 +51,25 @@
</div>
</form>
</div>
<div class="section">
<form method="post" action="/edit/member/disable">
<input type="hidden" name="residence" value="${residence}"/>
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}"/>
<div>
<span class="item_name">déconnexion</span>
<input type="submit" class="button" value="desactiver" />
</div>
</form>
</div>
<div class="section">
<form method="post" action="/edit/member/enable">
<input type="hidden" name="residence" value="${residence}"/>
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}"/>
<div>
<span class="item_name">reconnexion</span>
<input type="submit" class="button" value="reactiver" />
</div>
</form>
</div>
</body>
</html>