From 3b04c2bab49093368fe6a4ac70d7554303b443cc Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 6 Oct 2022 21:58:56 +0200 Subject: [PATCH 1/7] models: add User.keepalive field (#67901) --- src/authentic2/api_views.py | 2 +- src/authentic2/csv_import.py | 3 +++ .../migrations/0033_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/0033_user_keepalive.py diff --git a/src/authentic2/api_views.py b/src/authentic2/api_views.py index 3606238f..d195beaf 100644 --- a/src/authentic2/api_views.py +++ b/src/authentic2/api_views.py @@ -543,7 +543,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/0033_user_keepalive.py b/src/authentic2/custom_user/migrations/0033_user_keepalive.py new file mode 100644 index 00000000..45c94b73 --- /dev/null +++ b/src/authentic2/custom_user/migrations/0033_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', '0032_auto_20220919_1230'), + ] + + 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 f8138cc7..b15ef1b2 100644 --- a/src/authentic2/custom_user/models.py +++ b/src/authentic2/custom_user/models.py @@ -235,6 +235,8 @@ class User(AbstractBaseUser): 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 319c04db..beead340 100644 --- a/src/authentic2/manager/forms.py +++ b/src/authentic2/manager/forms.py @@ -180,7 +180,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 167b033b..e0a2fca7 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -90,6 +90,7 @@ class SerializerTests(TestCase): 'ou': None, 'deactivation': None, 'deactivation_reason': None, + 'keepalive': None, }, }, { -- 2.37.2