From ae7f1aaf380665882575a8995c3f5f0044735492 Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Wed, 15 Apr 2020 19:55:35 +0200 Subject: [PATCH 1/5] Add option enabling regular users to take a disabled user's room --- preferences/locale/fr/LC_MESSAGES/django.po | 8 +++++++ ...user_self_force_move_disabled_user_room.py | 20 ++++++++++++++++ preferences/models.py | 3 +++ .../preferences/display_preferences.html | 6 +++-- users/forms.py | 23 +++++++++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 preferences/migrations/0068_optionaluser_self_force_move_disabled_user_room.py diff --git a/preferences/locale/fr/LC_MESSAGES/django.po b/preferences/locale/fr/LC_MESSAGES/django.po index 4c43a549..b64fd0a1 100644 --- a/preferences/locale/fr/LC_MESSAGES/django.po +++ b/preferences/locale/fr/LC_MESSAGES/django.po @@ -268,6 +268,10 @@ msgstr "Les utilisateurs peuvent créer un adhérent." msgid "Users can edit their shell." msgstr "Les utilisateurs peuvent modifier leur interface en ligne de commande." +#: preferences/models.py:92 +msgid "Users can select a room occupied by a user with a disabled connection." +msgstr "Les utilisateurs peuvent sélectionner la chambre d'un adhérent dont la connexion est désactivée." + #: preferences/models.py:90 msgid "Users can edit their room." msgstr "Les utilisateurs peuvent modifier leur chambre." @@ -1111,6 +1115,10 @@ msgstr "Les utilisateurs peuvent modifier leur interface en ligne de commande" msgid "Users can edit their room" msgstr "Les utilisateurs peuvent modifier leur chambre" +#: preferences/templates/preferences/display_preferences.html:144 +msgid "Users can select a room occupied by a user with a disabled connection" +msgstr "Les utilisateurs peuvent sélectionner la chambre d'un adhérent dont la connexion est désactivée" + #: preferences/templates/preferences/display_preferences.html:154 msgid "GPG fingerprint field" msgstr "Champ empreinte GPG" diff --git a/preferences/migrations/0068_optionaluser_self_force_move_disabled_user_room.py b/preferences/migrations/0068_optionaluser_self_force_move_disabled_user_room.py new file mode 100644 index 00000000..97588be6 --- /dev/null +++ b/preferences/migrations/0068_optionaluser_self_force_move_disabled_user_room.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.28 on 2020-04-15 16:35 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0067_auto_20191120_0159'), + ] + + operations = [ + migrations.AddField( + model_name='optionaluser', + name='self_force_move_disabled_user_room', + field=models.BooleanField(default=False, help_text='Users can select a room occupied by a user with a dissabled connection.'), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index e470303d..5773bcc3 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -89,6 +89,9 @@ class OptionalUser(AclMixin, PreferencesModel): self_change_room = models.BooleanField( default=False, help_text=_("Users can edit their room.") ) + self_force_move_disabled_user_room = models.BooleanField( + default=False, help_text=_("Users can select a room occupied by a user with a disabled connection.") + ) local_email_accounts_enabled = models.BooleanField( default=False, help_text=_("Enable local email accounts for users.") ) diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 8eb75918..057f7159 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -147,10 +147,12 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "Users can edit their room" %} {{ useroptions.self_change_room|tick }} - {% trans "Telephone number required" %} - {{ useroptions.is_tel_mandatory|tick }} + {% trans "Users can select a room occupied by a user with a disabled connection" %} + {{ useroptions.self_force_move_disabled_user_room|tick }} + {% trans "Telephone number required" %} + {{ useroptions.is_tel_mandatory|tick }} {% trans "GPG fingerprint field" %} {{ useroptions.gpg_fingerprint|tick }} diff --git a/users/forms.py b/users/forms.py index 8e60b698..369290aa 100644 --- a/users/forms.py +++ b/users/forms.py @@ -351,6 +351,29 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): label=_("Force the move?"), initial=False, required=False ) + def clean(self): + # Handle case where regular users can force move + can_force_move = OptionalUser.get_cached_value("self_force_move_disabled_user_room") + if not can_force_move: + return super(AdherentForm, self).clean() + + # Ensure the user entered a proper room + room = self.cleaned_data.get("room") + if not room: + return super(AdherentForm, self).clean() + + try: + # If a user already is register for this room + # but their connection has expired, allow force move + user = Adherent.objects.get(room=room) + if user and not user.is_connected(): + remove_user_room(room) + except Adherent.DoesNotExist: + pass + + # Run standard clean process + return super(AdherentForm, self).clean() + def clean_email(self): if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get( "email" From 86813b1a47e28b84d01aeb0707b58ca16f0f452b Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Wed, 15 Apr 2020 18:42:36 +0000 Subject: [PATCH 2/5] Forbid user from forcing out another user with a free access --- .../migrations/0069_auto_20200415_2012.py | 20 +++++++++++++++++++ users/forms.py | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 preferences/migrations/0069_auto_20200415_2012.py diff --git a/preferences/migrations/0069_auto_20200415_2012.py b/preferences/migrations/0069_auto_20200415_2012.py new file mode 100644 index 00000000..94690d0e --- /dev/null +++ b/preferences/migrations/0069_auto_20200415_2012.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.28 on 2020-04-15 18:12 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0068_optionaluser_self_force_move_disabled_user_room'), + ] + + operations = [ + migrations.AlterField( + model_name='optionaluser', + name='self_force_move_disabled_user_room', + field=models.BooleanField(default=False, help_text='Users can select a room occupied by a user with a disabled connection.'), + ), + ] diff --git a/users/forms.py b/users/forms.py index 369290aa..322c715e 100644 --- a/users/forms.py +++ b/users/forms.py @@ -366,7 +366,7 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): # If a user already is register for this room # but their connection has expired, allow force move user = Adherent.objects.get(room=room) - if user and not user.is_connected(): + if user and not user.has_access(): remove_user_room(room) except Adherent.DoesNotExist: pass From d1365e2c9ec7c512f4044dea753d1c1e2cdd20ec Mon Sep 17 00:00:00 2001 From: Jean-Romain Garnier Date: Wed, 15 Apr 2020 19:04:14 +0000 Subject: [PATCH 3/5] Make call to remove_user_room cleaner --- re2o/utils.py | 8 +++++--- users/forms.py | 38 +++++++++++++++----------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/re2o/utils.py b/re2o/utils.py index 348e5c55..7c49ff0a 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -203,11 +203,13 @@ def all_active_assigned_interfaces_count(): return all_active_interfaces_count().filter(ipv4__isnull=False) -def remove_user_room(room): +def remove_user_room(room, force=True): """ Déménage de force l'ancien locataire de la chambre """ try: user = Adherent.objects.get(room=room) except Adherent.DoesNotExist: return - user.room = None - user.save() + + if force or not user.has_access(): + user.room = None + user.save() diff --git a/users/forms.py b/users/forms.py index 322c715e..a020a427 100644 --- a/users/forms.py +++ b/users/forms.py @@ -351,29 +351,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): label=_("Force the move?"), initial=False, required=False ) - def clean(self): - # Handle case where regular users can force move - can_force_move = OptionalUser.get_cached_value("self_force_move_disabled_user_room") - if not can_force_move: - return super(AdherentForm, self).clean() - - # Ensure the user entered a proper room - room = self.cleaned_data.get("room") - if not room: - return super(AdherentForm, self).clean() - - try: - # If a user already is register for this room - # but their connection has expired, allow force move - user = Adherent.objects.get(room=room) - if user and not user.has_access(): - remove_user_room(room) - except Adherent.DoesNotExist: - pass - - # Run standard clean process - return super(AdherentForm, self).clean() - def clean_email(self): if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get( "email" @@ -402,6 +379,21 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): remove_user_room(room) return + def clean_room(self): + """On supprime l'ancien user de la chambre si l'option est activée, + et que l'ancien user a une connexion désactivée""" + # Handle case where regular users can force move + room = self.cleaned_data.get("room") + can_force_move = OptionalUser.get_cached_value("self_force_move_disabled_user_room") + if not can_force_move or not room: + return room + + # Remove the previous user's room, if allowed and necessary + remove_user_room(room, force=False) + + # Run standard clean process + return room + class AdherentCreationForm(AdherentForm): """Formulaire de création d'un user. From 41fb5e5c04f6609fdfade2d995a9448aeddc68dc Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 19 Apr 2020 03:16:55 +0200 Subject: [PATCH 4/5] Simplify preferences, add all_room acl for users --- preferences/locale/fr/LC_MESSAGES/django.po | 319 ++++++++++-------- ...user_self_force_move_disabled_user_room.py | 20 -- .../migrations/0069_auto_20200415_2012.py | 20 -- .../migrations/0070_auto_20200419_0225.py | 24 ++ preferences/models.py | 20 +- .../preferences/display_preferences.html | 10 +- users/forms.py | 6 +- users/models.py | 2 +- 8 files changed, 217 insertions(+), 204 deletions(-) delete mode 100644 preferences/migrations/0068_optionaluser_self_force_move_disabled_user_room.py delete mode 100644 preferences/migrations/0069_auto_20200415_2012.py create mode 100644 preferences/migrations/0070_auto_20200419_0225.py diff --git a/preferences/locale/fr/LC_MESSAGES/django.po b/preferences/locale/fr/LC_MESSAGES/django.po index b64fd0a1..d207afba 100644 --- a/preferences/locale/fr/LC_MESSAGES/django.po +++ b/preferences/locale/fr/LC_MESSAGES/django.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: 2.5\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-04-18 01:38+0200\n" +"POT-Creation-Date: 2020-04-19 03:09+0200\n" "PO-Revision-Date: 2018-06-24 15:54+0200\n" "Last-Translator: Laouen Fernet \n" "Language-Team: \n" @@ -35,7 +35,7 @@ msgid "You don't have the right to view this application." msgstr "Vous n'avez pas le droit de voir cette application." #: preferences/forms.py:65 -#: preferences/templates/preferences/display_preferences.html:150 +#: preferences/templates/preferences/display_preferences.html:148 msgid "Telephone number required" msgstr "Numéro de téléphone requis" @@ -256,46 +256,64 @@ msgstr "Modèles de document actuels" msgid "Current attributes" msgstr "Attributs actuels" -#: preferences/models.py:77 +#: preferences/models.py:78 +#, fuzzy +#| msgid "Users can edit their room" +msgid "Users can't select their room" +msgstr "Les utilisateurs peuvent modifier leur chambre" + +#: preferences/models.py:79 +#, fuzzy +#| msgid "" +#| "Users can select a room occupied by a user with a disabled connection." +msgid "" +"Users can only select a room occupied by a user with a disabled connection." +msgstr "" +"Les utilisateurs peuvent sélectionner la chambre d'un adhérent dont la " +"connexion est désactivée." + +#: preferences/models.py:80 +#, fuzzy +#| msgid "Users can edit their room" +msgid "Users can select all rooms" +msgstr "Les utilisateurs peuvent modifier leur chambre" + +#: preferences/models.py:86 msgid "Users can create a club." msgstr "Les utilisateurs peuvent créer un club." -#: preferences/models.py:80 +#: preferences/models.py:89 msgid "Users can create a member." msgstr "Les utilisateurs peuvent créer un adhérent." -#: preferences/models.py:87 +#: preferences/models.py:95 msgid "Users can edit their shell." msgstr "Les utilisateurs peuvent modifier leur interface en ligne de commande." -#: preferences/models.py:92 -msgid "Users can select a room occupied by a user with a disabled connection." -msgstr "Les utilisateurs peuvent sélectionner la chambre d'un adhérent dont la connexion est désactivée." +#: preferences/models.py:101 +msgid "Policy on self users room edition" +msgstr "Autorisation d'édtion du champ chambre par les utilisateurs" -#: preferences/models.py:90 -msgid "Users can edit their room." -msgstr "Les utilisateurs peuvent modifier leur chambre." - -#: preferences/models.py:93 +#: preferences/models.py:104 msgid "Enable local email accounts for users." msgstr "Activer les comptes mail locaux pour les utilisateurs." -#: preferences/models.py:98 +#: preferences/models.py:109 msgid "Domain to use for local email accounts." msgstr "Domaine à utiliser pour les comptes mail locaux." -#: preferences/models.py:102 +#: preferences/models.py:113 msgid "Maximum number of local email addresses for a standard user." msgstr "" "Nombre maximum d'adresses mail locales autorisé pour un utilisateur standard." -#: preferences/models.py:107 +#: preferences/models.py:118 msgid "Not yet active users will be deleted after this number of days." msgstr "" "Les utilisateurs n'ayant jamais adhéré seront supprimés après ce nombre de " "jours." -#: preferences/models.py:113 +#: preferences/models.py:124 msgid "" "Users with an email address not yet confirmed will be disabled after this " "number of days." @@ -303,11 +321,11 @@ msgstr "" "Les utilisateurs n'ayant pas confirmé leur addresse mail seront désactivés " "après ce nombre de jours" -#: preferences/models.py:117 +#: preferences/models.py:128 msgid "A new user can create their account on Re2o." msgstr "Un nouvel utilisateur peut créer son compte sur Re2o." -#: preferences/models.py:122 +#: preferences/models.py:133 msgid "" "If True, all new created and connected users are active. If False, only when " "a valid registration has been paid." @@ -315,7 +333,7 @@ msgstr "" "Si True, tous les nouveaux utilisations créés et connectés sont actifs. Si " "False, seulement quand une inscription validée a été payée." -#: preferences/models.py:129 +#: preferences/models.py:140 msgid "" "If True, users have the choice to receive an email containing a link to " "reset their password during creation, or to directly set their password in " @@ -326,172 +344,172 @@ msgstr "" "de choisir leur mot de passe immédiatement. Si False, un mail est toujours " "envoyé." -#: preferences/models.py:136 +#: preferences/models.py:147 msgid "If True, archived users are allowed to connect." msgstr "Si True, les utilisateurs archivés sont autorisés à se connecter." -#: preferences/models.py:140 +#: preferences/models.py:151 msgid "Can view the user preferences" msgstr "Peut voir les préférences d'utilisateur" -#: preferences/models.py:141 +#: preferences/models.py:152 msgid "user preferences" msgstr "Préférences d'utilisateur" -#: preferences/models.py:148 +#: preferences/models.py:159 msgid "Email domain must begin with @." msgstr "Un domaine mail doit commencer par @." -#: preferences/models.py:166 +#: preferences/models.py:177 msgid "Automatic configuration by RA" msgstr "Configuration automatique par RA" -#: preferences/models.py:167 +#: preferences/models.py:178 msgid "IP addresses assignment by DHCPv6" msgstr "Attribution d'adresses IP par DHCPv6" -#: preferences/models.py:168 +#: preferences/models.py:179 msgid "Disabled" msgstr "Désactivé" -#: preferences/models.py:177 +#: preferences/models.py:188 msgid "default Time To Live (TTL) for CNAME, A and AAAA records" msgstr "" "Temps de vie (TTL) par défault pour des enregistrements CNAME, A et AAAA" -#: preferences/models.py:187 +#: preferences/models.py:198 msgid "Can view the machine preferences" msgstr "Peut voir les préférences de machine" -#: preferences/models.py:188 +#: preferences/models.py:199 msgid "machine preferences" msgstr "Préférences de machine" -#: preferences/models.py:208 preferences/models.py:666 +#: preferences/models.py:219 preferences/models.py:677 msgid "On the IP range's VLAN of the machine" msgstr "Sur le VLAN de la plage d'IP de la machine" -#: preferences/models.py:209 preferences/models.py:667 +#: preferences/models.py:220 preferences/models.py:678 msgid "Preset in \"VLAN for machines accepted by RADIUS\"" msgstr "Prédéfinie dans « VLAN pour les machines acceptées par RADIUS »" -#: preferences/models.py:215 +#: preferences/models.py:226 msgid "Web management, activated in case of automatic provision." msgstr "Gestion web, activée en cas de provision automatique." -#: preferences/models.py:220 +#: preferences/models.py:231 msgid "" "SSL web management, make sure that a certificate is installed on the switch." msgstr "" "Gestion web SSL, vérifiez qu'un certificat est installé sur le commutateur " "réseau." -#: preferences/models.py:226 +#: preferences/models.py:237 msgid "REST management, activated in case of automatic provision." msgstr "Gestion REST, activée en cas de provision automatique." -#: preferences/models.py:233 +#: preferences/models.py:244 msgid "IP range for the management of switches." msgstr "Plage d'IP pour la gestion des commutateurs réseau." -#: preferences/models.py:239 +#: preferences/models.py:250 msgid "Provision of configuration mode for switches." msgstr "Mode de provision de configuration pour les commutateurs réseau." -#: preferences/models.py:242 +#: preferences/models.py:253 msgid "SFTP login for switches." msgstr "Identifiant SFTP pour les commutateurs réseau." -#: preferences/models.py:245 +#: preferences/models.py:256 msgid "SFTP password." msgstr "Mot de passe SFTP." -#: preferences/models.py:349 +#: preferences/models.py:360 msgid "Can view the topology preferences" msgstr "Peut voir les préférences de topologie" -#: preferences/models.py:350 +#: preferences/models.py:361 msgid "topology preferences" msgstr "préférences de topologie" -#: preferences/models.py:363 +#: preferences/models.py:374 msgid "RADIUS key." msgstr "Clé RADIUS." -#: preferences/models.py:365 +#: preferences/models.py:376 msgid "Comment for this key." msgstr "Commentaire pour cette clé." -#: preferences/models.py:368 +#: preferences/models.py:379 msgid "Default key for switches." msgstr "Clé par défaut pour les commutateurs réseau." -#: preferences/models.py:372 +#: preferences/models.py:383 msgid "Can view a RADIUS key object" msgstr "Peut voir un objet clé RADIUS" -#: preferences/models.py:373 preferences/views.py:331 +#: preferences/models.py:384 preferences/views.py:331 msgid "RADIUS key" msgstr "Clé RADIUS" -#: preferences/models.py:374 +#: preferences/models.py:385 #: preferences/templates/preferences/display_preferences.html:207 msgid "RADIUS keys" msgstr "clés RADIUS" -#: preferences/models.py:381 +#: preferences/models.py:392 msgid "Default RADIUS key for switches already exists." msgstr "Clé par défaut pour les commutateurs réseau." -#: preferences/models.py:384 +#: preferences/models.py:395 msgid "RADIUS key " msgstr "clé RADIUS " -#: preferences/models.py:390 +#: preferences/models.py:401 msgid "Switch login." msgstr "Identifiant du commutateur réseau." -#: preferences/models.py:391 +#: preferences/models.py:402 msgid "Password." msgstr "Mot de passe." -#: preferences/models.py:393 +#: preferences/models.py:404 msgid "Default credentials for switches." msgstr "Identifiants par défaut pour les commutateurs réseau." -#: preferences/models.py:400 +#: preferences/models.py:411 msgid "Can view a switch management credentials object" msgstr "Peut voir un objet identifiants de gestion de commutateur réseau" -#: preferences/models.py:403 preferences/views.py:394 +#: preferences/models.py:414 preferences/views.py:394 msgid "switch management credentials" msgstr "identifiants de gestion de commutateur réseau" -#: preferences/models.py:406 +#: preferences/models.py:417 msgid "Switch login " msgstr "Identifiant du commutateur réseau " -#: preferences/models.py:418 +#: preferences/models.py:429 msgid "Delay between the email and the membership's end." msgstr "Délai entre le mail et la fin d'adhésion." -#: preferences/models.py:424 +#: preferences/models.py:435 msgid "Message displayed specifically for this reminder." msgstr "Message affiché spécifiquement pour ce rappel." -#: preferences/models.py:428 +#: preferences/models.py:439 msgid "Can view a reminder object" msgstr "Peut voir un objet rappel" -#: preferences/models.py:429 preferences/views.py:276 +#: preferences/models.py:440 preferences/views.py:276 msgid "reminder" msgstr "rappel" -#: preferences/models.py:430 +#: preferences/models.py:441 msgid "reminders" msgstr "rappels" -#: preferences/models.py:451 +#: preferences/models.py:462 msgid "" "General message displayed on the French version of the website (e.g. in case " "of maintenance)." @@ -499,7 +517,7 @@ msgstr "" "Message général affiché sur la version française du site (ex : en cas de " "maintenance)." -#: preferences/models.py:459 +#: preferences/models.py:470 msgid "" "General message displayed on the English version of the website (e.g. in " "case of maintenance)." @@ -507,75 +525,75 @@ msgstr "" "Message général affiché sur la version anglaise du site (ex : en cas de " "maintenance)." -#: preferences/models.py:474 +#: preferences/models.py:485 msgid "Can view the general preferences" msgstr "Peut voir les préférences générales" -#: preferences/models.py:475 +#: preferences/models.py:486 msgid "general preferences" msgstr "préférences générales" -#: preferences/models.py:495 +#: preferences/models.py:506 msgid "Can view the service preferences" msgstr "Peut voir les préférences de service" -#: preferences/models.py:496 preferences/views.py:227 +#: preferences/models.py:507 preferences/views.py:227 msgid "service" msgstr "service" -#: preferences/models.py:497 +#: preferences/models.py:508 msgid "services" msgstr "services" -#: preferences/models.py:507 +#: preferences/models.py:518 msgid "Contact email address." msgstr "Adresse mail de contact." -#: preferences/models.py:513 +#: preferences/models.py:524 msgid "Description of the associated email address." msgstr "Description de l'adresse mail associée." -#: preferences/models.py:523 +#: preferences/models.py:534 msgid "Can view a contact email address object" msgstr "Peut voir un objet adresse mail de contact" -#: preferences/models.py:525 +#: preferences/models.py:536 msgid "contact email address" msgstr "adresse mail de contact" -#: preferences/models.py:526 +#: preferences/models.py:537 msgid "contact email addresses" msgstr "adresses mail de contact" -#: preferences/models.py:534 preferences/views.py:634 +#: preferences/models.py:545 preferences/views.py:634 msgid "mandate" msgstr "mandat" -#: preferences/models.py:535 +#: preferences/models.py:546 msgid "mandates" msgstr "mandats" -#: preferences/models.py:536 +#: preferences/models.py:547 msgid "Can view a mandate object" msgstr "Peut voir un objet mandat" -#: preferences/models.py:543 +#: preferences/models.py:554 msgid "president of the association" msgstr "président de l'association" -#: preferences/models.py:544 +#: preferences/models.py:555 msgid "Displayed on subscription vouchers." msgstr "Affiché sur les reçus de cotisation." -#: preferences/models.py:546 +#: preferences/models.py:557 msgid "start date" msgstr "date de début" -#: preferences/models.py:547 +#: preferences/models.py:558 msgid "end date" msgstr "date de fin" -#: preferences/models.py:560 +#: preferences/models.py:571 msgid "" "No mandates have been created. Please go to the preferences page to create " "one." @@ -583,140 +601,140 @@ msgstr "" "Aucun mandat n'a été créé. Veuillez vous rendre sur la page de préférences " "pour en créer un." -#: preferences/models.py:575 +#: preferences/models.py:586 msgid "Networking organisation school Something" msgstr "Association de réseau de l'école Machin" -#: preferences/models.py:578 +#: preferences/models.py:589 msgid "Threadneedle Street" msgstr "1 rue de la Vrillière" -#: preferences/models.py:579 +#: preferences/models.py:590 msgid "London EC2R 8AH" msgstr "75001 Paris" -#: preferences/models.py:582 +#: preferences/models.py:593 msgid "Organisation" msgstr "Association" -#: preferences/models.py:589 +#: preferences/models.py:600 msgid "Can view the organisation preferences" msgstr "Peut voir les préférences d'association" -#: preferences/models.py:590 +#: preferences/models.py:601 msgid "organisation preferences" msgstr "préférences d'association" -#: preferences/models.py:608 +#: preferences/models.py:619 msgid "Can view the homepage preferences" msgstr "Peut voir les préférences de page d'accueil" -#: preferences/models.py:609 +#: preferences/models.py:620 msgid "homepage preferences" msgstr "Préférences de page d'accueil" -#: preferences/models.py:623 +#: preferences/models.py:634 msgid "Welcome email in French." msgstr "Mail de bienvenue en français." -#: preferences/models.py:626 +#: preferences/models.py:637 msgid "Welcome email in English." msgstr "Mail de bienvenue en anglais." -#: preferences/models.py:631 +#: preferences/models.py:642 msgid "Can view the email message preferences" msgstr "Peut voir les préférences de message pour les mails" -#: preferences/models.py:633 +#: preferences/models.py:644 msgid "email message preferences" msgstr "préférences de messages pour les mails" -#: preferences/models.py:638 +#: preferences/models.py:649 msgid "RADIUS attribute" msgstr "attribut RADIUS" -#: preferences/models.py:639 +#: preferences/models.py:650 msgid "RADIUS attributes" msgstr "attributs RADIUS" -#: preferences/models.py:643 preferences/views.py:587 +#: preferences/models.py:654 preferences/views.py:587 msgid "attribute" msgstr "attribut" -#: preferences/models.py:644 +#: preferences/models.py:655 msgid "See https://freeradius.org/rfc/attributes.html." msgstr "Voir https://freeradius.org/rfc/attributes.html." -#: preferences/models.py:646 +#: preferences/models.py:657 msgid "value" msgstr "valeur" -#: preferences/models.py:648 +#: preferences/models.py:659 msgid "comment" msgstr "commentaire" -#: preferences/models.py:649 +#: preferences/models.py:660 msgid "Use this field to document this attribute." msgstr "Utilisez ce champ pour documenter cet attribut." -#: preferences/models.py:660 +#: preferences/models.py:671 msgid "RADIUS policy" msgstr "politique de RADIUS" -#: preferences/models.py:661 +#: preferences/models.py:672 #: preferences/templates/preferences/display_preferences.html:285 msgid "RADIUS policies" msgstr "politiques de RADIUS" -#: preferences/models.py:672 +#: preferences/models.py:683 msgid "Reject the machine" msgstr "Rejeter la machine" -#: preferences/models.py:673 +#: preferences/models.py:684 msgid "Place the machine on the VLAN" msgstr "Placer la machine sur le VLAN" -#: preferences/models.py:682 +#: preferences/models.py:693 msgid "policy for unknown machines" msgstr "politique pour les machines inconnues" -#: preferences/models.py:690 +#: preferences/models.py:701 msgid "unknown machines VLAN" msgstr "VLAN pour les machines inconnues" -#: preferences/models.py:691 +#: preferences/models.py:702 msgid "VLAN for unknown machines if not rejected." msgstr "VLAN pour les machines inconnues si non rejeté." -#: preferences/models.py:697 +#: preferences/models.py:708 msgid "unknown machines attributes" msgstr "attributs pour les machines inconnues" -#: preferences/models.py:698 +#: preferences/models.py:709 msgid "Answer attributes for unknown machines." msgstr "Attributs de réponse pour les machines inconnues." -#: preferences/models.py:704 +#: preferences/models.py:715 msgid "policy for unknown ports" msgstr "politique pour les ports inconnus" -#: preferences/models.py:712 +#: preferences/models.py:723 msgid "unknown ports VLAN" msgstr "VLAN pour les ports inconnus" -#: preferences/models.py:713 +#: preferences/models.py:724 msgid "VLAN for unknown ports if not rejected." msgstr "VLAN pour les ports inconnus si non rejeté." -#: preferences/models.py:719 +#: preferences/models.py:730 msgid "unknown ports attributes" msgstr "attributs pour les ports inconnus" -#: preferences/models.py:720 +#: preferences/models.py:731 msgid "Answer attributes for unknown ports." msgstr "Attributs de réponse pour les ports inconnus." -#: preferences/models.py:727 +#: preferences/models.py:738 msgid "" "Policy for machines connecting from unregistered rooms (relevant on ports " "with STRICT RADIUS mode)" @@ -724,87 +742,87 @@ msgstr "" "Politique pour les machines se connectant depuis des chambre non " "enregistrées (pertinent pour les ports avec le mode de RADIUS STRICT)" -#: preferences/models.py:737 +#: preferences/models.py:748 msgid "unknown rooms VLAN" msgstr "VLAN pour les chambres inconnues" -#: preferences/models.py:738 +#: preferences/models.py:749 msgid "VLAN for unknown rooms if not rejected." msgstr "VLAN pour les chambres inconnues si non rejeté." -#: preferences/models.py:744 +#: preferences/models.py:755 msgid "unknown rooms attributes" msgstr "attributs pour les chambres inconnues" -#: preferences/models.py:745 +#: preferences/models.py:756 msgid "Answer attributes for unknown rooms." msgstr "Attributs de réponse pour les chambres inconnues." -#: preferences/models.py:751 +#: preferences/models.py:762 msgid "policy for non members" msgstr "politique pour les non adhérents" -#: preferences/models.py:759 +#: preferences/models.py:770 msgid "non members VLAN" msgstr "VLAN pour les non adhérents" -#: preferences/models.py:760 +#: preferences/models.py:771 msgid "VLAN for non members if not rejected." msgstr "VLAN pour les non adhérents si non rejeté." -#: preferences/models.py:766 +#: preferences/models.py:777 msgid "non members attributes" msgstr "attributs pour les non adhérents" -#: preferences/models.py:767 +#: preferences/models.py:778 msgid "Answer attributes for non members." msgstr "Attributs de réponse pour les non adhérents." -#: preferences/models.py:773 +#: preferences/models.py:784 msgid "policy for banned users" msgstr "politique pour les utilisateurs bannis" -#: preferences/models.py:781 +#: preferences/models.py:792 msgid "banned users VLAN" msgstr "VLAN pour les utilisateurs bannis" -#: preferences/models.py:782 +#: preferences/models.py:793 msgid "VLAN for banned users if not rejected." msgstr "VLAN pour les utilisateurs bannis si non rejeté." -#: preferences/models.py:788 +#: preferences/models.py:799 msgid "banned users attributes" msgstr "attributs pour les utilisateurs bannis" -#: preferences/models.py:789 +#: preferences/models.py:800 msgid "Answer attributes for banned users." msgstr "Attributs de réponse pour les utilisateurs bannis." -#: preferences/models.py:802 +#: preferences/models.py:813 msgid "accepted users attributes" msgstr "attributs pour les utilisateurs acceptés" -#: preferences/models.py:803 +#: preferences/models.py:814 msgid "Answer attributes for accepted users." msgstr "Attributs de réponse pour les utilisateurs acceptés." -#: preferences/models.py:830 +#: preferences/models.py:841 msgid "subscription preferences" msgstr "préférences de cotisation" -#: preferences/models.py:834 +#: preferences/models.py:845 msgid "template for invoices" msgstr "modèle pour les factures" -#: preferences/models.py:841 +#: preferences/models.py:852 msgid "template for subscription vouchers" msgstr "modèle pour les reçus de cotisation" -#: preferences/models.py:847 +#: preferences/models.py:858 msgid "send voucher by email when the invoice is controlled" msgstr "envoyer le reçu par mail quand la facture est contrôlée" -#: preferences/models.py:849 +#: preferences/models.py:860 msgid "" "Be careful, if no mandate is defined on the preferences page, errors will be " "triggered when generating vouchers." @@ -812,19 +830,19 @@ msgstr "" "Faites attention, si aucun mandat n'est défini sur la page de préférences, " "des erreurs seront déclenchées en générant des reçus." -#: preferences/models.py:861 +#: preferences/models.py:872 msgid "template" msgstr "modèle" -#: preferences/models.py:862 +#: preferences/models.py:873 msgid "name" msgstr "nom" -#: preferences/models.py:865 +#: preferences/models.py:876 msgid "document template" msgstr "modèle de document" -#: preferences/models.py:866 +#: preferences/models.py:877 msgid "document templates" msgstr "modèles de document" @@ -1111,18 +1129,14 @@ msgstr "Interface en ligne de commande par défaut pour les utilisateurs" msgid "Users can edit their shell" msgstr "Les utilisateurs peuvent modifier leur interface en ligne de commande" -#: preferences/templates/preferences/display_preferences.html:148 -msgid "Users can edit their room" -msgstr "Les utilisateurs peuvent modifier leur chambre" - -#: preferences/templates/preferences/display_preferences.html:144 -msgid "Users can select a room occupied by a user with a disabled connection" -msgstr "Les utilisateurs peuvent sélectionner la chambre d'un adhérent dont la connexion est désactivée" - -#: preferences/templates/preferences/display_preferences.html:154 +#: preferences/templates/preferences/display_preferences.html:150 msgid "GPG fingerprint field" msgstr "Champ empreinte GPG" +#: preferences/templates/preferences/display_preferences.html:154 +msgid "Policy for self-user room change" +msgstr "Autorisations pour le changement de chambre des utilisateurs" + #: preferences/templates/preferences/display_preferences.html:165 msgid "Machine preferences" msgstr "Préférences de machine" @@ -1485,3 +1499,12 @@ msgstr "Le mandat a été modifié." #: preferences/views.py:631 msgid "The mandate was deleted." msgstr "Le mandat été supprimé." + +#~ msgid "Users can edit their room." +#~ msgstr "Les utilisateurs peuvent modifier leur chambre." + +#~ msgid "" +#~ "Users can select a room occupied by a user with a disabled connection" +#~ msgstr "" +#~ "Les utilisateurs peuvent sélectionner la chambre d'un adhérent dont la " +#~ "connexion est désactivée" diff --git a/preferences/migrations/0068_optionaluser_self_force_move_disabled_user_room.py b/preferences/migrations/0068_optionaluser_self_force_move_disabled_user_room.py deleted file mode 100644 index 97588be6..00000000 --- a/preferences/migrations/0068_optionaluser_self_force_move_disabled_user_room.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.28 on 2020-04-15 16:35 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('preferences', '0067_auto_20191120_0159'), - ] - - operations = [ - migrations.AddField( - model_name='optionaluser', - name='self_force_move_disabled_user_room', - field=models.BooleanField(default=False, help_text='Users can select a room occupied by a user with a dissabled connection.'), - ), - ] diff --git a/preferences/migrations/0069_auto_20200415_2012.py b/preferences/migrations/0069_auto_20200415_2012.py deleted file mode 100644 index 94690d0e..00000000 --- a/preferences/migrations/0069_auto_20200415_2012.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.28 on 2020-04-15 18:12 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('preferences', '0068_optionaluser_self_force_move_disabled_user_room'), - ] - - operations = [ - migrations.AlterField( - model_name='optionaluser', - name='self_force_move_disabled_user_room', - field=models.BooleanField(default=False, help_text='Users can select a room occupied by a user with a disabled connection.'), - ), - ] diff --git a/preferences/migrations/0070_auto_20200419_0225.py b/preferences/migrations/0070_auto_20200419_0225.py new file mode 100644 index 00000000..6dd70fa4 --- /dev/null +++ b/preferences/migrations/0070_auto_20200419_0225.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.28 on 2020-04-19 00:25 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0069_optionaluser_disable_emailnotyetconfirmed'), + ] + + operations = [ + migrations.RemoveField( + model_name='optionaluser', + name='self_change_room', + ), + migrations.AddField( + model_name='optionaluser', + name='self_room_policy', + field=models.CharField(choices=[('DISABLED', "Users can't select their room"), ('ONLY_INACTIVE', 'Users can only select a room occupied by a user with a disabled connection.'), ('ALL_ROOM', 'Users can select all rooms')], default='DISABLED', help_text='Policy on self users room edition', max_length=32), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index 5773bcc3..66a72f46 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -71,6 +71,15 @@ class OptionalUser(AclMixin, PreferencesModel): """Options pour l'user : obligation ou nom du telephone, activation ou non du solde, autorisation du negatif, fingerprint etc""" + DISABLED = "DISABLED" + ONLY_INACTIVE = "ONLY_INACTIVE" + ALL_ROOM = "ALL_ROOM" + ROOM_POLICY = ( + (DISABLED, _("Users can't select their room")), + (ONLY_INACTIVE, _("Users can only select a room occupied by a user with a disabled connection.")), + (ALL_ROOM, _("Users can select all rooms")), + ) + is_tel_mandatory = models.BooleanField(default=True) gpg_fingerprint = models.BooleanField(default=True) all_can_create_club = models.BooleanField( @@ -79,18 +88,17 @@ class OptionalUser(AclMixin, PreferencesModel): all_can_create_adherent = models.BooleanField( default=False, help_text=_("Users can create a member.") ) - shell_default = models.OneToOneField( "users.ListShell", on_delete=models.PROTECT, blank=True, null=True ) self_change_shell = models.BooleanField( default=False, help_text=_("Users can edit their shell.") ) - self_change_room = models.BooleanField( - default=False, help_text=_("Users can edit their room.") - ) - self_force_move_disabled_user_room = models.BooleanField( - default=False, help_text=_("Users can select a room occupied by a user with a disabled connection.") + self_room_policy = models.CharField( + max_length=32, + choices=ROOM_POLICY, + default="DISABLED", + help_text=_("Policy on self users room edition") ) local_email_accounts_enabled = models.BooleanField( default=False, help_text=_("Enable local email accounts for users.") diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 057f7159..2142eb68 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -144,18 +144,16 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "Users can edit their shell" %} {{ useroptions.self_change_shell|tick }} - - {% trans "Users can edit their room" %} - {{ useroptions.self_change_room|tick }} - {% trans "Users can select a room occupied by a user with a disabled connection" %} - {{ useroptions.self_force_move_disabled_user_room|tick }} - {% trans "Telephone number required" %} {{ useroptions.is_tel_mandatory|tick }} {% trans "GPG fingerprint field" %} {{ useroptions.gpg_fingerprint|tick }} + + {% trans "Policy for self-user room change" %} + {{ useroptions.self_room_policy }} + diff --git a/users/forms.py b/users/forms.py index a020a427..e4f39f10 100644 --- a/users/forms.py +++ b/users/forms.py @@ -384,12 +384,12 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm): et que l'ancien user a une connexion désactivée""" # Handle case where regular users can force move room = self.cleaned_data.get("room") - can_force_move = OptionalUser.get_cached_value("self_force_move_disabled_user_room") - if not can_force_move or not room: + room_policy = OptionalUser.get_cached_value("self_room_policy") + if room_policy == OptionalUser.DISABLED or not room: return room # Remove the previous user's room, if allowed and necessary - remove_user_room(room, force=False) + remove_user_room(room, force=bool(room_policy == OptionalUser.ALL_ROOM)) # Run standard clean process return room diff --git a/users/models.py b/users/models.py index 621617c3..6b260170 100755 --- a/users/models.py +++ b/users/models.py @@ -1110,7 +1110,7 @@ class User( if not ( ( self.pk == user_request.pk - and OptionalUser.get_cached_value("self_change_room") + and OptionalUser.get_cached_value("self_room_policy") != OptionalUser.DISABLED ) or user_request.has_perm("users.change_user") ): From cd9e13b195962a1efb26dd0c8a9b71e95b74e624 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sun, 19 Apr 2020 15:15:27 +0200 Subject: [PATCH 5/5] Fix trads --- preferences/locale/fr/LC_MESSAGES/django.po | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/preferences/locale/fr/LC_MESSAGES/django.po b/preferences/locale/fr/LC_MESSAGES/django.po index d207afba..37c85224 100644 --- a/preferences/locale/fr/LC_MESSAGES/django.po +++ b/preferences/locale/fr/LC_MESSAGES/django.po @@ -257,15 +257,10 @@ msgid "Current attributes" msgstr "Attributs actuels" #: preferences/models.py:78 -#, fuzzy -#| msgid "Users can edit their room" msgid "Users can't select their room" -msgstr "Les utilisateurs peuvent modifier leur chambre" +msgstr "Les utilisateurs ne peuvent pas modifier leur chambre" #: preferences/models.py:79 -#, fuzzy -#| msgid "" -#| "Users can select a room occupied by a user with a disabled connection." msgid "" "Users can only select a room occupied by a user with a disabled connection." msgstr "" @@ -273,10 +268,8 @@ msgstr "" "connexion est désactivée." #: preferences/models.py:80 -#, fuzzy -#| msgid "Users can edit their room" msgid "Users can select all rooms" -msgstr "Les utilisateurs peuvent modifier leur chambre" +msgstr "Les utilisateurs peuvent choisir toutes les chambres" #: preferences/models.py:86 msgid "Users can create a club."