From 51c5fc812690cf416645164bbeebf5d024dcadf2 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 24 Mar 2018 21:19:52 +0100 Subject: [PATCH] Defini un shell par defaut --- .../migrations/0031_auto_20180323_0218.py | 20 +++++++++++++++++ .../0032_optionaluser_shell_default.py | 22 +++++++++++++++++++ preferences/models.py | 6 +++++ .../preferences/display_preferences.html | 4 +++- users/models.py | 10 +++++++-- 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 preferences/migrations/0031_auto_20180323_0218.py create mode 100644 preferences/migrations/0032_optionaluser_shell_default.py diff --git a/preferences/migrations/0031_auto_20180323_0218.py b/preferences/migrations/0031_auto_20180323_0218.py new file mode 100644 index 00000000..25c98cbf --- /dev/null +++ b/preferences/migrations/0031_auto_20180323_0218.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-03-23 01:18 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0030_merge_20180320_1419'), + ] + + operations = [ + migrations.AlterField( + model_name='generaloption', + name='email_from', + field=models.EmailField(default='www-data@example.com', max_length=254), + ), + ] diff --git a/preferences/migrations/0032_optionaluser_shell_default.py b/preferences/migrations/0032_optionaluser_shell_default.py new file mode 100644 index 00000000..365a616e --- /dev/null +++ b/preferences/migrations/0032_optionaluser_shell_default.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2018-03-24 19:22 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0070_auto_20180324_1906'), + ('preferences', '0031_auto_20180323_0218'), + ] + + operations = [ + migrations.AddField( + model_name='optionaluser', + name='shell_default', + field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.ListShell'), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index 80c3271e..5238e1a5 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -89,6 +89,12 @@ class OptionalUser(PreferencesModel): default=False, help_text="Un nouvel utilisateur peut se créer son compte sur re2o" ) + shell_default = models.OneToOneField( + 'users.ListShell', + on_delete=models.PROTECT, + blank=True, + null=True + ) class Meta: permissions = ( diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 26fc0308..4b234c5c 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -68,7 +68,9 @@ with this program; if not, write to the Free Software Foundation, Inc., Auto inscription {{ useroptions.self_adhesion }} - + Shell par défaut des utilisateurs + {{ useroptions.shell_default }} +

Préférences machines

diff --git a/users/models.py b/users/models.py index 5c6b5568..61f2bef5 100644 --- a/users/models.py +++ b/users/models.py @@ -300,6 +300,12 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin): """ Renvoie seulement le nom""" return self.surname + @property + def get_shell(self): + """ A utiliser de préférence, prend le shell par défaut + si il n'est pas défini""" + return self.shell or OptionalUser.get_cached_value('shell_default') + def end_adhesion(self): """ Renvoie la date de fin d'adhésion d'un user. Examine les objets cotisation""" @@ -502,8 +508,8 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin): user_ldap.gid = LDAP['user_gid'] user_ldap.user_password = self.password[:6] + self.password[7:] user_ldap.sambat_nt_password = self.pwd_ntlm.upper() - if self.shell: - user_ldap.login_shell = self.shell.shell + if self.get_shell: + user_ldap.login_shell = str(self.get_shell) if self.state == self.STATE_DISABLED: user_ldap.shadowexpire = str(0) else: