From 90ab28a292f6c89e458deef34d8c9dc99147e7b4 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 12 Sep 2013 18:47:51 +0200 Subject: [PATCH] forms: when creating delegation for existing users, emit errors, fixes #3570 - if the email is one of an existing simple delegation refuse to create it, - if the email belong to existing normal users, list them and tell user that it must use the combo box listing existing users, - if the email belong to the current user, tell him he cannot delegate to himself. --- docbow_project/docbow/forms.py | 25 ++++- .../docbow/locale/fr/LC_MESSAGES/django.po | 105 ++++++++++-------- 2 files changed, 79 insertions(+), 51 deletions(-) diff --git a/docbow_project/docbow/forms.py b/docbow_project/docbow/forms.py index d6cb55a..452722f 100644 --- a/docbow_project/docbow/forms.py +++ b/docbow_project/docbow/forms.py @@ -340,14 +340,14 @@ class DelegationForm(Form): required=False, queryset=User.objects.all) def __init__(self, *args, **kwargs): - user = kwargs.pop('user', None) - delegatees = kwargs.pop('delegatees', []) + self.user = kwargs.pop('user', None) + self.delegatees = kwargs.pop('delegatees', []) super(DelegationForm, self).__init__(*args, **kwargs) qs = non_guest_users() - if user: - qs = qs.exclude(id=user.id) - if delegatees: - qs = qs.exclude(id__in=[u.id for u in delegatees]) + if self.user: + qs = qs.exclude(id=self.user.id) + if self.delegatees: + qs = qs.exclude(id__in=[u.id for u in self.delegatees]) self.fields['existing_user'].queryset = qs.order_by('first_name', 'last_name') def clean(self): @@ -363,6 +363,19 @@ class DelegationForm(Form): 'exclusive.')) if not new and (ok1 or ok2 or ok3): raise ValidationError(_('To create a new user you must give a first name, a last name and a valid email')) + if new: + email = cleaned_data.get('email') + if email == self.user.email: + raise ValidationError(_('Email is yours, you cannot delegate to yourself')) + if any(delegate.email == email for delegate in self.delegatees): + raise ValidationError(_('A delegation with the same email already exists')) + qs = non_guest_users().filter(email=email) + if qs.exists(): + list_of_names = u', '.join([user.get_full_name() for user in qs]) + self.data = {} + self.is_bound = False + raise ValidationError(_('This email belong to existing user(s) {0}, look in the list of existing users') \ + .format(list_of_names)) return cleaned_data class Media: diff --git a/docbow_project/docbow/locale/fr/LC_MESSAGES/django.po b/docbow_project/docbow/locale/fr/LC_MESSAGES/django.po index c86fcfc..7b65956 100644 --- a/docbow_project/docbow/locale/fr/LC_MESSAGES/django.po +++ b/docbow_project/docbow/locale/fr/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: docbow 1.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-09-11 13:27+0200\n" -"PO-Revision-Date: 2013-09-11 17:36+0200\n" +"POT-Creation-Date: 2013-09-12 18:30+0200\n" +"PO-Revision-Date: 2013-09-12 18:30+0200\n" "Last-Translator: Benjamin Dauvergne \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -88,7 +88,7 @@ msgstr "" msgid "None" msgstr "" -#: admin.py:245 forms.py:333 templates/admin/object_history.html:26 +#: admin.py:245 forms.py:339 templates/admin/object_history.html:26 msgid "User" msgstr "Utilisateur" @@ -142,7 +142,7 @@ msgstr "Contacter un administrateur du système" msgid "Your delegation does not allow you to do this action" msgstr "Votre délégation ne vous permet pas d'accomplir cette action" -#: fields.py:69 forms.py:55 forms.py:109 models.py:260 +#: fields.py:69 forms.py:61 forms.py:115 models.py:260 msgid "Recipients" msgstr "Destinataire(s)" @@ -151,66 +151,66 @@ msgid "you must set at least one user recipient or one list recipient..." msgstr "" "Vous devez choisir au moins un utilisateur ou une liste destinataire..." -#: forms.py:56 models.py:190 +#: forms.py:62 models.py:190 msgid "Sender" msgstr "Expéditeur" -#: forms.py:63 +#: forms.py:69 msgid "forward the document" msgstr "Transférer le document" -#: forms.py:125 +#: forms.py:131 msgid "send a file" msgstr "Envoyer le document" -#: forms.py:164 models.py:221 models.py:239 +#: forms.py:170 models.py:221 models.py:239 msgid "Attached files" msgstr "Fichiers attaché(s)" -#: forms.py:207 +#: forms.py:213 #, python-format msgid "You must attach at most %d file(s)." msgstr "Vous devez attacher au plus %d fichier(s)." -#: forms.py:209 +#: forms.py:215 #, python-format msgid "You must attach at least %d file(s)." msgstr "Vous devez attacher au moins %d fichier(s)." -#: forms.py:214 +#: forms.py:220 msgid "" "The file name \"{file_name}\" does not match the patterns \"{extensions}\"." msgstr "" -#: forms.py:253 forms.py:278 +#: forms.py:259 forms.py:284 msgid "send your message" msgstr "Envoyer le message" -#: forms.py:260 +#: forms.py:266 msgid "Subject" msgstr "Sujet" -#: forms.py:263 +#: forms.py:269 msgid "Message" msgstr "Message" -#: forms.py:285 models.py:486 models.py:575 +#: forms.py:291 models.py:486 models.py:575 msgid "Name" msgstr "Nom" -#: forms.py:286 forms.py:332 +#: forms.py:292 forms.py:338 msgid "Email" msgstr "" -#: forms.py:287 +#: forms.py:293 msgid "Phone number" msgstr "Numéro de téléphone" -#: forms.py:304 +#: forms.py:310 msgid "Persons" msgstr "Personnes" -#: forms.py:318 +#: forms.py:324 msgid "" "

