From 4edb009af3f92ff6d5f61e5cae61b61bdd6dbfb7 Mon Sep 17 00:00:00 2001 From: Matt Jaquiery Date: Tue, 25 Jun 2024 11:07:37 +0100 Subject: [PATCH] fix: token generation --- backend_django/config/settings_base.py | 2 +- .../0043_alter_datacolumntype_data_type.py | 18 ++++++++++++++++++ backend_django/galv/models/models.py | 2 +- backend_django/galv/serializers/serializers.py | 6 +++--- backend_django/galv/views.py | 10 +++++----- docs/source/conf.py | 2 +- docs/tags.json | 2 +- 7 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 backend_django/galv/migrations/0043_alter_datacolumntype_data_type.py diff --git a/backend_django/config/settings_base.py b/backend_django/config/settings_base.py index 41327ad..7411c57 100644 --- a/backend_django/config/settings_base.py +++ b/backend_django/config/settings_base.py @@ -20,7 +20,7 @@ # Build paths inside the project like this: BASE_DIR / 'subdir'. import os -API_VERSION = "2.1.45" +API_VERSION = "2.1.46" try: USER_ACTIVATION_TOKEN_EXPIRY_S = int(os.environ.get("DJANGO_USER_ACTIVATION_TOKEN_EXPIRY_S")) diff --git a/backend_django/galv/migrations/0043_alter_datacolumntype_data_type.py b/backend_django/galv/migrations/0043_alter_datacolumntype_data_type.py new file mode 100644 index 0000000..cba3b11 --- /dev/null +++ b/backend_django/galv/migrations/0043_alter_datacolumntype_data_type.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.3 on 2024-06-25 06:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('galv', '0042_alter_schemavalidation_schema'), + ] + + operations = [ + migrations.AlterField( + model_name='datacolumntype', + name='data_type', + field=models.TextField(choices=[('int', 'int'), ('float', 'float'), ('str', 'str'), ('bool', 'bool'), ('datetime64[ns]', 'datetime64[ns]')], default='float', help_text='Type of the data in this column.'), + ), + ] diff --git a/backend_django/galv/models/models.py b/backend_django/galv/models/models.py index 7908468..2d38d3b 100644 --- a/backend_django/galv/models/models.py +++ b/backend_django/galv/models/models.py @@ -1616,7 +1616,7 @@ class DataColumnType(ResourceModelPermissionsMixin, ValidatableBySchemaMixin): data_type = models.TextField( null=False, choices=[(v, v) for v in DATA_TYPES], - help_text="Type of the data in this column", + help_text="Type of the data in this column.", default="float" ) is_default = models.BooleanField( diff --git a/backend_django/galv/serializers/serializers.py b/backend_django/galv/serializers/serializers.py index 3343e9a..574adc5 100644 --- a/backend_django/galv/serializers/serializers.py +++ b/backend_django/galv/serializers/serializers.py @@ -641,19 +641,19 @@ class WithTeamMixin(serializers.Serializer): choices=[(v.value, v.label) for v in ALLOWED_USER_LEVELS_READ], help_text="Minimum user level required to read this resource", allow_null=True, - required=False + default=UserLevel.LAB_MEMBER.value ) edit_access_level = serializers.ChoiceField( choices=[(v.value, v.label) for v in ALLOWED_USER_LEVELS_EDIT], help_text="Minimum user level required to edit this resource", allow_null=True, - required=False + default=UserLevel.TEAM_MEMBER.value ) delete_access_level = serializers.ChoiceField( choices=[(v.value, v.label) for v in ALLOWED_USER_LEVELS_DELETE], help_text="Minimum user level required to create this resource", allow_null=True, - required=False + default=UserLevel.TEAM_MEMBER.value ) def validate_team(self, value): diff --git a/backend_django/galv/views.py b/backend_django/galv/views.py index 5791008..af5282b 100644 --- a/backend_django/galv/views.py +++ b/backend_django/galv/views.py @@ -460,14 +460,14 @@ def get_token_ttl(self): def get_post_response_data(self, request, token, instance): # clean up expired user tokens - for token in KnoxAuthToken.objects.filter(user=request.user): + for t in KnoxAuthToken.objects.filter(user=request.user): try: - knox_token = AuthToken.objects.get(token_key=token.knox_token_key) + knox_token = AuthToken.objects.get(token_key=t.knox_token_key) except AuthToken.DoesNotExist: - token.delete() + t.delete() continue - if knox_token.expiry < timezone.now(): - token.delete() + if knox_token.expiry is not None and knox_token.expiry < timezone.now(): + t.delete() error = None name = request.data.get('name') diff --git a/docs/source/conf.py b/docs/source/conf.py index 0d8cab8..a3ec852 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -11,7 +11,7 @@ project = 'Galv' copyright = '2023, Oxford RSE' author = 'Oxford RSE' -release = '2.1.45' +release = '2.1.46' # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration diff --git a/docs/tags.json b/docs/tags.json index a7c7a2a..024e012 100644 --- a/docs/tags.json +++ b/docs/tags.json @@ -1 +1 @@ -["v2.1.45","main"] \ No newline at end of file +["v2.1.46","main"] \ No newline at end of file