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 """
|
||||
machine = None
|
||||
|
||||
member = None
|
||||
|
||||
def __init__(self, new_show):
|
||||
self.show = new_show
|
||||
self.wifi = WifiRestController(new_show)
|
||||
self.machine = MachineController()
|
||||
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 """
|
||||
@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)
|
||||
if residence_dn is None:
|
||||
@ -78,14 +93,20 @@ class EditController(AuthenticatedBaseController):
|
||||
"rooms" : rooms
|
||||
}
|
||||
#end def
|
||||
|
||||
""" 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
|
||||
@expose()
|
||||
def post(self, residence, member_uid, sn, givenName, mail, comment):
|
||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||
member = Member.get_by_uid(self.user, residence_dn, member_uid)
|
||||
|
||||
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 """
|
||||
class MachineController(AuthenticatedBaseController):
|
||||
@ -167,6 +188,14 @@ class MachineAddController(AuthenticatedRestController):
|
||||
taken_attribute = IpReservation.taken_attr(str(datetime.today()))
|
||||
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)
|
||||
machine_top = Machine.entry_attr(name)
|
||||
|
||||
|
@ -74,7 +74,7 @@ class MembersAddController(AuthenticatedRestController):
|
||||
def post(self, residence, prenom, nom, mail):
|
||||
|
||||
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)
|
||||
|
||||
|
@ -86,11 +86,32 @@ class Ldap(object):
|
||||
def search_dn(self, dn):
|
||||
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é
|
||||
dn : adresse de l'élément
|
||||
attributes : dictionnaire d'attributs
|
||||
"""
|
||||
def replace_attr(self, dn, attributes):
|
||||
attributes = Ldap.str_attributes(attributes)
|
||||
|
||||
modlist = []
|
||||
for attribute in attributes.iteritems():
|
||||
modlist.append((ldap.MOD_REPLACE, attribute[0], attribute[1]))
|
||||
@ -103,6 +124,8 @@ class Ldap(object):
|
||||
attributes : dictionnaire des nouveaux attributs
|
||||
"""
|
||||
def add_attr(self, dn, attributes):
|
||||
attributes = Ldap.str_attributes(attributes)
|
||||
|
||||
modlist = []
|
||||
for attribute in attributes.iteritems():
|
||||
modlist.append((ldap.MOD_ADD, attribute[0], attribute[1]))
|
||||
@ -118,6 +141,8 @@ class Ldap(object):
|
||||
attributes : dictionnaire des attributs à supprimer
|
||||
"""
|
||||
def delete_attr(self, dn, attributes):
|
||||
attributes = Ldap.str_attributes(attributes)
|
||||
|
||||
modlist = []
|
||||
for attribute in attributes.iteritems():
|
||||
modlist.append((ldap.MOD_DELETE, attribute[0], attribute[1]))
|
||||
@ -133,6 +158,8 @@ class Ldap(object):
|
||||
attributes : dictionnaire des attributes de l'élément
|
||||
"""
|
||||
def add_entry(self, dn, attributes):
|
||||
attributes = Ldap.str_attributes(attributes)
|
||||
|
||||
modlist = []
|
||||
for attribute in attributes.iteritems():
|
||||
modlist.append((attribute[0], attribute[1]))
|
||||
@ -169,7 +196,7 @@ class Ldap(object):
|
||||
modlist = []
|
||||
|
||||
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
|
||||
ldap_entry._deletions = []
|
||||
|
||||
@ -187,12 +214,14 @@ class Ldap(object):
|
||||
print "modified : " + str(ldap_attribute._modified)
|
||||
|
||||
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 = []
|
||||
#end if
|
||||
|
||||
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 = []
|
||||
#end if
|
||||
|
||||
@ -247,7 +276,10 @@ class LdapEntry(object):
|
||||
#end def
|
||||
|
||||
def __getattr__(self, name):
|
||||
return None
|
||||
attr = LdapAttribute(name, [])
|
||||
self.__dict__[name] = attr
|
||||
|
||||
return attr
|
||||
#end def
|
||||
|
||||
""" Ajoute un attribut """
|
||||
@ -346,7 +378,9 @@ class LdapAttribute(object):
|
||||
si la valeur est nulle, modifie la première valeur
|
||||
"""
|
||||
def replace(self, old, new):
|
||||
|
||||
if old == new:
|
||||
return
|
||||
|
||||
# Fonction usuelle de remplacement
|
||||
def replace(current):
|
||||
if current == old:
|
||||
@ -360,6 +394,8 @@ class LdapAttribute(object):
|
||||
# l'ancienne valeur n'est que supprimée
|
||||
if new in self.values:
|
||||
self.delete(old)
|
||||
elif self.values == []:
|
||||
self.add(new)
|
||||
else:
|
||||
self.values = [replace(value) for value in self.values]
|
||||
|
||||
@ -370,7 +406,7 @@ class LdapAttribute(object):
|
||||
self._modified = True
|
||||
#end if
|
||||
|
||||
|
||||
#end def
|
||||
|
||||
#end class
|
||||
|
||||
|
@ -14,7 +14,7 @@ class Member(object):
|
||||
"cn" : (prenom + " " + nom.upper()).encode("utf-8"),
|
||||
"sn" : (nom.upper()).encode("utf-8"),
|
||||
"givenName" : (prenom).encode("utf-8"),
|
||||
"uidNumber" : uid_number,
|
||||
"uidNumber" : str(uid_number),
|
||||
"gidNumber" : "10000",
|
||||
"homeDirectory" : ("/net/home/" + uid).encode("utf-8"),
|
||||
"mail" : mail.encode("utf-8"),
|
||||
@ -120,6 +120,14 @@ class Wifi(object):
|
||||
|
||||
class Machine(object):
|
||||
|
||||
@staticmethod
|
||||
def folder_attr():
|
||||
return {
|
||||
"objectClass" : ["organizationalRole", "top"],
|
||||
"cn" : "machines"
|
||||
}
|
||||
#end def
|
||||
|
||||
@staticmethod
|
||||
def entry_attr(machine_id):
|
||||
return {
|
||||
|
@ -11,55 +11,35 @@
|
||||
<a href="/show/${page}/${residence}/${id}" class="button">RETOUR</a>
|
||||
</py:def>
|
||||
<py:def function="member_view(member_ldap)">
|
||||
<div class="section">
|
||||
<span class="section_name show_section_name">${member_ldap.cn.first()}</span>
|
||||
<div>
|
||||
<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">
|
||||
<span class="section_name show_section_name">${member_ldap.cn.first()}</span>
|
||||
<div>
|
||||
<span class="item_name">Prénom</span>
|
||||
<input type="text" value="${member_ldap.givenName.first('')}" />
|
||||
</div>
|
||||
<div>
|
||||
<span class="item_name">Nom</span>
|
||||
<input type="text" 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>
|
||||
<span class="item_name">E-mail</span>
|
||||
<input type="text" 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>
|
||||
<span class="item_name">Commentaire</span>
|
||||
<span py:choose="member_ldap.get('x-comment')">
|
||||
<span py:when="None"></span>
|
||||
<span py:otherwise="">${member_ldap.get("x-comment").first()}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="item_name">Cas spécial</span>
|
||||
<py:with vars="cas_spec = member_ldap.get('x-specialCase')">
|
||||
<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>
|
||||
<span class="item_name">Prénom</span>
|
||||
<input type="text" name="givenName" value="${member_ldap.givenName.first('')}" />
|
||||
</div>
|
||||
<div>
|
||||
<span class="item_name">Nom</span>
|
||||
<input type="text" name="sn" value="${member_ldap.sn.first()}" />
|
||||
</div>
|
||||
<div>
|
||||
<span class="item_name">E-mail</span>
|
||||
<input type="text" name="mail" value="${member_ldap.mail.first('')}" />
|
||||
</div>
|
||||
<div>
|
||||
<span class="item_name">Commentaire</span>
|
||||
<input type="text" name="comment" value="${member_ldap.get('x-comment').first('')}" />
|
||||
</div>
|
||||
<div>
|
||||
<span class="item_name"></span>
|
||||
<input type="submit" value="Soumettre" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="section">
|
||||
<span class="section_name show_section_name">MACHINES</span>
|
||||
<div py:for="name, mac, ip in machines">
|
||||
|
@ -52,10 +52,6 @@
|
||||
<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.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>
|
||||
</table>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user