Browse Source

Add option enabling regular users to take a disabled user's room

user_force_move_disabled_user_room
Jean-Romain Garnier 6 years ago
committed by chirac
parent
commit
ae7f1aaf38
  1. 8
      preferences/locale/fr/LC_MESSAGES/django.po
  2. 20
      preferences/migrations/0068_optionaluser_self_force_move_disabled_user_room.py
  3. 3
      preferences/models.py
  4. 6
      preferences/templates/preferences/display_preferences.html
  5. 23
      users/forms.py

8
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"

20
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.'),
),
]

3
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.")
)

6
preferences/templates/preferences/display_preferences.html

@ -147,10 +147,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<th>{% trans "Users can edit their room" %}</th>
<td>{{ useroptions.self_change_room|tick }}</td>
<th>{% trans "Telephone number required" %}</th>
<td>{{ useroptions.is_tel_mandatory|tick }}</td>
<th>{% trans "Users can select a room occupied by a user with a disabled connection" %}</th>
<td>{{ useroptions.self_force_move_disabled_user_room|tick }}</td>
</tr>
<tr>
<th>{% trans "Telephone number required" %}</th>
<td>{{ useroptions.is_tel_mandatory|tick }}</td>
<th>{% trans "GPG fingerprint field" %}</th>
<td>{{ useroptions.gpg_fingerprint|tick }}</td>
</tr>

23
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"

Loading…
Cancel
Save