On permet d'effectuer les modifications par batch + add attributs.py
This commit is contained in:
parent
f1d8f5bd67
commit
22a8e3be78
2 changed files with 348 additions and 148 deletions
311
attributs.py
Normal file
311
attributs.py
Normal file
|
@ -0,0 +1,311 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# ATTRIBUTS.PY-- Description des attributs ldap
|
||||
#
|
||||
# Copyright (C) 2010 Cr@ns <roots@crans.org>
|
||||
# Author: Antoine Durand-Gasselin <adg@crans.org>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# * Neither the name of the Cr@ns nor the names of its contributors may
|
||||
# be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT
|
||||
# HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
def validate_name(value, more_chars=""):
|
||||
return re.match("[A-Za-z][-' A-Za-z%s]*" % more_chars,
|
||||
normalize('NFKD', decode(a)).encode('ASCII', 'ignore'))
|
||||
|
||||
def validate_mac(value):
|
||||
return True
|
||||
|
||||
class Attr:
|
||||
legend = "Human-readable description of attribute"
|
||||
def validate(self, values, uldif):
|
||||
"validates"
|
||||
self._check_cardinality(values)
|
||||
self._check_type(values)
|
||||
self._check_uniqueness(values)
|
||||
self._check_values(values)
|
||||
self._check_users_restrictions(values)
|
||||
|
||||
def normalize(self, values, uldif):
|
||||
"normalizes"
|
||||
return values
|
||||
|
||||
def self._check_cardinality(values):
|
||||
"""Vérifie qu'il y a un nombre correct de valeur =1, <=1, {0,1},
|
||||
etc..."""
|
||||
if self.singlevalue and len(vals) > 1:
|
||||
raise ValueError(u'%s doit avoir au maximum une valeur (affecte %s)' % self.__class__, values)
|
||||
if not self.optional and len(vals) == 0:
|
||||
raise ValueError('%s doit avoir au moins une valeur' % attr)
|
||||
|
||||
def _check_type(self, values):
|
||||
"""Vérifie que les valeurs ont le bon type (nom est un mot, tel
|
||||
est un nombre, etc...)"""
|
||||
for v in values:
|
||||
assert isunicode(v)
|
||||
|
||||
def _check_uniqueness(self, values):
|
||||
"""Vérifie l'unicité dans la base de la valeur (mailAlias, chbre,
|
||||
etc...)"""
|
||||
pass
|
||||
|
||||
def _check_values(self, values):
|
||||
"""Vérifie que les valeurs sont valides (typiquement chbre)"""
|
||||
pass
|
||||
|
||||
def _check_users_restrictions(self, values):
|
||||
"""Vérifie les restrictions supplémentaires imposées selon les
|
||||
niveaux de droits (<= 3 mailAlias, pas de mac identiques,
|
||||
etc...)"""
|
||||
pass
|
||||
|
||||
def can_modify(self):
|
||||
"""Vérifie si l'attribut est modifiable"""
|
||||
return False
|
||||
|
||||
Class nom(Attr):
|
||||
singlevalue = True
|
||||
optional = False
|
||||
legend = "Nom"
|
||||
def _check_type(self, values): return validate_name()
|
||||
|
||||
def normalize(self, values):
|
||||
return [ values.strip().capitalize() for v in values ]
|
||||
|
||||
Class prenom(Attr):
|
||||
singlevalue = True
|
||||
optional = False
|
||||
legend = u"Prénom"
|
||||
def _check_type(self, values): return validate_name()
|
||||
|
||||
def normalize(self, values):
|
||||
return [ values.strip().capitalize() for v in values ]
|
||||
|
||||
class tel(Attr):
|
||||
singlevalue = True
|
||||
optional = False
|
||||
legend = u"Téléphone"
|
||||
|
||||
def normalize(self, value):
|
||||
return value # XXX - To implement
|
||||
|
||||
class paiement(Attr):
|
||||
singlevallue = False
|
||||
optional = True
|
||||
legend = u"Paiement"
|
||||
|
||||
def normalize(self, values):
|
||||
return values # XXX - To implement
|
||||
|
||||
class carteEtudiant(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u"Carte d'étudiant"
|
||||
|
||||
class mailAlias(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u"Alias mail"
|
||||
|
||||
class canonicalAlias(Attr):
|
||||
singlevalue = True
|
||||
optional = False
|
||||
legend = u"Alias mail canonique"
|
||||
|
||||
class etudes(Attr):
|
||||
singlevalue = False
|
||||
optional = False
|
||||
legend = u"Études"
|
||||
|
||||
class chbre(Attr):
|
||||
singlevalue = True
|
||||
optional = False
|
||||
legend = u"Chambre sur le campus"
|
||||
|
||||
class droits(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u"Droits sur les serveurs"
|
||||
|
||||
class solde(Attr):
|
||||
singlevalue = True
|
||||
optional = True
|
||||
legend = u"Solde d'impression"
|
||||
|
||||
|
||||
class mid(Attr):
|
||||
singlevalue = True
|
||||
optional = False
|
||||
legend = "Identifiant de machine"
|
||||
|
||||
class hostAlias(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u'Alias de nom de machine'
|
||||
|
||||
class ipsec(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u'Clef wifi'
|
||||
|
||||
class puissance(Attr):
|
||||
singlevalue = True
|
||||
optional = True
|
||||
legend = u"puissance d'émission pour les bornes wifi"
|
||||
|
||||
class canal(Attr):
|
||||
singlevalue = True
|
||||
optional = True
|
||||
legend = u'Canal d\'émission de la borne'
|
||||
|
||||
class portTCPout(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u'Port TCP ouvert vers l\'extérieur'
|
||||
|
||||
class portTCPin(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u"Port TCP ouvert depuis l'extérieur"
|
||||
|
||||
class portUDPout(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u"Port UDP ouvert vers l'extérieur"
|
||||
|
||||
class portUDPin(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u"Port UDP ouvert depuis l'extérieur"
|
||||
|
||||
class prise(Attr):
|
||||
singlevalue = True
|
||||
optional = True
|
||||
legend = u"Prise sur laquelle est branchée la machine"
|
||||
|
||||
class cid(Attr):
|
||||
singlevalue = True
|
||||
optional = True
|
||||
legend = u"Identifiant du club"
|
||||
|
||||
class responsable(Attr):
|
||||
singlevalue = True
|
||||
optional =True
|
||||
legend = u"Responsable du club"
|
||||
|
||||
|
||||
class blacklist(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u"Blackliste"
|
||||
|
||||
class historique(Attr):
|
||||
singlevalue = False
|
||||
optional = True
|
||||
legend = u"Historique de l'objet"
|
||||
|
||||
|
||||
# CRANS_ATTRIBUTES = {
|
||||
# 'nom' : { 'attr' : 'nom',
|
||||
# 'hname' : 'Nom',
|
||||
# 'isunique' : True },
|
||||
# 'prenom' : { 'attr' : 'prenom',
|
||||
# 'hname' : u'Prénom',
|
||||
# 'isunique' : True },
|
||||
# 'tel' : { 'attr' : 'tel',
|
||||
# 'hname' : 'Téléphone',
|
||||
# 'isunique' : True },
|
||||
# 'paiement' : { 'attr' : 'paiement',
|
||||
# 'hname' : u'Années de cotisations',
|
||||
# 'isunique' : False },
|
||||
# 'carteEtudiant' : { 'attr' : 'carteEtudiant',
|
||||
# 'hname' : u'Carte fournie pour les années',
|
||||
# 'isunique' : False },
|
||||
# 'mailAlias' : { 'attr' : 'mailAlias',
|
||||
# 'hname' : 'Alias mail',
|
||||
# 'isunique' : False },
|
||||
# 'canonicalAlias' : { 'attr' : 'canonicalAlias',
|
||||
# 'hname' : 'Alias mail canonique',
|
||||
# 'isunique' : True },
|
||||
# 'etudes' : { 'attr' : 'etudes',
|
||||
# 'hname' : u'Études suivies',
|
||||
# 'isunique' : False },
|
||||
# 'chbre' : { 'attr' : 'chbre',
|
||||
# 'hname' : 'Chambre',
|
||||
# 'isunique' : True },
|
||||
# 'droits' : { 'attr' : 'droits',
|
||||
# 'hname' : 'Droits',
|
||||
# 'isunique' : False },
|
||||
# 'solde' : { 'attr' : 'solde',
|
||||
# 'hname' : "Solde sur le compte d'impression",
|
||||
# 'isunique' : True },
|
||||
#
|
||||
#
|
||||
# 'mid' : { 'attr' : 'mid',
|
||||
# 'hname' : 'Identifiant de machine',
|
||||
# 'isunique' : True },
|
||||
# 'hostAlias' : { 'attr' : 'hostAlias',
|
||||
# 'hname' : 'Alias de nom de machine',
|
||||
# 'isunique' : False },
|
||||
# 'ipsec' : { 'attr' : 'ipsec',
|
||||
# 'hname' : 'Clef wifi',
|
||||
# 'isunique' : True },
|
||||
# 'puissance' : { 'attr' : 'puissance',
|
||||
# 'hname' : u"Puissance d'émission de la borne wifi",
|
||||
# 'isunique' : True },
|
||||
# 'canal' : { 'attr' : 'canal',
|
||||
# 'hname' : u"Canal d'émission de la borne wifi",
|
||||
# 'isunique' : True },
|
||||
# 'portTCPout' : { 'attr' : 'portTCPout',
|
||||
# 'hname' : u"Port TCP ouvert vers l'extérieur",
|
||||
# 'isunique' : False },
|
||||
# 'portTCPin' : { 'attr' : 'portTCPin',
|
||||
# 'hname' : u"Port TCP ouvert depuis l'extérieur",
|
||||
# 'isunique' : False },
|
||||
# 'portUDPout' : { 'attr' : 'portUDPout',
|
||||
# 'hname' : u"Port UDP ouvert vers l'extérieur",
|
||||
# 'isunique' : False },
|
||||
# 'portUDPin' : { 'attr' : 'portUDPin',
|
||||
# 'hname' : u"Port UDP ouvert depuis l'extérieur",
|
||||
# 'isunique' : False },
|
||||
# 'prise' : { 'attr' : 'prise',
|
||||
# 'hname' : 'Prise sur laquelle est branchée la machine',
|
||||
# 'isunique' : True },
|
||||
#
|
||||
#
|
||||
# 'cid' : { 'attr' : 'cid',
|
||||
# 'hname' : 'Identifiant de club',
|
||||
# 'isunique' : True },
|
||||
# 'responsable' : { 'attr' : 'responsable',
|
||||
# 'hname' : 'Responsable du club',
|
||||
# 'isunique' : True },
|
||||
#
|
||||
# 'blacklist' : {'attr' : 'blacklist',
|
||||
# 'hname' : 'Historique des sanctions',
|
||||
# 'isunique' : False },
|
||||
# 'historique' : { 'attr' : 'historique',
|
||||
# 'hname' : 'Historique des modifications',
|
||||
# 'isunique' : False },
|
||||
# }
|
Loading…
Add table
Add a link
Reference in a new issue