suppression bug ajout membre, gestion ajout membre, correction bug ajout machine
This commit is contained in:
parent
e668914725
commit
b6e09c13a9
@ -36,16 +36,31 @@ class EditController(AuthenticatedBaseController):
|
|||||||
|
|
||||||
""" Controller fils de gestion des machines """
|
""" Controller fils de gestion des machines """
|
||||||
machine = None
|
machine = None
|
||||||
|
|
||||||
|
member = None
|
||||||
|
|
||||||
def __init__(self, new_show):
|
def __init__(self, new_show):
|
||||||
self.show = new_show
|
self.show = new_show
|
||||||
self.wifi = WifiRestController(new_show)
|
self.wifi = WifiRestController(new_show)
|
||||||
self.machine = MachineController()
|
self.machine = MachineController()
|
||||||
self.room = RoomController(new_show)
|
self.room = RoomController(new_show)
|
||||||
|
self.member = MemberModificationController()
|
||||||
|
|
||||||
|
|
||||||
|
""" Affiche les détails éditables de la chambre """
|
||||||
|
@expose("brie.templates.edit.room")
|
||||||
|
def room(self, residence, room_id):
|
||||||
|
return self.show.room(residence, room_id)
|
||||||
|
#end def
|
||||||
|
|
||||||
|
#end class
|
||||||
|
|
||||||
|
class MemberModificationController(AuthenticatedRestController):
|
||||||
|
require_group = groups_enum.admin
|
||||||
|
|
||||||
""" Affiche les détails éditables du membre et de la chambre """
|
""" Affiche les détails éditables du membre et de la chambre """
|
||||||
@expose("brie.templates.edit.member")
|
@expose("brie.templates.edit.member")
|
||||||
def member(self, residence, uid):
|
def get(self, residence, uid):
|
||||||
|
|
||||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||||
if residence_dn is None:
|
if residence_dn is None:
|
||||||
@ -79,13 +94,19 @@ class EditController(AuthenticatedBaseController):
|
|||||||
}
|
}
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
""" Affiche les détails éditables de la chambre """
|
@expose()
|
||||||
@expose("brie.templates.edit.room")
|
def post(self, residence, member_uid, sn, givenName, mail, comment):
|
||||||
def room(self, residence, room_id):
|
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||||
return self.show.room(residence, room_id)
|
member = Member.get_by_uid(self.user, residence_dn, member_uid)
|
||||||
#end def
|
|
||||||
|
|
||||||
#end class
|
member.sn.replace(member.sn.first(), sn)
|
||||||
|
|
||||||
|
member.givenName.replace(member.givenName.first(), givenName)
|
||||||
|
member.mail.replace(member.mail.first(), mail)
|
||||||
|
member.get("x-comment").replace(member.get("x-comment").first(), comment)
|
||||||
|
|
||||||
|
self.user.ldap_bind.save(member)
|
||||||
|
#end def
|
||||||
|
|
||||||
""" Controller de gestion des machines """
|
""" Controller de gestion des machines """
|
||||||
class MachineController(AuthenticatedBaseController):
|
class MachineController(AuthenticatedBaseController):
|
||||||
@ -167,6 +188,14 @@ class MachineAddController(AuthenticatedRestController):
|
|||||||
taken_attribute = IpReservation.taken_attr(str(datetime.today()))
|
taken_attribute = IpReservation.taken_attr(str(datetime.today()))
|
||||||
self.user.ldap_bind.add_attr(ip.dn, taken_attribute)
|
self.user.ldap_bind.add_attr(ip.dn, taken_attribute)
|
||||||
|
|
||||||
|
machine_folder = Machine.folder_attr()
|
||||||
|
machine_folder_dn = ldap_config.machine_base_dn + member.dn
|
||||||
|
try:
|
||||||
|
self.user.ldap_bind.add_entry(machine_folder_dn, machine_folder)
|
||||||
|
except ldap.ALREADY_EXISTS:
|
||||||
|
pass # OKAY
|
||||||
|
#end try
|
||||||
|
|
||||||
# Attributs ldap de l'objet machine (regroupant dns et dhcp)
|
# Attributs ldap de l'objet machine (regroupant dns et dhcp)
|
||||||
machine_top = Machine.entry_attr(name)
|
machine_top = Machine.entry_attr(name)
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class MembersAddController(AuthenticatedRestController):
|
|||||||
def post(self, residence, prenom, nom, mail):
|
def post(self, residence, prenom, nom, mail):
|
||||||
|
|
||||||
member_uid = Translations.to_uid(prenom, nom)
|
member_uid = Translations.to_uid(prenom, nom)
|
||||||
member = Member.entry_attr(member_uid, prenom, nom, mail, 1)
|
member = Member.entry_attr(member_uid, prenom, nom, mail, -1)
|
||||||
|
|
||||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||||
|
|
||||||
|
@ -86,11 +86,32 @@ class Ldap(object):
|
|||||||
def search_dn(self, dn):
|
def search_dn(self, dn):
|
||||||
return self.search_first(dn, "(objectClass=*)", ldap.SCOPE_BASE)
|
return self.search_first(dn, "(objectClass=*)", ldap.SCOPE_BASE)
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def str_attributes(attributes):
|
||||||
|
def str_value(value):
|
||||||
|
if isinstance(value, str):
|
||||||
|
return value
|
||||||
|
elif isinstance(value, list):
|
||||||
|
return [str(subval) for subval in value]
|
||||||
|
#end if
|
||||||
|
|
||||||
|
return str(value)
|
||||||
|
#end def
|
||||||
|
|
||||||
|
return dict([
|
||||||
|
(keyval[0], str_value(keyval[1]))
|
||||||
|
for keyval in attributes.iteritems()
|
||||||
|
])
|
||||||
|
#end def
|
||||||
|
|
||||||
""" Remplace les attributs d'un dn donné
|
""" Remplace les attributs d'un dn donné
|
||||||
dn : adresse de l'élément
|
dn : adresse de l'élément
|
||||||
attributes : dictionnaire d'attributs
|
attributes : dictionnaire d'attributs
|
||||||
"""
|
"""
|
||||||
def replace_attr(self, dn, attributes):
|
def replace_attr(self, dn, attributes):
|
||||||
|
attributes = Ldap.str_attributes(attributes)
|
||||||
|
|
||||||
modlist = []
|
modlist = []
|
||||||
for attribute in attributes.iteritems():
|
for attribute in attributes.iteritems():
|
||||||
modlist.append((ldap.MOD_REPLACE, attribute[0], attribute[1]))
|
modlist.append((ldap.MOD_REPLACE, attribute[0], attribute[1]))
|
||||||
@ -103,6 +124,8 @@ class Ldap(object):
|
|||||||
attributes : dictionnaire des nouveaux attributs
|
attributes : dictionnaire des nouveaux attributs
|
||||||
"""
|
"""
|
||||||
def add_attr(self, dn, attributes):
|
def add_attr(self, dn, attributes):
|
||||||
|
attributes = Ldap.str_attributes(attributes)
|
||||||
|
|
||||||
modlist = []
|
modlist = []
|
||||||
for attribute in attributes.iteritems():
|
for attribute in attributes.iteritems():
|
||||||
modlist.append((ldap.MOD_ADD, attribute[0], attribute[1]))
|
modlist.append((ldap.MOD_ADD, attribute[0], attribute[1]))
|
||||||
@ -118,6 +141,8 @@ class Ldap(object):
|
|||||||
attributes : dictionnaire des attributs à supprimer
|
attributes : dictionnaire des attributs à supprimer
|
||||||
"""
|
"""
|
||||||
def delete_attr(self, dn, attributes):
|
def delete_attr(self, dn, attributes):
|
||||||
|
attributes = Ldap.str_attributes(attributes)
|
||||||
|
|
||||||
modlist = []
|
modlist = []
|
||||||
for attribute in attributes.iteritems():
|
for attribute in attributes.iteritems():
|
||||||
modlist.append((ldap.MOD_DELETE, attribute[0], attribute[1]))
|
modlist.append((ldap.MOD_DELETE, attribute[0], attribute[1]))
|
||||||
@ -133,6 +158,8 @@ class Ldap(object):
|
|||||||
attributes : dictionnaire des attributes de l'élément
|
attributes : dictionnaire des attributes de l'élément
|
||||||
"""
|
"""
|
||||||
def add_entry(self, dn, attributes):
|
def add_entry(self, dn, attributes):
|
||||||
|
attributes = Ldap.str_attributes(attributes)
|
||||||
|
|
||||||
modlist = []
|
modlist = []
|
||||||
for attribute in attributes.iteritems():
|
for attribute in attributes.iteritems():
|
||||||
modlist.append((attribute[0], attribute[1]))
|
modlist.append((attribute[0], attribute[1]))
|
||||||
@ -169,7 +196,7 @@ class Ldap(object):
|
|||||||
modlist = []
|
modlist = []
|
||||||
|
|
||||||
for global_deletion in ldap_entry._deletions:
|
for global_deletion in ldap_entry._deletions:
|
||||||
modlist.append((ldap.MOD_DELETE, global_deletion, NONE))
|
modlist.append((ldap.MOD_DELETE, global_deletion, None))
|
||||||
#end for
|
#end for
|
||||||
ldap_entry._deletions = []
|
ldap_entry._deletions = []
|
||||||
|
|
||||||
@ -187,12 +214,14 @@ class Ldap(object):
|
|||||||
print "modified : " + str(ldap_attribute._modified)
|
print "modified : " + str(ldap_attribute._modified)
|
||||||
|
|
||||||
if ldap_attribute._deletions != []:
|
if ldap_attribute._deletions != []:
|
||||||
modlist.append((ldap.MOD_DELETE, ldap_attribute.name, ldap_attribute._deletions))
|
str_values = [str(value) for value in ldap_attribute._deletions]
|
||||||
|
modlist.append((ldap.MOD_DELETE, ldap_attribute.name, str_values))
|
||||||
ldap_attribute._deletions = []
|
ldap_attribute._deletions = []
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
if ldap_attribute._additions != []:
|
if ldap_attribute._additions != []:
|
||||||
modlist.append((ldap.MOD_ADD, ldap_attribute.name, ldap_attribute._additions))
|
str_values = [str(value) for value in ldap_attribute._additions]
|
||||||
|
modlist.append((ldap.MOD_ADD, ldap_attribute.name, str_values))
|
||||||
ldap_attribute._additions = []
|
ldap_attribute._additions = []
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
@ -247,7 +276,10 @@ class LdapEntry(object):
|
|||||||
#end def
|
#end def
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return None
|
attr = LdapAttribute(name, [])
|
||||||
|
self.__dict__[name] = attr
|
||||||
|
|
||||||
|
return attr
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
""" Ajoute un attribut """
|
""" Ajoute un attribut """
|
||||||
@ -346,6 +378,8 @@ class LdapAttribute(object):
|
|||||||
si la valeur est nulle, modifie la première valeur
|
si la valeur est nulle, modifie la première valeur
|
||||||
"""
|
"""
|
||||||
def replace(self, old, new):
|
def replace(self, old, new):
|
||||||
|
if old == new:
|
||||||
|
return
|
||||||
|
|
||||||
# Fonction usuelle de remplacement
|
# Fonction usuelle de remplacement
|
||||||
def replace(current):
|
def replace(current):
|
||||||
@ -360,6 +394,8 @@ class LdapAttribute(object):
|
|||||||
# l'ancienne valeur n'est que supprimée
|
# l'ancienne valeur n'est que supprimée
|
||||||
if new in self.values:
|
if new in self.values:
|
||||||
self.delete(old)
|
self.delete(old)
|
||||||
|
elif self.values == []:
|
||||||
|
self.add(new)
|
||||||
else:
|
else:
|
||||||
self.values = [replace(value) for value in self.values]
|
self.values = [replace(value) for value in self.values]
|
||||||
|
|
||||||
@ -370,7 +406,7 @@ class LdapAttribute(object):
|
|||||||
self._modified = True
|
self._modified = True
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
|
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
#end class
|
#end class
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class Member(object):
|
|||||||
"cn" : (prenom + " " + nom.upper()).encode("utf-8"),
|
"cn" : (prenom + " " + nom.upper()).encode("utf-8"),
|
||||||
"sn" : (nom.upper()).encode("utf-8"),
|
"sn" : (nom.upper()).encode("utf-8"),
|
||||||
"givenName" : (prenom).encode("utf-8"),
|
"givenName" : (prenom).encode("utf-8"),
|
||||||
"uidNumber" : uid_number,
|
"uidNumber" : str(uid_number),
|
||||||
"gidNumber" : "10000",
|
"gidNumber" : "10000",
|
||||||
"homeDirectory" : ("/net/home/" + uid).encode("utf-8"),
|
"homeDirectory" : ("/net/home/" + uid).encode("utf-8"),
|
||||||
"mail" : mail.encode("utf-8"),
|
"mail" : mail.encode("utf-8"),
|
||||||
@ -120,6 +120,14 @@ class Wifi(object):
|
|||||||
|
|
||||||
class Machine(object):
|
class Machine(object):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def folder_attr():
|
||||||
|
return {
|
||||||
|
"objectClass" : ["organizationalRole", "top"],
|
||||||
|
"cn" : "machines"
|
||||||
|
}
|
||||||
|
#end def
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def entry_attr(machine_id):
|
def entry_attr(machine_id):
|
||||||
return {
|
return {
|
||||||
|
@ -11,55 +11,35 @@
|
|||||||
<a href="/show/${page}/${residence}/${id}" class="button">RETOUR</a>
|
<a href="/show/${page}/${residence}/${id}" class="button">RETOUR</a>
|
||||||
</py:def>
|
</py:def>
|
||||||
<py:def function="member_view(member_ldap)">
|
<py:def function="member_view(member_ldap)">
|
||||||
|
<form action="/edit/member/" method="POST">
|
||||||
|
<input type="hidden" name="residence" value="${residence}" />
|
||||||
|
<input type="hidden" name="member_uid" value="${member_ldap.uid.first()}" />
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<span class="section_name show_section_name">${member_ldap.cn.first()}</span>
|
<span class="section_name show_section_name">${member_ldap.cn.first()}</span>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<span class="item_name">Prénom</span>
|
<span class="item_name">Prénom</span>
|
||||||
<input type="text" value="${member_ldap.givenName.first('')}" />
|
<input type="text" name="givenName" value="${member_ldap.givenName.first('')}" />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="item_name">Nom</span>
|
<span class="item_name">Nom</span>
|
||||||
<input type="text" value="${member_ldap.sn.first()}" />
|
<input type="text" name="sn" value="${member_ldap.sn.first()}" />
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<span class="item_name">Fin de connexion</span>
|
|
||||||
<span py:choose="member_ldap.get('x-connectionEnd')">
|
|
||||||
<span py:when="None">Pas de fin de connexion</span>
|
|
||||||
<span py:otherwise="">${member_ldap.get("x-connectionEnd").first()}</span>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="item_name">E-mail</span>
|
<span class="item_name">E-mail</span>
|
||||||
<input type="text" value="${member_ldap.mail.first('')}" />
|
<input type="text" name="mail" value="${member_ldap.mail.first('')}" />
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<span class="item_name">Certificat</span>
|
|
||||||
<py:with vars="certif = member_ldap.get('x-certificatGiven')">
|
|
||||||
<span py:choose="">
|
|
||||||
<span py:when="certif is not None and certif.first() == 'TRUE'">oui</span>
|
|
||||||
<span py:otherwise="">non</span>
|
|
||||||
</span>
|
|
||||||
</py:with>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="item_name">Commentaire</span>
|
<span class="item_name">Commentaire</span>
|
||||||
<span py:choose="member_ldap.get('x-comment')">
|
<input type="text" name="comment" value="${member_ldap.get('x-comment').first('')}" />
|
||||||
<span py:when="None"></span>
|
|
||||||
<span py:otherwise="">${member_ldap.get("x-comment").first()}</span>
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="item_name">Cas spécial</span>
|
<span class="item_name"></span>
|
||||||
<py:with vars="cas_spec = member_ldap.get('x-specialCase')">
|
<input type="submit" value="Soumettre" />
|
||||||
<span py:choose="">
|
|
||||||
<span py:when="cas_spec is not None and cas_spec.first() == 'TRUE'">oui</span>
|
|
||||||
<span py:otherwise="">non</span>
|
|
||||||
</span>
|
|
||||||
</py:with>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<span class="section_name show_section_name">MACHINES</span>
|
<span class="section_name show_section_name">MACHINES</span>
|
||||||
<div py:for="name, mac, ip in machines">
|
<div py:for="name, mac, ip in machines">
|
||||||
|
@ -52,10 +52,6 @@
|
|||||||
<tr py:for="member in sort_name(members)">
|
<tr py:for="member in sort_name(members)">
|
||||||
<td><a href="/show/member/${residence}/${member.uid.first()}">${member.givenName.first()}</a></td>
|
<td><a href="/show/member/${residence}/${member.uid.first()}">${member.givenName.first()}</a></td>
|
||||||
<td><a href="/show/member/${residence}/${member.uid.first()}">${member.sn.first()}</a></td>
|
<td><a href="/show/member/${residence}/${member.uid.first()}">${member.sn.first()}</a></td>
|
||||||
<py:choose test="member.room">
|
|
||||||
<td py:when="None"></td>
|
|
||||||
<td py:otherwise=""><a href="/show/room/${residence}/${member.room.cn.first()}">${member.room.cn.first()}</a></td>
|
|
||||||
</py:choose>
|
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user