Merge with Roven

This commit is contained in:
Romain Beuque 2014-02-21 22:17:58 +01:00
commit ddd76e3f76
6 changed files with 172 additions and 3 deletions

View File

@ -303,9 +303,15 @@ class MachineController(AuthenticatedBaseController):
add = None
""" Controller fils de suppression de machine """
delete = None
""" Controller fils de desactivation de machine """
disable = None
""" Controller fils d'activation de machine """
enable = None
def __init__(self):
self.add = MachineAddController()
self.delete = MachineDeleteController()
self.enable = MachineEnableController()
self.disable = MachineDisableController()
#end class
@ -443,10 +449,49 @@ class CotisationController(AuthenticatedBaseController):
require_group = groups_enum.admin
add = None
delete = None
def __init__(self):
self.add = CotisationAddController()
self.delete = CotisationDeleteController()
#end def
#end class
class CotisationDeleteController(AuthenticatedRestController):
require_group = groups_enum.admin
@expose()
def post(self, residence, member_uid, cotisation_cn):
residence_dn = Residences.get_dn_by_name(self.user, residence)
member = Member.get_by_uid(self.user, residence_dn, member_uid)
print "WTF"
if member is None:
raise Exception('membre inconnu')
#end if
current_year = CotisationComputes.current_year()
cotisation = Cotisation.get_payment_by_name(self.user, member.dn, cotisation_cn, current_year)
if cotisation.has('x-paymentCashed') and cotisation.get('x-paymentCashed').first() == 'TRUE':
raise Exception('Impossible de supprimer une cotisation encaissée')
#end if
self.user.ldap_bind.delete_entry_subtree(cotisation.dn)
redirect("/edit/member/"+residence+"/"+member_uid)
#end def
#end class
class CotisationAddController(AuthenticatedRestController):
require_group = groups_enum.admin
@ -609,6 +654,78 @@ class MachineDeleteController(AuthenticatedRestController):
#end def
""" Controller REST de gestion de la deconnexion d'une machine. """
class MachineDisableController(AuthenticatedRestController):
require_group = groups_enum.admin
""" Gestion des requêtes post sur ce controller """
@expose()
def post(self, residence, member_uid, mac):
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
machine = Machine.get_dhcp_by_mac(self.user, member.dn, mac)
if machine is None:
raise Exception('machine inconnue')
#end if
machine_membre_tag = "machine_membre" # FIXME move to config
if machine.uid.first() == machine_membre_tag:
machine.uid.replace(machine_membre_tag, machine_membre_tag + "_disabled")
self.user.ldap_bind.save(machine)
#end if
print("[LOG] disable member "+member_uid+" machine "+ machine.dhcpStatements.first().split(" ")[1] +" by "+self.user.attrs.dn)
# On redirige sur la page d'édition du membre
redirect("/edit/member/" + residence + "/" + member_uid)
#end def
""" Controller REST de gestion de la reconnexion d'une machine. """
class MachineEnableController(AuthenticatedRestController):
require_group = groups_enum.admin
""" Gestion des requêtes post sur ce controller """
@expose()
def post(self, residence, member_uid, mac):
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
machine = Machine.get_dhcp_by_mac(self.user, member.dn, mac)
if machine is None:
raise Exception('machine inconnue')
#end if
machine_membre_tag = "machine_membre" # FIXME move to config
machine_membre_disabled = machine_membre_tag + "_disabled" # FIXME move to config
if machine.uid.first() == machine_membre_disabled:
machine.uid.replace(machine_membre_disabled, machine_membre_tag)
self.user.ldap_bind.save(machine)
#end if
print("[LOG] enable member "+member_uid+" machine "+ mac +" by "+self.user.attrs.dn)
# On redirige sur la page d'édition du membre
redirect("/edit/member/" + residence + "/" + member_uid)
#end def
class WifiRestController(AuthenticatedRestController):
require_group = groups_enum.respsalleinfo

View File

