From dffa67abd61ac7b028c68857a531de9f672a5555 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 6 Oct 2022 21:58:56 +0200 Subject: [PATCH 1/6] models: add User.keepalive field (#67901) --- src/authentic2/api_views.py | 2 +- src/authentic2/csv_import.py | 3 +++ .../migrations/0032_user_keepalive.py | 18 ++++++++++++++++++ src/authentic2/custom_user/models.py | 2 ++ src/authentic2/manager/forms.py | 10 +++++++++- tests/test_all.py | 1 + 6 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/authentic2/custom_user/migrations/0032_user_keepalive.py diff --git a/src/authentic2/api_views.py b/src/authentic2/api_views.py index b404370c..b466f2db 100644 --- a/src/authentic2/api_views.py +++ b/src/authentic2/api_views.py @@ -542,7 +542,7 @@ class BaseUserSerializer(serializers.ModelSerializer): 'required': False, } } - exclude = ('user_permissions', 'groups') + exclude = ('user_permissions', 'groups', 'keepalive') class DuplicateUserSerializer(BaseUserSerializer): diff --git a/src/authentic2/csv_import.py b/src/authentic2/csv_import.py index 39d8a620..e3a37523 100644 --- a/src/authentic2/csv_import.py +++ b/src/authentic2/csv_import.py @@ -273,6 +273,9 @@ class ImportUserForm(BaseUserForm): raise ValidationError(_('Invalid password format or unknown hashing algorithm.')) return password_hash + class Meta: + exclude = ('keepalive',) + class ImportUserFormWithExternalId(ImportUserForm): locals()[SOURCE_NAME] = forms.CharField( diff --git a/src/authentic2/custom_user/migrations/0032_user_keepalive.py b/src/authentic2/custom_user/migrations/0032_user_keepalive.py new file mode 100644 index 00000000..a1f6f7cb --- /dev/null +++ b/src/authentic2/custom_user/migrations/0032_user_keepalive.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.26 on 2022-10-06 19:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('custom_user', '0031_profile_email'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='keepalive', + field=models.DateTimeField(blank=True, null=True, verbose_name='Keepalive timestamp'), + ), + ] diff --git a/src/authentic2/custom_user/models.py b/src/authentic2/custom_user/models.py index baeade85..eea3f097 100644 --- a/src/authentic2/custom_user/models.py +++ b/src/authentic2/custom_user/models.py @@ -192,6 +192,8 @@ class User(AbstractBaseUser, PermissionMixin): verified_attributes = AttributesDescriptor(verified=True) is_verified = IsVerifiedDescriptor() + keepalive = models.DateTimeField(verbose_name=_('Keepalive timestamp'), null=True, blank=True) + attribute_values = GenericRelation('authentic2.AttributeValue') USERNAME_FIELD = 'username' diff --git a/src/authentic2/manager/forms.py b/src/authentic2/manager/forms.py index 8e8713d5..bb15881b 100644 --- a/src/authentic2/manager/forms.py +++ b/src/authentic2/manager/forms.py @@ -181,7 +181,15 @@ class UserEditForm(LimitQuerysetFormMixin, CssClass, BaseUserForm): class Meta: model = User - exclude = ('is_staff', 'groups', 'user_permissions', 'last_login', 'date_joined', 'password') + exclude = ( + 'is_staff', + 'groups', + 'user_permissions', + 'last_login', + 'date_joined', + 'password', + 'keepalive', + ) class UserChangePasswordForm(CssClass, forms.ModelForm): diff --git a/tests/test_all.py b/tests/test_all.py index dd0f2dd2..40917a4e 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -88,6 +88,7 @@ class SerializerTests(TestCase): 'ou': None, 'deactivation': None, 'deactivation_reason': None, + 'keepalive': None, }, }, { -- 2.37.2