You can delegate to a newly created user, then all following fields are " "mandatory:

" @@ -218,24 +218,24 @@ msgstr "" "

Vous pouvez déléguer à un nouvel utilisateur que vous créez — tous les " "champs suivants sont obligatoires dans ce cas:

" -#: forms.py:320 +#: forms.py:326 msgid "

or you can delegate to an existing user:

" msgstr "

ou bien déléguer à un utilisateur existant:

" -#: forms.py:323 templates/docbow/delegate.html:57 +#: forms.py:329 templates/docbow/delegate.html:57 #: templates/docbow/full-profile.html:69 msgid "Create a new delegation" msgstr "Créer une nouvelle délégation" -#: forms.py:330 +#: forms.py:336 msgid "Firstname" msgstr "Prénom" -#: forms.py:331 +#: forms.py:337 msgid "Lastname" msgstr "Nom" -#: forms.py:355 +#: forms.py:361 msgid "" "You must choose between creating a new user or delegating to an existing " "one; the two are mutually exclusive." @@ -243,7 +243,7 @@ msgstr "" "Vous devez choisir entre déléguer à un nouvel utilisateur qui sera créé ou " "déléguer à un utilisateur existant, les deux choix s'excluant mutuellement." -#: forms.py:359 +#: forms.py:365 msgid "" "To create a new user you must give a first name, a last name and a valid " "email" @@ -251,13 +251,28 @@ msgstr "" "Pour créer un nouvel utilisateur vous devez donner un prénom, un nom et une " "adresse de courriel valide." -#: forms.py:376 +#: forms.py:369 +msgid "Email is yours, you cannot delegate to yourself" +msgstr "Ce courriel est à vous, vous ne pouvez pas déléguer à vous même" + +#: forms.py:371 +msgid "A delegation with the same email already exists" +msgstr "Une délégation à ce courriel existe déjà" + +#: forms.py:377 +msgid "" +"This email belong to existing user(s) {0}, look in the list of existing users" +msgstr "" +"Ce courriel appartient à/aux utilisateur(s) existant {0}, sélectionnez les " +"dans la liste des utilisateurs existant" + +#: forms.py:395 msgid "A forwarding rule must have at least one recipient, person or list." msgstr "" "Une règle de transfert doit contenir au moins un nouveau destinataire; une " "personne ou une liste." -#: forms.py:393 +#: forms.py:412 msgid "" "

