les noms des machines sont maintenant ultra cleans
This commit is contained in:
parent
716124e9d5
commit
0fce45a997
@ -26,7 +26,7 @@ import ldap
|
|||||||
|
|
||||||
#root = tg.config['application_root_module'].RootController
|
#root = tg.config['application_root_module'].RootController
|
||||||
|
|
||||||
""" Controller d'edition de details de membres, chambres"""
|
""" Controller d'edition de details de membres, chambres"""
|
||||||
class EditController(AuthenticatedBaseController):
|
class EditController(AuthenticatedBaseController):
|
||||||
require_group = groups_enum.admin
|
require_group = groups_enum.admin
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ class EditController(AuthenticatedBaseController):
|
|||||||
self.add = MemberAddController()
|
self.add = MemberAddController()
|
||||||
self.member_delete = MemberDeleteController(self.machine, self.room, self.cotisation)
|
self.member_delete = MemberDeleteController(self.machine, self.room, self.cotisation)
|
||||||
|
|
||||||
|
|
||||||
""" Affiche les détails éditables de la chambre """
|
""" Affiche les détails éditables de la chambre """
|
||||||
@expose("brie.templates.edit.room")
|
@expose("brie.templates.edit.room")
|
||||||
def room(self, residence, room_id):
|
def room(self, residence, room_id):
|
||||||
@ -78,14 +78,14 @@ class MemberAddController(AuthenticatedRestController):
|
|||||||
#end if
|
#end if
|
||||||
|
|
||||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||||
|
|
||||||
# On modifie silencieusement le nom de la machine si il existe déjà
|
# On modifie silencieusement le nom de la machine si il existe déjà
|
||||||
def try_name(name, number):
|
def try_name(name, number):
|
||||||
actual_name = name
|
actual_name = name
|
||||||
if number > 0:
|
if number > 0:
|
||||||
actual_name = name + str(number)
|
actual_name = name + str(number)
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
member = Member.get_by_uid(self.user, residence_dn, actual_name)
|
member = Member.get_by_uid(self.user, residence_dn, actual_name)
|
||||||
if member is not None:
|
if member is not None:
|
||||||
return try_name(name, number + 1)
|
return try_name(name, number + 1)
|
||||||
@ -107,7 +107,7 @@ class MemberAddController(AuthenticatedRestController):
|
|||||||
|
|
||||||
|
|
||||||
member_uid = try_name(member_uid, 0)
|
member_uid = try_name(member_uid, 0)
|
||||||
|
|
||||||
member = Member.entry_attr(member_uid, prenom, nom, mail, phone, -1)
|
member = Member.entry_attr(member_uid, prenom, nom, mail, phone, -1)
|
||||||
|
|
||||||
year = CotisationComputes.registration_current_year()
|
year = CotisationComputes.registration_current_year()
|
||||||
@ -115,7 +115,7 @@ class MemberAddController(AuthenticatedRestController):
|
|||||||
member_dn = "uid=" + member_uid + ",ou=" + str(year) + "," + ldap_config.username_base_dn + residence_dn
|
member_dn = "uid=" + member_uid + ",ou=" + str(year) + "," + ldap_config.username_base_dn + residence_dn
|
||||||
year_directory_exists(year)
|
year_directory_exists(year)
|
||||||
self.user.ldap_bind.add_entry(member_dn, member)
|
self.user.ldap_bind.add_entry(member_dn, member)
|
||||||
|
|
||||||
|
|
||||||
#preview = member, room
|
#preview = member, room
|
||||||
#index_result["preview"] = preview
|
#index_result["preview"] = preview
|
||||||
@ -154,10 +154,10 @@ class MemberModificationController(AuthenticatedRestController):
|
|||||||
@expose("brie.templates.edit.member")
|
@expose("brie.templates.edit.member")
|
||||||
def get(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)
|
||||||
|
|
||||||
self.show.user = self.user
|
self.show.user = self.user
|
||||||
show_values = self.show.member(residence, uid)
|
show_values = self.show.member(residence, uid)
|
||||||
|
|
||||||
rooms = Room.get_rooms(self.user, residence_dn)
|
rooms = Room.get_rooms(self.user, residence_dn)
|
||||||
if rooms is None:
|
if rooms is None:
|
||||||
raise Exception("unable to retrieve rooms")
|
raise Exception("unable to retrieve rooms")
|
||||||
@ -174,7 +174,7 @@ class MemberModificationController(AuthenticatedRestController):
|
|||||||
#end if
|
#end if
|
||||||
#end for
|
#end for
|
||||||
#end for
|
#end for
|
||||||
|
|
||||||
|
|
||||||
show_values["rooms"] = rooms
|
show_values["rooms"] = rooms
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ class MemberModificationController(AuthenticatedRestController):
|
|||||||
already_paid = 0
|
already_paid = 0
|
||||||
for cotisation in cotisations:
|
for cotisation in cotisations:
|
||||||
paid_months = (
|
paid_months = (
|
||||||
paid_months +
|
paid_months +
|
||||||
[int(month) for month in cotisation.get("x-validMonth").all()]
|
[int(month) for month in cotisation.get("x-validMonth").all()]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -230,7 +230,7 @@ class MemberModificationController(AuthenticatedRestController):
|
|||||||
|
|
||||||
available_months_prices = []
|
available_months_prices = []
|
||||||
index = 1
|
index = 1
|
||||||
|
|
||||||
anniversary = CotisationComputes.generate_new_anniversary_from_ldap_items(cotisations)
|
anniversary = CotisationComputes.generate_new_anniversary_from_ldap_items(cotisations)
|
||||||
|
|
||||||
for available_month in available_months:
|
for available_month in available_months:
|
||||||
@ -238,7 +238,7 @@ class MemberModificationController(AuthenticatedRestController):
|
|||||||
available_months_prices.append(
|
available_months_prices.append(
|
||||||
(available_month, "fin de l'année ".decode("utf-8"), CotisationComputes.price_to_pay(year_price, month_price, already_paid, index))
|
(available_month, "fin de l'année ".decode("utf-8"), CotisationComputes.price_to_pay(year_price, month_price, already_paid, index))
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
available_months_prices.append(
|
available_months_prices.append(
|
||||||
(available_month, str(anniversary.day) + " " + month_names[available_month % 12], CotisationComputes.price_to_pay(year_price, month_price, already_paid, index))
|
(available_month, str(anniversary.day) + " " + month_names[available_month % 12], CotisationComputes.price_to_pay(year_price, month_price, already_paid, index))
|
||||||
)
|
)
|
||||||
@ -247,7 +247,7 @@ class MemberModificationController(AuthenticatedRestController):
|
|||||||
#end for
|
#end for
|
||||||
|
|
||||||
show_values["available_months_prices"] = available_months_prices
|
show_values["available_months_prices"] = available_months_prices
|
||||||
|
|
||||||
extras_available = Cotisation.get_all_extras(self.user, residence_dn)
|
extras_available = Cotisation.get_all_extras(self.user, residence_dn)
|
||||||
show_values["extras_available"] = extras_available
|
show_values["extras_available"] = extras_available
|
||||||
|
|
||||||
@ -263,7 +263,7 @@ class MemberModificationController(AuthenticatedRestController):
|
|||||||
sn = unicode.encode(sn, 'utf-8')
|
sn = unicode.encode(sn, 'utf-8')
|
||||||
givenName = unicode.encode(givenName, 'utf-8')
|
givenName = unicode.encode(givenName, 'utf-8')
|
||||||
comment = unicode.encode(comment, 'utf-8')
|
comment = unicode.encode(comment, 'utf-8')
|
||||||
|
|
||||||
member.sn.replace(member.sn.first(), sn)
|
member.sn.replace(member.sn.first(), sn)
|
||||||
|
|
||||||
member.givenName.replace(member.givenName.first(), givenName)
|
member.givenName.replace(member.givenName.first(), givenName)
|
||||||
@ -298,7 +298,7 @@ class MemberDisableController(AuthenticatedRestController):
|
|||||||
#end if
|
#end if
|
||||||
|
|
||||||
dhcps = Machine.get_dhcps(self.user, member.dn)
|
dhcps = Machine.get_dhcps(self.user, member.dn)
|
||||||
|
|
||||||
machine_membre_tag = "machine_membre" # FIXME move to config
|
machine_membre_tag = "machine_membre" # FIXME move to config
|
||||||
|
|
||||||
for dhcp_item in dhcps:
|
for dhcp_item in dhcps:
|
||||||
@ -331,7 +331,7 @@ class MemberEnableController(AuthenticatedRestController):
|
|||||||
#end if
|
#end if
|
||||||
|
|
||||||
dhcps = Machine.get_dhcps(self.user, member.dn)
|
dhcps = Machine.get_dhcps(self.user, member.dn)
|
||||||
|
|
||||||
machine_membre_tag = "machine_membre" # FIXME move to config
|
machine_membre_tag = "machine_membre" # FIXME move to config
|
||||||
machine_membre_disabled = machine_membre_tag + "_disabled" # FIXME move to config
|
machine_membre_disabled = machine_membre_tag + "_disabled" # FIXME move to config
|
||||||
|
|
||||||
@ -354,7 +354,7 @@ class MemberDeleteController(AuthenticatedRestController):
|
|||||||
machine = None
|
machine = None
|
||||||
room = None
|
room = None
|
||||||
cotisation = None
|
cotisation = None
|
||||||
|
|
||||||
def __init__(self, machine, room, cotisation):
|
def __init__(self, machine, room, cotisation):
|
||||||
self.machine = machine
|
self.machine = machine
|
||||||
self.room = room
|
self.room = room
|
||||||
@ -441,7 +441,9 @@ class MachineAddController(AuthenticatedRestController):
|
|||||||
|
|
||||||
mac = mac.strip()
|
mac = mac.strip()
|
||||||
name = name.strip().replace(" ", "-").replace("_", "-")
|
name = name.strip().replace(" ", "-").replace("_", "-")
|
||||||
name = Translations.strip_accents(name)
|
name = Translations.formatName(name)
|
||||||
|
#name = Translations.strip_accents(name)
|
||||||
|
|
||||||
|
|
||||||
#Vérification que l'adresse mac soit correcte
|
#Vérification que l'adresse mac soit correcte
|
||||||
mac_match = re.match('^([0-9A-Fa-f]{2}[:-]?){5}([0-9A-Fa-f]{2})$', mac)
|
mac_match = re.match('^([0-9A-Fa-f]{2}[:-]?){5}([0-9A-Fa-f]{2})$', mac)
|
||||||
@ -455,7 +457,7 @@ class MachineAddController(AuthenticatedRestController):
|
|||||||
if mac_match is not None:
|
if mac_match is not None:
|
||||||
mac = mac_match.group(1) + ":" + mac_match.group(2) + ":" + mac_match.group(3) + ":" + mac_match.group(4) + ":" + mac_match.group(5) + ":" + mac_match.group(6)
|
mac = mac_match.group(1) + ":" + mac_match.group(2) + ":" + mac_match.group(3) + ":" + mac_match.group(4) + ":" + mac_match.group(5) + ":" + mac_match.group(6)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#Remplacement de l'adresse mac séparée par des tirets
|
#Remplacement de l'adresse mac séparée par des tirets
|
||||||
mac_match = re.match('^([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})$', mac)
|
mac_match = re.match('^([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})$', mac)
|
||||||
if mac_match is not None:
|
if mac_match is not None:
|
||||||
@ -488,7 +490,7 @@ class MachineAddController(AuthenticatedRestController):
|
|||||||
actual_name = name
|
actual_name = name
|
||||||
if number > 0:
|
if number > 0:
|
||||||
actual_name = name + "-" + str(number)
|
actual_name = name + "-" + str(number)
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
machine = Machine.get_dns_by_name(self.user, member_base_dn, actual_name)
|
machine = Machine.get_dns_by_name(self.user, member_base_dn, actual_name)
|
||||||
if machine is not None:
|
if machine is not None:
|
||||||
@ -502,7 +504,7 @@ class MachineAddController(AuthenticatedRestController):
|
|||||||
name = re.sub('_', '-', name)
|
name = re.sub('_', '-', name)
|
||||||
|
|
||||||
name = try_name(name, 0)
|
name = try_name(name, 0)
|
||||||
|
|
||||||
# Génération de l'id de la machine et recherche d'une ip libre
|
# Génération de l'id de la machine et recherche d'une ip libre
|
||||||
ip = IpReservation.get_first_free(self.user, residence_dn)
|
ip = IpReservation.get_first_free(self.user, residence_dn)
|
||||||
|
|
||||||
@ -510,7 +512,7 @@ class MachineAddController(AuthenticatedRestController):
|
|||||||
raise Exception("le pool d'adresse IP est vide. aucune adresse IP disponible pour ajouter une machine")
|
raise Exception("le pool d'adresse IP est vide. aucune adresse IP disponible pour ajouter une machine")
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
# Indique que l'ip est prise
|
# Indique que l'ip est prise
|
||||||
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)
|
||||||
|
|
||||||
@ -528,24 +530,24 @@ class MachineAddController(AuthenticatedRestController):
|
|||||||
# Attributs ldap des objets dhcp et dns, fils de l'objet machine
|
# Attributs ldap des objets dhcp et dns, fils de l'objet machine
|
||||||
machine_dhcp = Machine.dhcp_attr(name, mac)
|
machine_dhcp = Machine.dhcp_attr(name, mac)
|
||||||
machine_dns = Machine.dns_attr(name, ip.cn.first())
|
machine_dns = Machine.dns_attr(name, ip.cn.first())
|
||||||
|
|
||||||
# Construction du dn et ajout de l'objet machine
|
# Construction du dn et ajout de l'objet machine
|
||||||
# en fils du membre (membre.dn)
|
# en fils du membre (membre.dn)
|
||||||
machine_dn = "cn=" + name + "," + ldap_config.machine_base_dn + member.dn
|
machine_dn = "cn=" + name + "," + ldap_config.machine_base_dn + member.dn
|
||||||
self.user.ldap_bind.add_entry(machine_dn, machine_top)
|
self.user.ldap_bind.add_entry(machine_dn, machine_top)
|
||||||
|
|
||||||
# Construction du dn et ajout de l'objet dhcp
|
# Construction du dn et ajout de l'objet dhcp
|
||||||
# en fils de la machine (machine_dn)
|
# en fils de la machine (machine_dn)
|
||||||
dhcp_dn = "cn=dhcp," + machine_dn
|
dhcp_dn = "cn=dhcp," + machine_dn
|
||||||
self.user.ldap_bind.add_entry(dhcp_dn, machine_dhcp)
|
self.user.ldap_bind.add_entry(dhcp_dn, machine_dhcp)
|
||||||
|
|
||||||
# Construction du dn et ajout de l'objet dns
|
# Construction du dn et ajout de l'objet dns
|
||||||
dns_dn = "cn=dns," + machine_dn
|
dns_dn = "cn=dns," + machine_dn
|
||||||
self.user.ldap_bind.add_entry(dns_dn, machine_dns)
|
self.user.ldap_bind.add_entry(dns_dn, machine_dns)
|
||||||
|
|
||||||
# Ajout de l'entrée dans les logs
|
# Ajout de l'entrée dans les logs
|
||||||
BrieLogging.get().info("ajout machine " + mac + " pour l'utilisateur "+ member.dn + " par l'admin "+ self.user.attrs.dn)
|
BrieLogging.get().info("ajout machine " + mac + " pour l'utilisateur "+ member.dn + " par l'admin "+ self.user.attrs.dn)
|
||||||
|
|
||||||
plugin_vars = {
|
plugin_vars = {
|
||||||
"machine_dn" : machine_dn,
|
"machine_dn" : machine_dn,
|
||||||
"name" : name,
|
"name" : name,
|
||||||
@ -554,13 +556,13 @@ class MachineAddController(AuthenticatedRestController):
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugin_action(self.user, residence, plugin_vars)
|
plugin_action(self.user, residence, plugin_vars)
|
||||||
|
|
||||||
if go_redirect:
|
if go_redirect:
|
||||||
redirect("/edit/member/" + residence + "/" + member_uid)
|
redirect("/edit/member/" + residence + "/" + member_uid)
|
||||||
#end if
|
#end if
|
||||||
#end def
|
#end def
|
||||||
#end class
|
#end class
|
||||||
|
|
||||||
class CotisationController(AuthenticatedBaseController):
|
class CotisationController(AuthenticatedBaseController):
|
||||||
require_group = groups_enum.admin
|
require_group = groups_enum.admin
|
||||||
|
|
||||||
@ -650,7 +652,7 @@ class CotisationAddController(AuthenticatedRestController):
|
|||||||
def create_cotisation(self, member, time, current_year, residence, residence_dn, member_uid, next_end):
|
def create_cotisation(self, member, time, current_year, residence, residence_dn, member_uid, next_end):
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
next_month = int(next_end)
|
next_month = int(next_end)
|
||||||
|
|
||||||
if not CotisationComputes.is_valid_month(next_month):
|
if not CotisationComputes.is_valid_month(next_month):
|
||||||
raise Exception("Invalid month") #FIXME
|
raise Exception("Invalid month") #FIXME
|
||||||
@ -661,7 +663,7 @@ class CotisationAddController(AuthenticatedRestController):
|
|||||||
already_paid = 0
|
already_paid = 0
|
||||||
for cotisation in cotisations_existantes:
|
for cotisation in cotisations_existantes:
|
||||||
paid_months = (
|
paid_months = (
|
||||||
paid_months +
|
paid_months +
|
||||||
[int(month) for month in cotisation.get("x-validMonth").all()]
|
[int(month) for month in cotisation.get("x-validMonth").all()]
|
||||||
)
|
)
|
||||||
already_paid += int(cotisation.get("x-amountPaid").first())
|
already_paid += int(cotisation.get("x-amountPaid").first())
|
||||||
@ -681,11 +683,11 @@ class CotisationAddController(AuthenticatedRestController):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
#end try
|
#end try
|
||||||
|
|
||||||
price_to_pay = CotisationComputes.price_to_pay(year_price, month_price, already_paid, len(available_months))
|
price_to_pay = CotisationComputes.price_to_pay(year_price, month_price, already_paid, len(available_months))
|
||||||
|
|
||||||
|
|
||||||
# réactivation des machines du membre # FIXME
|
# réactivation des machines du membre # FIXME
|
||||||
if now.month in available_months:
|
if now.month in available_months:
|
||||||
dhcps = Machine.get_dhcps(self.user, member.dn)
|
dhcps = Machine.get_dhcps(self.user, member.dn)
|
||||||
|
|
||||||
@ -709,7 +711,7 @@ class CotisationAddController(AuthenticatedRestController):
|
|||||||
user_info = self.user.attrs.cn.first()
|
user_info = self.user.attrs.cn.first()
|
||||||
return Cotisation.extra_attr(time, residence, current_year, self.user.attrs.dn, user_info, extra_item.uid.first(), prix)
|
return Cotisation.extra_attr(time, residence, current_year, self.user.attrs.dn, user_info, extra_item.uid.first(), prix)
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
@expose()
|
@expose()
|
||||||
def post(self, residence, member_uid, next_end, extra_name, go_redirect = True):
|
def post(self, residence, member_uid, next_end, extra_name, go_redirect = True):
|
||||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||||
@ -723,7 +725,7 @@ class CotisationAddController(AuthenticatedRestController):
|
|||||||
|
|
||||||
if next_end != "":
|
if next_end != "":
|
||||||
cotisation = self.create_cotisation(member, time, current_year, residence, residence_dn, member_uid, next_end)
|
cotisation = self.create_cotisation(member, time, current_year, residence, residence_dn, member_uid, next_end)
|
||||||
|
|
||||||
if extra_name != "":
|
if extra_name != "":
|
||||||
extra = self.create_extra(time, current_year, residence, residence_dn, member_uid, extra_name)
|
extra = self.create_extra(time, current_year, residence, residence_dn, member_uid, extra_name)
|
||||||
#end if
|
#end if
|
||||||
@ -735,10 +737,10 @@ class CotisationAddController(AuthenticatedRestController):
|
|||||||
return
|
return
|
||||||
#end if
|
#end if
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
folder_dn = ldap_config.cotisation_member_base_dn + member.dn
|
folder_dn = ldap_config.cotisation_member_base_dn + member.dn
|
||||||
year_dn = "cn=" + str(current_year) + "," + folder_dn
|
year_dn = "cn=" + str(current_year) + "," + folder_dn
|
||||||
|
|
||||||
try:
|
try:
|
||||||
folder = Cotisation.folder_attr()
|
folder = Cotisation.folder_attr()
|
||||||
self.user.ldap_bind.add_entry(folder_dn, folder)
|
self.user.ldap_bind.add_entry(folder_dn, folder)
|
||||||
@ -753,12 +755,12 @@ class CotisationAddController(AuthenticatedRestController):
|
|||||||
pass # OKAY
|
pass # OKAY
|
||||||
#end try
|
#end try
|
||||||
|
|
||||||
|
|
||||||
if cotisation is not None:
|
if cotisation is not None:
|
||||||
cotisation_dn = "cn=cotisation-" + time + "," + year_dn
|
cotisation_dn = "cn=cotisation-" + time + "," + year_dn
|
||||||
BrieLogging.get().info("cotisation ajoutee pour "+ member.dn +"("+str(cotisation.get("x-amountPaid")) +"EUR) by "+ self.user.attrs.dn)
|
BrieLogging.get().info("cotisation ajoutee pour "+ member.dn +"("+str(cotisation.get("x-amountPaid")) +"EUR) by "+ self.user.attrs.dn)
|
||||||
self.user.ldap_bind.add_entry(cotisation_dn, cotisation)
|
self.user.ldap_bind.add_entry(cotisation_dn, cotisation)
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
if extra is not None:
|
if extra is not None:
|
||||||
extra_dn = "cn=extra-" + time + "," + year_dn
|
extra_dn = "cn=extra-" + time + "," + year_dn
|
||||||
@ -769,7 +771,7 @@ class CotisationAddController(AuthenticatedRestController):
|
|||||||
if go_redirect:
|
if go_redirect:
|
||||||
redirect("/edit/member/" + residence + "/" + member_uid)
|
redirect("/edit/member/" + residence + "/" + member_uid)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
#end if
|
#end if
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
@ -897,28 +899,28 @@ class WifiRestController(AuthenticatedRestController):
|
|||||||
|
|
||||||
def __init__(self, new_show):
|
def __init__(self, new_show):
|
||||||
self.show = new_show
|
self.show = new_show
|
||||||
|
|
||||||
@expose("brie.templates.edit.wifi")
|
@expose("brie.templates.edit.wifi")
|
||||||
def get(self, uid):
|
def get(self, uid):
|
||||||
member = Member.get_by_uid(self.user, self.user.residence_dn, uid)
|
member = Member.get_by_uid(self.user, self.user.residence_dn, uid)
|
||||||
|
|
||||||
if member is None:
|
if member is None:
|
||||||
self.show.error_no_entry()
|
self.show.error_no_entry()
|
||||||
|
|
||||||
return { "member_ldap" : member }
|
return { "member_ldap" : member }
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
|
|
||||||
@expose("brie.templates.edit.wifi")
|
@expose("brie.templates.edit.wifi")
|
||||||
def post(self, uid, password):
|
def post(self, uid, password):
|
||||||
|
|
||||||
member = Member.get_by_uid(self.user, self.user.residence_dn, uid)
|
member = Member.get_by_uid(self.user, self.user.residence_dn, uid)
|
||||||
|
|
||||||
if member is None:
|
if member is None:
|
||||||
self.show.error_no_entry()
|
self.show.error_no_entry()
|
||||||
|
|
||||||
wifi = Wifi.get_by_dn(self.user, member.dn)
|
wifi = Wifi.get_by_dn(self.user, member.dn)
|
||||||
|
|
||||||
if wifi is None:
|
if wifi is None:
|
||||||
wifi_dn = "cn=wifi," + member.dn
|
wifi_dn = "cn=wifi," + member.dn
|
||||||
self.user.ldap_bind.add_entry(wifi_dn, Wifi.entry_attr(password))
|
self.user.ldap_bind.add_entry(wifi_dn, Wifi.entry_attr(password))
|
||||||
@ -930,7 +932,7 @@ class WifiRestController(AuthenticatedRestController):
|
|||||||
redirect("/show/member/" + uid)
|
redirect("/show/member/" + uid)
|
||||||
#end def
|
#end def
|
||||||
#end class
|
#end class
|
||||||
|
|
||||||
""" Controller de gestion des rooms """
|
""" Controller de gestion des rooms """
|
||||||
class RoomController(AuthenticatedBaseController):
|
class RoomController(AuthenticatedBaseController):
|
||||||
require_group = groups_enum.admin
|
require_group = groups_enum.admin
|
||||||
@ -948,7 +950,7 @@ class RoomController(AuthenticatedBaseController):
|
|||||||
""" Affiche les détails éditables de la chambre """
|
""" Affiche les détails éditables de la chambre """
|
||||||
@expose("brie.templates.edit.room")
|
@expose("brie.templates.edit.room")
|
||||||
def index(self, residence, room_id):
|
def index(self, residence, room_id):
|
||||||
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
residence_dn = Residences.get_dn_by_name(self.user, residence)
|
||||||
|
|
||||||
room = Room.get_by_uid(self.user, residence_dn, room_id)
|
room = Room.get_by_uid(self.user, residence_dn, room_id)
|
||||||
|
|
||||||
@ -960,14 +962,14 @@ class RoomController(AuthenticatedBaseController):
|
|||||||
member = Member.get_by_dn(self.user, room.get("x-memberIn").first())
|
member = Member.get_by_dn(self.user, room.get("x-memberIn").first())
|
||||||
|
|
||||||
members = Member.get_all(self.user, residence_dn)
|
members = Member.get_all(self.user, residence_dn)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"residence" : residence,
|
"residence" : residence,
|
||||||
"user" : self.user,
|
"user" : self.user,
|
||||||
"room_ldap" : room,
|
"room_ldap" : room,
|
||||||
"member_ldap" : member,
|
"member_ldap" : member,
|
||||||
"members" : members
|
"members" : members
|
||||||
}
|
}
|
||||||
#se Exception("tait toi")
|
#se Exception("tait toi")
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
@ -1016,7 +1018,7 @@ class RoomMoveController(AuthenticatedRestController):
|
|||||||
BrieLogging.get().info("retrait de chambre pour le member "+member_uid+" from "+ old_room.uid.first() +" by "+self.user.attrs.dn)
|
BrieLogging.get().info("retrait de chambre pour le member "+member_uid+" from "+ old_room.uid.first() +" by "+self.user.attrs.dn)
|
||||||
#end if
|
#end if
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
#self.user.ldap_bind.delete_entry_subtree(machine.dn)
|
#self.user.ldap_bind.delete_entry_subtree(machine.dn)
|
||||||
|
|
||||||
#taken_attribute = IpReservation.taken_attr(ip.get("x-taken").first())
|
#taken_attribute = IpReservation.taken_attr(ip.get("x-taken").first())
|
||||||
@ -1051,7 +1053,7 @@ class RoomChangeMemberController(AuthenticatedRestController):
|
|||||||
|
|
||||||
if member is not None:
|
if member is not None:
|
||||||
old_room_member = Room.get_by_member_dn(self.user, residence_dn, member.dn)
|
old_room_member = Room.get_by_member_dn(self.user, residence_dn, member.dn)
|
||||||
|
|
||||||
# Si la machine existe effectivement, on la supprime
|
# Si la machine existe effectivement, on la supprime
|
||||||
if old_room_member is not None:
|
if old_room_member is not None:
|
||||||
raise Exception("le nouveau membre possèdait déjà une chambre. conflit")
|
raise Exception("le nouveau membre possèdait déjà une chambre. conflit")
|
||||||
@ -1071,7 +1073,7 @@ class RoomChangeMemberController(AuthenticatedRestController):
|
|||||||
memberIn_attribute = Room.memberIn_attr(str(member.dn))
|
memberIn_attribute = Room.memberIn_attr(str(member.dn))
|
||||||
self.user.ldap_bind.add_attr(room.dn, memberIn_attribute)
|
self.user.ldap_bind.add_attr(room.dn, memberIn_attribute)
|
||||||
BrieLogging.get().info("ajout de chambre pour le member "+ member_uid +" to "+ room_uid +" by "+self.user.attrs.dn)
|
BrieLogging.get().info("ajout de chambre pour le member "+ member_uid +" to "+ room_uid +" by "+self.user.attrs.dn)
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
# On redirige sur la page d'édition du membre
|
# On redirige sur la page d'édition du membre
|
||||||
redirect("/edit/room/index/" + residence + "/" + room_uid)
|
redirect("/edit/room/index/" + residence + "/" + room_uid)
|
||||||
@ -1097,7 +1099,7 @@ class AllMembersDisableController(AuthenticatedRestController):
|
|||||||
groups_of_user = Groupes.get_by_user_dn(self.user, residence_dn, member.dn)
|
groups_of_user = Groupes.get_by_user_dn(self.user, residence_dn, member.dn)
|
||||||
if "exemptdecoglobale" not in groups_of_user:
|
if "exemptdecoglobale" not in groups_of_user:
|
||||||
dhcps = Machine.get_dhcps(self.user, member.dn)
|
dhcps = Machine.get_dhcps(self.user, member.dn)
|
||||||
|
|
||||||
machine_membre_tag = "machine_membre" # FIXME move to config
|
machine_membre_tag = "machine_membre" # FIXME move to config
|
||||||
|
|
||||||
for dhcp_item in dhcps:
|
for dhcp_item in dhcps:
|
||||||
@ -1132,7 +1134,7 @@ class AllMembersEnableController(AuthenticatedRestController):
|
|||||||
# On ne reconnecte que les membres ayant payé leur cotisation.
|
# On ne reconnecte que les membres ayant payé leur cotisation.
|
||||||
if CotisationComputes.is_cotisation_paid(member.dn, self.user, residence_dn):
|
if CotisationComputes.is_cotisation_paid(member.dn, self.user, residence_dn):
|
||||||
dhcps = Machine.get_dhcps(self.user, member.dn)
|
dhcps = Machine.get_dhcps(self.user, member.dn)
|
||||||
|
|
||||||
machine_membre_tag = "machine_membre" # FIXME move to config
|
machine_membre_tag = "machine_membre" # FIXME move to config
|
||||||
machine_membre_disabled = machine_membre_tag + "_disabled" # FIXME move to config
|
machine_membre_disabled = machine_membre_tag + "_disabled" # FIXME move to config
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from os import urandom
|
|||||||
from binascii import b2a_hex
|
from binascii import b2a_hex
|
||||||
|
|
||||||
class Translations(object):
|
class Translations(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def to_uid(name, surname):
|
def to_uid(name, surname):
|
||||||
clean_name = Translations.strip_accents(name.replace(" ", "")).lower()[:15]
|
clean_name = Translations.strip_accents(name.replace(" ", "")).lower()[:15]
|
||||||
@ -23,26 +23,36 @@ class Translations(object):
|
|||||||
def area_of_room(room):
|
def area_of_room(room):
|
||||||
if Translations.floor_of_room(room) == 5:
|
if Translations.floor_of_room(room) == 5:
|
||||||
return "crous"
|
return "crous"
|
||||||
|
|
||||||
floor_number = room % 100
|
floor_number = room % 100
|
||||||
|
|
||||||
if floor_number <= 33:
|
if floor_number <= 33:
|
||||||
return "sud"
|
return "sud"
|
||||||
else:
|
else:
|
||||||
return "nord"
|
return "nord"
|
||||||
#end if
|
#end if
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
#end class
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string
|
# http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def strip_accents(s):
|
def strip_accents(s):
|
||||||
return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
|
return ''.join((c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn'))
|
||||||
#end def
|
#end def
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def formatName(value):
|
||||||
|
"""
|
||||||
|
Converts to ASCII. Converts spaces to hyphens. Removes characters that
|
||||||
|
aren't alphanumerics, underscores, or hyphens. Converts to lowercase.
|
||||||
|
Also strips leading and trailing whitespace.
|
||||||
|
"""
|
||||||
|
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
|
||||||
|
value = re.sub('[^\w\s-]', '', value).strip().lower()
|
||||||
|
return re.sub('[-\s]+', '-', value)
|
||||||
|
#end def
|
||||||
|
|
||||||
|
#end class
|
||||||
|
|
||||||
class Passwords(object):
|
class Passwords(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user