diff --git a/gestion/gest_crans_lc.py b/gestion/gest_crans_lc.py index 68e71fcb..164b3ab2 100755 --- a/gestion/gest_crans_lc.py +++ b/gestion/gest_crans_lc.py @@ -618,7 +618,8 @@ class GestCrans(object): attributs.dnsIpv6 : True # pour dnsIpv6, c'est True } choices = [(a.ldap_name, a.legend, 1 if values.get(a.ldap_name, obj[a.ldap_name][0] if obj[a.ldap_name] else missing.get(a, missing['default'])) else 0) for a in attribs] - (code, output) = self.dialog.checklist("Activier ou désactiver les propriétés suivantes", + def box(): + return self.dialog.checklist("Activier ou désactiver les propriétés suivantes", height=0, width=0, timeout=self.timeout, @@ -638,6 +639,8 @@ class GestCrans(object): # On s'en va en mettant à jour dans la continuation la valeur de obj raise Continue(cont(**{update_obj:obj})) + (code, output) = self.handle_dialog(cont, box) + # On transforme la liste des cases dialog cochée en dictionnnaire values = dict((a.ldap_name, a.ldap_name in output) for a in attribs) @@ -1898,9 +1901,131 @@ les valeurs valident sont : codes_todo=[([self.dialog.DIALOG_OK], todo, [tag, menu, adherent, cont_ret])] ) - def adherent_administratif(self, cont, adherent): + def adherent_administratif(self, cont, adherent, default_item=None): + """Menu de gestion du compte crans d'un proprio""" + + a = attributs + menu_droits = { + "Adhésion": [a.cableur, a.nounou], + 'Connexion': [a.cableur, a.nounou], + "Charte MA" : [a.nounou, a.bureau], + "Carte Étudiant" : [a.nounou, a.cableur, a.tresorier], + } + menu = { + "Adhésion" : {"text":"Pour toute réadhésion *sans* connexion.", "help":"", "callback":self.adherent_adhesion}, + 'Connexion' : {'text': "Mise à jour de l'accès Internet (effectue la réadhésion si besoin)", "help":"", 'callback':self.adherent_connexion}, + "Carte Étudiant" : {"text" : "Validation de la carte étudiant", "help":"", "callback":self.adherent_carte_etudiant}, + "Charte MA" : {"text" : "Signature de la charte des membres actifs", "help":'', "callback":self.adherent_charte}, + } + menu_order = ["Adhésion", 'Connexion'] + if self.has_right(a.tresorier, adherent) or not adherent.carte_controle(): + menu_order.append("Carte Étudiant") + menu_order.append("Charte MA") + def box(default_item=None): + return self.dialog.menu( + "Quelle action administrative effectuer", + width=0, + height=0, + timeout=self.timeout, + item_help=1, + default_item=str(default_item), + title="Gestion administrative de %s %s" % (adherent.get('prenom', [''])[0], adherent["nom"][0]), + scrollbar=True, + cancel_label="Retour", + backtitle=u"Vous êtes connecté en tant que %s" % self.conn.current_login, + choices=[(k, menu[k]['text'], menu[k]['help']) for k in menu_order if self.has_right(menu_droits[k], adherent)]) + + def todo(tag, menu, adherent, self_cont): + if not tag in menu_order: + raise Continue(self_cont) + elif 'callback' in menu[tag]: + raise Continue(TailCall(menu[tag]['callback'], cont=self_cont, adherent=adherent)) + else: + raise EnvironmentError("Il n'y a pas de champs 'callback' pour le tag %s" % tag) + + + (code, tag) = self.handle_dialog(cont, box, default_item) + self_cont = TailCall(self.adherent_administratif, adherent=adherent, cont=cont, default_item=tag) + return self.handle_dialog_result( + code=code, + output=tag, + cancel_cont=cont, + error_cont=self_cont, + codes_todo=[([self.dialog.DIALOG_OK], todo, [tag, menu, adherent, self_cont])] + ) + + def adherent_adhesion(self, cont, adherent): self.dialog.msgbox("todo", width=0, height=0) return cont + def adherent_connexion(self, cont, adherent): + self.dialog.msgbox("todo", width=0, height=0) + return cont + def adherent_carte_etudiant(self, cont, adherent, values={}): + # Dictionnaire décrivant quelle est la valeur booléenne à donner à l'absence de l'attribut + a = attributs + choices = [] + choices.append((a.carteEtudiant.ldap_name, "Carte étudiant présentée", 1 if adherent.carte_ok() or values.get(a.carteEtudiant.ldap_name, False) else 0)) + if self.has_right(a.tresorier, adherent): + choices.append(("controleCarte", "La carte a-t-elle été controlée", 1 if adherent.carte_controle() or values.get("controleCarte", False) else 0)) + + def box(): + return self.dialog.checklist("Gestion de la carte étudiant", + height=0, + width=0, + timeout=self.timeout, + list_height=7, + choices=choices, + title="Gestion de la carte étudiant") + + def todo(values, adherent, cont): + # On met à jour chaque attribut si sa valeur à changé + with self.conn.search(dn=adherent.dn, scope=0, mode='rw')[0] as adherent: + # Si on est trésorier et que controleCarte a changer on enregistre le changement + if self.has_right(a.tresorier, adherent) and values["controleCarte"] and not adherent.carte_controle(): + if adherent["controle"]: + adherent["controle"] = u"c%s" % adherent["controle"][0] + else: + adherent["controle"] = u"c" + elif self.has_right(a.tresorier, adherent) and not values["controleCarte"] and adherent.carte_controle(): + adherent["controle"]=unicode(adherent["controle"][0]).replace('c','') + if not adherent["controle"][0]: + adherent["controle"] = [] + # Si la carte n'est pas validé ou qu'on est trésorier, on sauvegarde les changements + if values[a.carteEtudiant.ldap_name] and not adherent.carte_ok() and (not adherent.carte_controle() or self.has_right(a.tresorier, adherent)): + adherent[a.carteEtudiant.ldap_name] = u"TRUE" + elif not values[a.carteEtudiant.ldap_name] and adherent.carte_ok() and (not adherent.carte_controle() or self.has_right(a.tresorier, adherent)): + adherent[a.carteEtudiant.ldap_name] = [] + if adherent["controle"]: + adherent["controle"]=unicode(adherent["controle"][0]).replace('c','') + if not adherent["controle"][0]: + adherent["controle"] = [] + adherent.save() + # On s'en va en mettant à jour dans la continuation la valeur de obj + raise Continue(cont(adherent=adherent)) + + (code, output) = self.handle_dialog(cont, box) + # On transforme la liste des cases dialog cochée en dictionnnaire + values = dict((a[0], a[0] in output) for a in choices) + + # Une continuation que l'on suivra si quelque chose se passe mal + retry_cont = TailCall(self.adherent_carte_etudiant, adherent=adherent, cont=cont, values=values) + + return self.handle_dialog_result( + code=code, + output=output, + cancel_cont=cont, + error_cont=retry_cont, + codes_todo=[([self.dialog.DIALOG_OK], todo, [values, adherent, cont])] + ) + def adherent_charte(self, cont, adherent): + a = attributs + attribs = [a.charteMA] + return self.edit_boolean_attributs( + obj=adherent, + attribs=attribs, + title="Signature de la charte membre actif de %s %s" % (adherent['prenom'][0], adherent['nom'][0]), + update_obj='adherent', + cont=cont) def adherent_personnel(self, cont, adherent=None, fields_attrs={}, make_compte_crans=None, force_create=False): """ @@ -2832,13 +2957,15 @@ les valeurs valident sont : associationCrans = self.conn.search(dn="ou=data,dc=crans,dc=org", scope=0)[0] return self.create_machine_proprio(cont=cont, proprio=associationCrans) - def has_right(self, list, obj=None): + def has_right(self, liste, obj=None): """Vérifie que l'un des droits de l'utilisateur courant est inclus dans list""" + if not isinstance(liste, list): + liste = [liste] if obj: droits = obj.rights() else: droits = self.conn.droits - for d in list: + for d in liste: if d in droits: return True return False