@ -402,6 +402,11 @@ class Cotisation:
return user_session.ldap_bind.search("cn=" + str(year) + "," + ldap_config.cotisation_member_base_dn + member_dn, "(&(objectClass=aurorePayment)(!(objectClass=auroreCotisation)))")
#end def
@staticmethod
def get_payment_by_name(user_session, member_dn, payment_cn, year):
return user_session.ldap_bind.search_first("cn=" + str(year) + "," + ldap_config.cotisation_member_base_dn + member_dn, "(&(objectClass=aurorePayment)(cn="+payment_cn+"))")
#end def
@staticmethod
def get_all_extras(user_session, residence_dn):
dn = ldap_config.extra_base_dn + residence_dn

View File

@ -8,7 +8,7 @@ a {
text-decoration: none;
}
a:hover, input[type="button"]
a:hover, input[type="button"], button
{
color: white;
background-color: black;
@ -51,9 +51,10 @@ a:hover, input[type="button"]
width: 70%;
}
input[type="submit"]
input[type="submit"], button
{
border: none;
color:black;
padding: 5px;
}

View File

@ -6,6 +6,7 @@
<link href="/css/bootstrap.css" rel="stylesheet"/>
<link href="/css/form-signin.css" rel="stylesheet"/>
<link href="/css/bootstrap-responsive.css" rel="stylesheet" />
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet" />
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>

View File

@ -39,6 +39,28 @@
</div>
</div>
<xi:include href="../show/cotisation.html" />
<div class="section">
<div py:for="cotisation in cotisations">
<span class="item_name"></span>
${cotisation.cn.first()} - ${cotisation.get('x-action-user-info').first()}
<form method="post" action="/edit/cotisation/delete" style="display:inline;" py:if="cotisation.get('x-paymentCashed').first() != 'TRUE'">
<input type="hidden" name="residence" value="${residence}" />
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}" />
<input type="hidden" name="cotisation_cn" value="${cotisation.get('cn').first()}" />
<input type="submit" class="button" value="supprimer" />
</form>
</div>
<div py:for="cotisation in extras">
<span class="item_name"></span>
${cotisation.cn.first()} - ${cotisation.get('x-action-user-info').first()}
<form method="post" action="/edit/cotisation/delete" style="display:inline;" py:if="cotisation.get('x-paymentCashed').first() != 'TRUE'">
<input type="hidden" name="residence" value="${residence}" />
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}" />
<input type="hidden" name="cotisation_cn" value="${cotisation.get('cn').first()}" />
<input type="submit" value="supprimer" class="button" />
</form>
</div>
</div>
<div class="section">
<form method="post" action="/edit/cotisation/add">
<input type="hidden" name="residence" value="${residence}"/>

View File

@ -46,15 +46,38 @@
</form>
<div class="section">
<span class="section_name show_section_name">MACHINES</span>
<div py:for="name, mac, ip in machines">
<div py:for="name, mac, ip, disable in machines">
<span class="item_name">${name}</span>
<span>${mac} : ${ip}</span>
<form action="/edit/machine/delete/" method="post" class="inline_block">
<input type="hidden" name="residence" value="${residence}"/>
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}"/>
<input type="hidden" name="machine_id" value="${name}"/>
<input type="submit" value="X" class="button"/>
</form>
<py:choose test="">
<div py:when="disable == ''" style="display:inline;">
<form action="/edit/machine/disable/" method="post" class="inline_block">
<input type="hidden" name="residence" value="${residence}"/>
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}"/>
<input type="hidden" name="mac" value="${mac}"/>
<button class="button">
<i class="fa fa-chain-broken"></i>
</button>
</form>
</div>
<div py:otherwise="" style="display:inline; color:red;">&nbsp;&nbsp;&gt;&gt;&nbsp; Machine désactivée
<form action="/edit/machine/enable/" method="post" class="inline_block">
<input type="hidden" name="residence" value="${residence}"/>
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}"/>
<input type="hidden" name="mac" value="${mac}"/>
<button class="button">
<i class="fa fa-link"></i>
</button>
</form>
</div>
</py:choose>
</div>
<div>
<form action="/edit/machine/add/" method="post">