From 8558280d3afb744b4940573d32ba4a3f0b893e09 Mon Sep 17 00:00:00 2001 From: Romain Beuque Date: Fri, 21 Feb 2014 22:16:28 +0100 Subject: [PATCH] =?UTF-8?q?suppression=20d'une=20cotisation=20si=20non=20e?= =?UTF-8?q?ncaiss=C3=A9e=20+=20ajout=20de=20la=20d=C3=A9connexion=20d'une?= =?UTF-8?q?=20seule=20machine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Brie/brie/controllers/edit.py | 117 ++++++++++++++++++ Brie/brie/model/ldap.py | 5 + Brie/brie/public/css/common.css | 5 +- Brie/brie/templates/common-css-header.html | 1 + Brie/brie/templates/edit/member.html | 22 ++++ .../member_room_interface_edit_views.html | 25 +++- 6 files changed, 172 insertions(+), 3 deletions(-) diff --git a/Brie/brie/controllers/edit.py b/Brie/brie/controllers/edit.py index 2578f12..18d6c48 100644 --- a/Brie/brie/controllers/edit.py +++ b/Brie/brie/controllers/edit.py @@ -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 diff --git a/Brie/brie/model/ldap.py b/Brie/brie/model/ldap.py index e039947..16d7fc9 100644 --- a/Brie/brie/model/ldap.py +++ b/Brie/brie/model/ldap.py @@ -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 diff --git a/Brie/brie/public/css/common.css b/Brie/brie/public/css/common.css index 0046e7a..c2d6df2 100644 --- a/Brie/brie/public/css/common.css +++ b/Brie/brie/public/css/common.css @@ -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; } diff --git a/Brie/brie/templates/common-css-header.html b/Brie/brie/templates/common-css-header.html index bc619d0..ae928b8 100644 --- a/Brie/brie/templates/common-css-header.html +++ b/Brie/brie/templates/common-css-header.html @@ -6,6 +6,7 @@ +