diff --git a/preferences/admin.py b/preferences/admin.py index efeefc87..6b6969ed 100644 --- a/preferences/admin.py +++ b/preferences/admin.py @@ -29,7 +29,6 @@ from django.contrib import admin from reversion.admin import VersionAdmin from .models import ( - OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption, @@ -44,6 +43,7 @@ from .models import ( DocumentTemplate ) +from users.preferences.models import PreferencesUser as OptionalUser class OptionalUserAdmin(VersionAdmin): """Class admin options user""" diff --git a/preferences/forms.py b/preferences/forms.py index d2bede7c..b962a27f 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -30,7 +30,6 @@ from django import forms from django.utils.translation import ugettext_lazy as _ from re2o.mixins import FormRevMixin from .models import ( - OptionalUser, OptionalMachine, OptionalTopologie, GeneralOption, @@ -46,6 +45,7 @@ from .models import ( CotisationsOption, DocumentTemplate ) +from users.preferences.models import PreferencesUser as OptionalUser from topologie.models import Switch diff --git a/preferences/views.py b/preferences/views.py index 471207e0..d1f91486 100644 --- a/preferences/views.py +++ b/preferences/views.py @@ -57,7 +57,6 @@ from .forms import ( from .models import ( Service, MailContact, - OptionalUser, OptionalMachine, AssoOption, MailMessageOption, @@ -71,6 +70,8 @@ from .models import ( CotisationsOption, DocumentTemplate ) + +from users.preferences.models import PreferencesUser as OptionalUser from . import models from . import forms diff --git a/re2o/templatetags/self_adhesion.py b/re2o/templatetags/self_adhesion.py index 09fe5ede..d80f99da 100644 --- a/re2o/templatetags/self_adhesion.py +++ b/re2o/templatetags/self_adhesion.py @@ -26,7 +26,7 @@ which indicated if a user can creates an account by himself """ from django import template -from preferences.models import OptionalUser +from users.preferences.models import PreferencesUser as OptionalUser register = template.Library() diff --git a/users/forms.py b/users/forms.py index 582b2f97..904984ff 100644 --- a/users/forms.py +++ b/users/forms.py @@ -44,7 +44,7 @@ from django.utils.safestring import mark_safe from machines.models import Interface, Machine, Nas from topologie.models import Port -from preferences.models import OptionalUser +from .preferences.models import PreferencesUser as OptionalUser from re2o.utils import remove_user_room from re2o.base import get_input_formats_help_text from re2o.mixins import FormRevMixin diff --git a/users/models.py b/users/models.py index 823d1f7f..898f3ab3 100755 --- a/users/models.py +++ b/users/models.py @@ -85,7 +85,8 @@ from re2o.base import smtp_check from cotisations.models import Cotisation, Facture, Paiement, Vente from machines.models import Domain, Interface, Machine, regen -from preferences.models import GeneralOption, AssoOption, OptionalUser +from preferences.models import GeneralOption, AssoOption +from .preferences.models import PreferencesUser as OptionalUser from preferences.models import OptionalMachine, MailMessageOption diff --git a/users/preferences/models.py b/users/preferences/models.py new file mode 100644 index 00000000..a93a5238 --- /dev/null +++ b/users/preferences/models.py @@ -0,0 +1,108 @@ +# quelques clics. +# +# Copyright © 2017 Gabriel Détraz +# Copyright © 2017 Goulven Kermarec +# Copyright © 2017 Augustin Lemesle +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +from django.db import models +from django.db.models.signals import post_save +from django.dispatch import receiver +from django.forms import ValidationError +from django.utils.translation import ugettext_lazy as _ + +from re2o.mixins import AclMixin + +from preferences.models import PreferencesModel + +class PreferencesUser(AclMixin, PreferencesModel): + """Options pour l'user : obligation ou nom du telephone, + activation ou non du solde, autorisation du negatif, fingerprint etc""" + + is_tel_mandatory = models.BooleanField(default=True) + gpg_fingerprint = models.BooleanField(default=True) + all_can_create_club = models.BooleanField( + default=False, + help_text=_("Users can create a club.") + ) + all_can_create_adherent = models.BooleanField( + default=False, + help_text=_("Users can create a member."), + ) + + shell_default = models.OneToOneField( + 'users.ListShell', + on_delete=models.PROTECT, + blank=True, + null=True + ) + self_change_shell = models.BooleanField( + 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.") + ) + local_email_domain = models.CharField( + max_length=32, + default="@example.org", + help_text=_("Domain to use for local email accounts") + ) + max_email_address = models.IntegerField( + default=15, + help_text=_("Maximum number of local email addresses for a standard" + " user.") + ) + delete_notyetactive = models.IntegerField( + default=15, + help_text=_("Not yet active 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.") + ) + 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 = ( + ("view_optionaluser", _("Can view the user options")), + ) + verbose_name = _("user options") + + def clean(self): + """Clean model: + Check the mail_extension + """ + if self.local_email_domain[0] != "@": + raise ValidationError(_("Email domain must begin with @")) + + +@receiver(post_save, sender=PreferencesUser) +def preferencesUser_post_save(**kwargs): + """Ecriture dans le cache""" + user_pref = kwargs['instance'] + user_pref.set_in_cache() diff --git a/users/views.py b/users/views.py index 045446b1..35ad8761 100644 --- a/users/views.py +++ b/users/views.py @@ -55,7 +55,8 @@ from reversion import revisions as reversion from cotisations.models import Facture, Paiement from machines.models import Machine -from preferences.models import OptionalUser, GeneralOption, AssoOption +from preferences.models import GeneralOption, AssoOption +from .preferences.models import PreferencesUser as OptionalUser from importlib import import_module from re2o.settings_local import OPTIONNAL_APPS_RE2O from re2o.views import form