If You would like to receive a SMS alert each time " "your inbox receives a document, provide your mobile phone number. If you do " @@ -268,15 +283,15 @@ msgstr "" "de téléphone. Si vous ne remplissez pas ce champ, vous ne recevrez pas de " "SMS.

" -#: forms.py:399 +#: forms.py:418 msgid "Clear SMS alert" msgstr "Supprimer l'alerte par SMS" -#: forms.py:400 +#: forms.py:419 msgid "Validate" msgstr "Valider" -#: forms.py:407 +#: forms.py:426 msgid "" "Use international phone number format, i.e +[country code][number]. A " "challenge SMS will be sent to you to validate it." @@ -286,15 +301,15 @@ msgstr "" "code vous sera envoyé et il vous faudra valider une deuxième fois votre " "numéro avec le code." -#: forms.py:433 +#: forms.py:457 msgid "Enter code received by SMS" msgstr "Entrez le code reçu par SMS" -#: forms.py:454 +#: forms.py:478 msgid "E-mail or identifier" msgstr "E-mail ou nom d'utilisateur" -#: forms.py:470 +#: forms.py:494 msgid "" "That e-mail address or identifier doesn't have an associated user account. " "Are you sure you've registered?" @@ -302,15 +317,15 @@ msgstr "" "Cette adresse email ou cet identifiant n'ont pas de compte utilisateur " "associé.Êtes-vous bien sûr d'être enregistré?" -#: forms.py:488 +#: forms.py:512 msgid "From" msgstr "De" -#: forms.py:489 templates/docbow/message.html:34 +#: forms.py:513 templates/docbow/message.html:34 msgid "To" msgstr "Destinataire(s)" -#: forms.py:504 +#: forms.py:528 msgid "From must be inferior or equal to To" msgstr "Le début de la période doit être inférieur ou égal à sa fin" @@ -742,7 +757,7 @@ msgstr "nom de fichier trop long, seulement %d caractères sont permis" msgid "too much file attached, delete to add a new one" msgstr "trop de fichiers attachés, supprimez en un pour en ajouter un autre" -#: views.py:171 +#: views.py:172 msgid "" "An internal error occured, administrators have been notified; sending seems " "blocked at the moment. You should try agrain later. If it still does not " @@ -753,26 +768,26 @@ msgstr "" "incitons à réessayer plus tard. Si cela ne fonctionne toujours pas, prenez " "contact avec les gestionnaires." -#: views.py:232 +#: views.py:233 msgid "back to inbox" msgstr "Retour aux documents reçus" -#: views.py:234 +#: views.py:235 msgid "back to outbox" msgstr "Retour aux documents envoyés" -#: views.py:248 +#: views.py:249 msgid "Document forwarded to {recipients_count} recipient." msgid_plural "Document forwarded to {recipients_count} recipients." msgstr[0] "Document tranféré à {recipients_count} destinataire." msgstr[1] "Document tranféré à {recipients_count} destinataires." -#: views.py:318 views.py:322 +#: views.py:319 views.py:323 #, python-format msgid "Message from %(name)s <%(email)s>" msgstr "Message de %(name)s <%(email)s>" -#: views.py:324 +#: views.py:325 #, python-format msgid "" "\n" @@ -781,17 +796,17 @@ msgstr "" "\n" "Numéro de téléphone: %s" -#: views.py:329 +#: views.py:330 #, python-format msgid "Your message was sent to %d administrators" msgstr "Votre message a été envoyé à %d administrateurs." -#: views.py:364 +#: views.py:365 #, python-format msgid "back to %s" msgstr "Retour à %s" -#: views.py:442 +#: views.py:443 msgid "Email with password reset instruction has been sent." msgstr "" "Un email avec les instructions pour la réinitialisation de votre mot de "