From 0b1c35900fbec6d815a7f9e4a37993a290344619 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 5 Jan 2019 18:32:54 +0100 Subject: [PATCH] =?UTF-8?q?Ajoute=20un=20reglage=20pour=20set=20tous=20les?= =?UTF-8?q?=20comptes=20actifs=20=C3=A0=20l'initialisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0057_optionaluser_all_users_active.py | 20 +++++++++++++++++++ preferences/models.py | 5 +++++ .../preferences/display_preferences.html | 4 ++++ users/forms.py | 1 + users/models.py | 2 +- 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 preferences/migrations/0057_optionaluser_all_users_active.py diff --git a/preferences/migrations/0057_optionaluser_all_users_active.py b/preferences/migrations/0057_optionaluser_all_users_active.py new file mode 100644 index 00000000..3f0cc8c1 --- /dev/null +++ b/preferences/migrations/0057_optionaluser_all_users_active.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2019-01-05 17:15 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('preferences', '0056_4_radiusoption'), + ] + + operations = [ + migrations.AddField( + model_name='optionaluser', + name='all_users_active', + field=models.BooleanField(default=False, help_text='If True, all new created and connected users are active. If False, only when a valid registration has been paid'), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index 104c261d..228807a6 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -116,6 +116,11 @@ class OptionalUser(AclMixin, PreferencesModel): default=False, help_text=_("A new user can create their account on Re2o") ) + all_users_active = models.BooleanField( + default=False, + help_text=_("If True, all new created and connected users are active.\ + If False, only when a valid registration has been paid") + ) class Meta: permissions = ( diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 0e34d6e9..e4321f5b 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -122,6 +122,10 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "Delete not yet active users after" %} {{ useroptions.delete_notyetactive }} days + + {% trans "All users are active by default" %} + {{ useroptions.all_users_active|tick }} +

{% trans "Users general permissions" %}

diff --git a/users/forms.py b/users/forms.py index effcc60c..d4110dcd 100644 --- a/users/forms.py +++ b/users/forms.py @@ -117,6 +117,7 @@ class PassForm(FormRevMixin, FieldPermissionFormMixin, forms.ModelForm): """Changement du mot de passe""" user = super(PassForm, self).save(commit=False) user.set_password(self.cleaned_data.get("passwd1")) + user.set_active() user.save() diff --git a/users/models.py b/users/models.py index e4c25956..c5287fb6 100755 --- a/users/models.py +++ b/users/models.py @@ -337,7 +337,7 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser, def set_active(self): """Enable this user if he subscribed successfully one time before""" if self.state == self.STATE_NOT_YET_ACTIVE: - if self.facture_set.filter(valid=True).filter(Q(vente__type_cotisation='All') | Q(vente__type_cotisation='Adhesion')).exists(): + if self.facture_set.filter(valid=True).filter(Q(vente__type_cotisation='All') | Q(vente__type_cotisation='Adhesion')).exists() or OptionalUser.get_cached_value('all_users_active'): self.state = self.STATE_ACTIVE self.save()