8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 07:23:46 +00:00

Merge branch 'gpg_fp' into 'dev'

Gpg fp

See merge request federez/re2o!370
This commit is contained in:
klafyvel 2018-12-28 23:29:49 +01:00
commit f54cbc1a38
3 changed files with 54 additions and 26 deletions

View file

@ -324,14 +324,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
self.fields['room'].empty_label = _("No room")
self.fields['school'].empty_label = _("Select a school")
def clean_email(self):
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'):
return self.cleaned_data.get('email').lower()
else:
raise forms.ValidationError(
_("You can't use a {} address.").format(
OptionalUser.objects.first().local_email_domain))
class Meta:
model = Adherent
fields = [
@ -345,6 +337,19 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
'room',
]
force = forms.BooleanField(
label=_("Force the move?"),
initial=False,
required=False
)
def clean_email(self):
if not OptionalUser.objects.first().local_email_domain in self.cleaned_data.get('email'):
return self.cleaned_data.get('email').lower()
else:
raise forms.ValidationError(
_("You can't use a {} address.").format(
OptionalUser.objects.first().local_email_domain))
def clean_telephone(self):
"""Verifie que le tel est présent si 'option est validée
@ -356,12 +361,6 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
)
return telephone
force = forms.BooleanField(
label=_("Force the move?"),
initial=False,
required=False
)
def clean_force(self):
"""On supprime l'ancien user de la chambre si et seulement si la
case est cochée"""
@ -369,6 +368,7 @@ class AdherentForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
remove_user_room(self.cleaned_data.get('room'))
return
class AdherentCreationForm(AdherentForm):
"""Formulaire de création d'un user.
AdherentForm auquel on ajoute une checkbox afin d'éviter les
@ -399,12 +399,6 @@ class AdherentEditForm(AdherentForm):
if 'shell' in self.fields:
self.fields['shell'].empty_label = _("Default shell")
def clean_gpg_fingerprint(self):
"""Format the GPG fingerprint"""
gpg_fingerprint = self.cleaned_data.get('gpg_fingerprint', None)
if gpg_fingerprint:
return gpg_fingerprint.replace(' ', '').upper()
class Meta:
model = Adherent
fields = [

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-12-28 19:39
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0078_auto_20181011_1405'),
]
operations = [
migrations.AlterField(
model_name='adherent',
name='gpg_fingerprint',
field=models.CharField(blank=True, max_length=49, null=True),
),
]

View file

@ -1053,20 +1053,27 @@ class Adherent(User):
null=True
)
gpg_fingerprint = models.CharField(
max_length=40,
max_length=49,
blank=True,
null=True,
validators=[RegexValidator(
'^[0-9A-F]{40}$',
message=_("A GPG fingerprint must contain 40 hexadecimal"
" characters.")
)]
)
class Meta(User.Meta):
verbose_name = _("member")
verbose_name_plural = _("members")
def format_gpgfp(self):
"""Format gpg finger print as AAAA BBBB... from a string AAAABBBB...."""
self.gpg_fingerprint = ' '.join([self.gpg_fingerprint[i:i + 4] for i in range(0, len(self.gpg_fingerprint), 4)])
def validate_gpgfp(self):
"""Validate from raw entry if is it a valid gpg fp"""
if self.gpg_fingerprint:
gpg_fingerprint = self.gpg_fingerprint.replace(' ', '').upper()
if not re.match("^[0-9A-F]{40}$", gpg_fingerprint):
raise ValidationError(_("A gpg fingerprint must contain 40 hexadecimal carracters"))
self.gpg_fingerprint = gpg_fingerprint
@classmethod
def get_instance(cls, adherentid, *_args, **_kwargs):
"""Try to find an instance of `Adherent` with the given id.
@ -1097,6 +1104,13 @@ class Adherent(User):
_("You don't have the right to create a user.")
)
def clean(self, *args, **kwargs):
"""Format the GPG fingerprint"""
super(Adherent, self).clean(*args, **kwargs)
if self.gpg_fingerprint:
self.validate_gpgfp()
self.format_gpgfp()
class Club(User):
""" A class representing a club (it is considered as a user