8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-09 03:16:25 +00:00

Merge branch 'self_pseudo_change' into 'dev'

Add self pseudo setting

See merge request re2o/re2o!515
This commit is contained in:
Jean-Romain Garnier 2020-04-23 14:57:43 +02:00
commit 856664b66b
7 changed files with 432 additions and 314 deletions

View file

@ -66,10 +66,19 @@ class EditOptionalUserForm(ModelForm):
self.fields["gpg_fingerprint"].label = _("GPG fingerprint")
self.fields["all_can_create_club"].label = _("All can create a club")
self.fields["all_can_create_adherent"].label = _("All can create a member")
self.fields["disable_emailnotyetconfirmed"].label = _("Delay before disabling accounts without a verified email")
self.fields["self_adhesion"].label = _("Self registration")
self.fields["shell_default"].label = _("Default shell")
self.fields["allow_set_password_during_user_creation"].label = _("Allow directly setting a password during account creation")
self.fields["self_change_shell"].label = _("Self change shell")
self.fields["self_change_pseudo"].label = _("Self change pseudo")
self.fields["self_room_policy"].label = _("Self room policy")
self.fields["local_email_accounts_enabled"].label = _("Local email accounts enabled")
self.fields["local_email_domain"].label = _("Local email domain")
self.fields["max_email_address"].label = _("Max local email address")
self.fields["delete_notyetactive"].label = _("Delete not yet active users")
self.fields["disable_emailnotyetconfirmed"].label = _("Disabled email not yet confirmed")
self.fields["self_adhesion"].label = _("Self registration")
self.fields["all_users_active"].label = _("All users are state active by default")
self.fields["allow_set_password_during_user_creation"].label = _("Allow set password during user creation")
self.fields["allow_archived_connexion"].label = _("Allow archived connexion")
class EditOptionalMachineForm(ModelForm):

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.28 on 2020-04-23 09:01
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0070_auto_20200419_0225'),
]
operations = [
migrations.AddField(
model_name='optionaluser',
name='self_change_pseudo',
field=models.BooleanField(default=True, help_text='Users can edit their pseudo.'),
),
]

View file

@ -99,6 +99,9 @@ class OptionalUser(AclMixin, PreferencesModel):
self_change_shell = models.BooleanField(
default=False, help_text=_("Users can edit their shell.")
)
self_change_pseudo = models.BooleanField(
default=True, help_text=_("Users can edit their pseudo.")
)
self_room_policy = models.CharField(
max_length=32,
choices=ROOM_POLICY,

View file

@ -154,6 +154,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<th>{% trans "Policy for self-user room change" %}</th>
<td>{{ useroptions.self_room_policy }}</td>
<th>{% trans "Users can edit their pseudo" %}</th>
<td>{{ useroptions.self_change_pseudo|tick }}</td>
</tr>
</table>
<h4 id="users">{% trans "Local email accounts settings" %}</h4>

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.28 on 2020-04-23 10:56
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('users', '0090_auto_20200421_1825'),
]
operations = [
migrations.AlterModelOptions(
name='user',
options={'permissions': (('change_user_password', 'Can change the password of a user'), ('change_user_state', 'Can edit the state of a user'), ('change_user_force', 'Can force the move'), ('change_user_shell', 'Can edit the shell of a user'), ('change_user_pseudo', 'Can edit the pseudo of a user'), ('change_user_groups', 'Can edit the groups of rights of a user (critical permission)'), ('change_all_users', 'Can edit all users, including those with rights'), ('view_user', 'Can view a user object')), 'verbose_name': 'user (member or club)', 'verbose_name_plural': 'users (members or clubs)'},
),
]

View file

@ -252,6 +252,7 @@ class User(
("change_user_state", _("Can edit the state of a user")),
("change_user_force", _("Can force the move")),
("change_user_shell", _("Can edit the shell of a user")),
("change_user_pseudo", _("Can edit the pseudo of a user")),
(
"change_user_groups",
_("Can edit the groups of rights of a user (critical permission)"),
@ -1168,6 +1169,28 @@ class User(
else:
return True, None, None
def can_change_pseudo(self, user_request, *_args, **_kwargs):
""" Check if a user can change a pseudo
: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 shell
"""
if not (
(
self.pk == user_request.pk
and OptionalUser.get_cached_value("self_change_pseudo")
)
or user_request.has_perm("users.change_user_pseudo")
):
return (
False,
_("You don't have the right to change the pseudo."),
("users.change_user_pseudo",),
)
else:
return True, None, None
@staticmethod
def can_change_local_email_redirect(user_request, *_args, **_kwargs):
""" Check if a user can change local_email_redirect.
@ -1314,6 +1337,7 @@ class User(
super(User, self).__init__(*args, **kwargs)
self.field_permissions = {
"shell": self.can_change_shell,
"pseudo": self.can_change_pseudo,
"force": self.can_change_force,
"selfpasswd": self.check_selfpasswd,
"local_email_redirect": self.can_change_local_email_redirect,