From ba31a94c20bdfd11e92d90befec05b14fdd275cd Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Mon, 13 Aug 2018 19:36:57 +0200 Subject: [PATCH 1/2] users can change their shell --- .../0049_optionaluser_self_change_shell.py | 20 +++++++++++++++++++ preferences/models.py | 4 ++++ .../preferences/display_preferences.html | 9 +++++++-- users/models.py | 12 +++++------ 4 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 preferences/migrations/0049_optionaluser_self_change_shell.py diff --git a/preferences/migrations/0049_optionaluser_self_change_shell.py b/preferences/migrations/0049_optionaluser_self_change_shell.py new file mode 100644 index 00000000..161792eb --- /dev/null +++ b/preferences/migrations/0049_optionaluser_self_change_shell.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-08-13 17:18 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0048_auto_20180811_1515'), + ] + + operations = [ + migrations.AddField( + model_name='optionaluser', + name='self_change_shell', + field=models.BooleanField(default=False, help_text='Users can change their shell'), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index ed4cd1e0..0ebb2fec 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -85,6 +85,10 @@ class OptionalUser(AclMixin, PreferencesModel): blank=True, null=True ) + self_change_shell = models.BooleanField( + default=False, + help_text="Users can change their shell" + ) 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 2e34db5a..a7ada02b 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -45,10 +45,11 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ useroptions.self_adhesion|tick }} - Champ gpg fingerprint - {{ useroptions.gpg_fingerprint|tick }} + Shell par défaut des utilisateurs {{ useroptions.shell_default }} + Les utilisateurs peuvent changer leur shell + {{ useroptions.self_change_shell|tick }} Creations d'adhérents par tous @@ -56,6 +57,10 @@ with this program; if not, write to the Free Software Foundation, Inc., Creations de clubs par tous {{ useroptions.all_can_create_club|tick }} + + Champ gpg fingerprint + {{ useroptions.gpg_fingerprint|tick }} +
Comptes mails
diff --git a/users/models.py b/users/models.py index 0fe2cd62..12f3cf1c 100755 --- a/users/models.py +++ b/users/models.py @@ -832,18 +832,18 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, "Droit requis pour changer l'état" ) - @staticmethod - def can_change_shell(user_request, *_args, **_kwargs): + def can_change_shell(self, user_request, *_args, **_kwargs): """ Check if a user can change a shell :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 """ - return ( - user_request.has_perm('users.change_user_shell'), - "Droit requis pour changer le shell" - ) + if not ((self == user_request and OptionalUser.get_cached_value('self_change_shell')) + or user_request.has_perm('users.change_user_shell')): + return False, u"Droit requis pour changer le shell" + else: + return True, None @staticmethod def can_change_local_email_redirect(user_request, *_args, **_kwargs): From 1e47fa16a05e1a2b7af43b1490ff3b787555e6cf Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Wed, 15 Aug 2018 23:14:30 +0200 Subject: [PATCH 2/2] Rend can_change_shell de User cast-proof --- users/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/users/models.py b/users/models.py index 12f3cf1c..bceb84bb 100755 --- a/users/models.py +++ b/users/models.py @@ -839,7 +839,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, :returns: a message and a boolean which is True if the user has the right to change a shell """ - if not ((self == user_request and OptionalUser.get_cached_value('self_change_shell')) + if not ((self.pk == user_request.pk and OptionalUser.get_cached_value('self_change_shell')) or user_request.has_perm('users.change_user_shell')): return False, u"Droit requis pour changer le shell" else: