Commit 510d7ab3 authored by chirac's avatar chirac

Merge branch 'fix_room_display' into 'dev'

Fix room display, possibilité de desactiver le champ room sur register

See merge request federez/re2o!338
parents 5a868269 ae82289f
This diff is collapsed.
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-10-14 22:14
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0052_optionaluser_delete_notyetactive'),
]
operations = [
migrations.AddField(
model_name='optionaluser',
name='self_change_room',
field=models.BooleanField(default=False, help_text='Users can edit their room'),
),
]
......@@ -79,10 +79,7 @@ class OptionalUser(AclMixin, PreferencesModel):
default=False,
help_text=_("Users can create a member"),
)
self_adhesion = models.BooleanField(
default=False,
help_text=_("A new user can create their account on Re2o")
)
shell_default = models.OneToOneField(
'users.ListShell',
on_delete=models.PROTECT,
......@@ -93,6 +90,10 @@ class OptionalUser(AclMixin, PreferencesModel):
default=False,
help_text=_("Users can edit their shell")
)
self_change_room = models.BooleanField(
default=False,
help_text=_("Users can edit their room")
)
local_email_accounts_enabled = models.BooleanField(
default=False,
help_text=_("Enable local email accounts for users")
......@@ -111,6 +112,10 @@ class OptionalUser(AclMixin, PreferencesModel):
default=15,
help_text=_("Inactive users will be deleted after this number of days")
)
self_adhesion = models.BooleanField(
default=False,
help_text=_("A new user can create their account on Re2o")
)
class Meta:
permissions = (
......@@ -220,7 +225,7 @@ class OptionalTopologie(AclMixin, PreferencesModel):
switchs_web_management_ssl = models.BooleanField(
default=False,
help_text="Web management ssl. Assurez-vous que un certif est installé sur le switch !"
)
)
switchs_rest_management = models.BooleanField(
default=False,
help_text="Rest management, activé si provision auto"
......@@ -257,7 +262,7 @@ class OptionalTopologie(AclMixin, PreferencesModel):
from topologie.models import Switch
return Switch.objects.filter(automatic_provision=True)
@cached_property
@cached_property
def switchs_management_interface(self):
"""Return the ip of the interface that the switch have to contact to get it's config"""
if self.switchs_ip_type:
......@@ -266,7 +271,7 @@ class OptionalTopologie(AclMixin, PreferencesModel):
else:
return None
@cached_property
@cached_property
def switchs_management_interface_ip(self):
"""Same, but return the ipv4"""
if not self.switchs_management_interface:
......@@ -400,7 +405,7 @@ class Reminder(AclMixin, models.Model):
from re2o.utils import all_has_access
date = timezone.now().replace(minute=0,hour=0)
futur_date = date + timedelta(days=self.days)
users = all_has_access(futur_date).exclude(pk__in = all_has_access(futur_date + timedelta(days=1)))
users = all_has_access(futur_date).exclude(pk__in = all_has_access(futur_date + timedelta(days=1)))
return users
......
......@@ -36,33 +36,45 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<i class="fa fa-edit"></i>
{% trans "Edit" %}
</a>
<p>
</p>
<h5>{% trans "General preferences" %}</h5>
<table class="table table-striped">
<tr>
<th>{% trans "Telephone number required" %}</th>
<td>{{ useroptions.is_tel_mandatory|tick }}</td>
<th>{% trans "Creation of members by everyone" %}</th>
<td>{{ useroptions.all_can_create_adherent|tick }}</td>
<th>{% trans "Creation of clubs by everyone" %}</th>
<td>{{ useroptions.all_can_create_club|tick }}</td>
</tr>
<tr>
<th>{% trans "Self registration" %}</th>
<td>{{ useroptions.self_adhesion|tick }}</td>
<th>{% trans "Delete not yet active users after" %}</th>
<td>{{ useroptions.delete_notyetactive }} days</td>
</tr>
</table>
<h5>{% trans "Users general permissions" %}</h5>
<table class="table table-striped">
<tr>
<th>{% trans "Default shell for users" %}</th>
<td>{{ useroptions.shell_default }}</td>
<td>{{ useroptions.shell_default }}</td>
<th>{% trans "Users can edit their shell" %}</th>
<td>{{ useroptions.self_change_shell|tick }}</td>
</tr>
<tr>
<th>{% trans "Creation of members by everyone" %}</th>
<td>{{ useroptions.all_can_create_adherent|tick }}</td>
<th>{% trans "Creation of clubs by everyone" %}</th>
<td>{{ useroptions.all_can_create_club|tick }}</td>
<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>
</tr>
<tr>
<th>{% trans "GPG fingerprint field" %}</th>
<td>{{ useroptions.gpg_fingerprint|tick }}</td>
<th>{% trans "Delete not yet active users after" %}</th>
<td>{{ useroptions.delete_notyetactive }} days</td>
</tr>
</table>
<h5>{% trans "Email accounts preferences" %}
<h5>{% trans "Email accounts preferences" %}</h5>
<table class="table table-striped">
<tr>
<th>{% trans "Local email accounts enabled" %}</th>
......@@ -183,13 +195,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<h5>{% if topologieoptions.provisioned_switchs %}<span class="label label-success">Provision de la config des switchs{% else %}<span class="label label-danger">Provision de la config des switchs{% endif%}</span></h5>
<table class="table table-striped">
<tr>
<th>Switchs configurés automatiquement</th>
<td>{{ topologieoptions.provisioned_switchs|join:", " }}</td>
</tr>
</table>
<h4>{% trans "General preferences" %}</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'GeneralOption' %}">
<i class="fa fa-edit"></i>
......
......@@ -318,8 +318,9 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
self.fields['email'].label = _("Email address")
self.fields['school'].label = _("School")
self.fields['comment'].label = _("Comment")
self.fields['room'].label = _("Room")
self.fields['room'].empty_label = _("No room")
if 'room' in self.fields:
self.fields['room'].label = _("Room")
self.fields['room'].empty_label = _("No room")
self.fields['school'].empty_label = _("Select a school")
def clean_email(self):
......@@ -340,7 +341,7 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
'school',
'comment',
'telephone',
'room'
'room',
]
......@@ -428,8 +429,9 @@ class ClubForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
self.fields['surname'].label = _("Name")
self.fields['school'].label = _("School")
self.fields['comment'].label = _("Comment")
self.fields['room'].label = _("Room")
self.fields['room'].empty_label = _("No room")
if 'room' in self.fields:
self.fields['room'].label = _("Room")
self.fields['room'].empty_label = _("No room")
self.fields['school'].empty_label = _("Select a school")
self.fields['mailing'].label = _("Use a mailing list")
......
......@@ -845,6 +845,20 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
"""
return user_request == self, None
@staticmethod
def can_change_room(user_request, *_args, **_kwargs):
""" Check if a user can change a room
:param user_request: The user who request
:returns: a message and a boolean which is True if the user has
the right to change a state
"""
if not ((self.pk == user_request.pk and OptionalUser.get_cached_value('self_change_room'))
or user_request.has_perm('users.change_user')):
return False, _("Permission required to change the room.")
else:
return True, None
@staticmethod
def can_change_state(user_request, *_args, **_kwargs):
""" Check if a user can change a state
......@@ -993,6 +1007,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
'selfpasswd': self.check_selfpasswd,
'local_email_redirect': self.can_change_local_email_redirect,
'local_email_enabled': self.can_change_local_email_enabled,
'room': self.can_change_room,
}
self.__original_state = self.state
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment