|
25 | 25 | from django.contrib.admin.templatetags.admin_urls import admin_urlname |
26 | 26 | from django.contrib.admin.views.main import ChangeList |
27 | 27 | from django.contrib.auth.models import Group |
28 | | -from django.contrib.auth.views import redirect_to_login |
| 28 | +from django.contrib.auth.views import logout_then_login, redirect_to_login |
29 | 29 | from django.core.exceptions import PermissionDenied, ValidationError |
| 30 | +from django.core.files.storage import storages |
30 | 31 | from django.db.models import Q, QuerySet |
31 | 32 | from django.db.models.fields.json import JSONField |
32 | 33 | from django.db.models.functions import Lower |
|
68 | 69 | from qfieldcloud.core.templatetags.filters import filesizeformat10 |
69 | 70 | from qfieldcloud.core.utils import get_file_storage_choices |
70 | 71 | from qfieldcloud.core.utils2 import delta_utils, jobs, pg_service_file |
| 72 | +from qfieldcloud.filestorage.backend import QfcS3Boto3Storage |
71 | 73 | from qfieldcloud.filestorage.models import File |
72 | 74 |
|
73 | 75 |
|
@@ -99,6 +101,12 @@ def login( |
99 | 101 | request.GET.get("next", ""), login_url=reverse(settings.LOGIN_URL) |
100 | 102 | ) |
101 | 103 |
|
| 104 | + def logout( # type: ignore[override] |
| 105 | + self, request: HttpRequest, extra_context: dict[str, Any] | None = None |
| 106 | + ) -> HttpResponse: |
| 107 | + """Override the default Django admin logout view to redirect to the Allauth's logout view.""" |
| 108 | + return logout_then_login(request) |
| 109 | + |
102 | 110 | # TODO consider adding a logout view to redirect to the Allauth's logout view, but then we lose the nice template we have right now. |
103 | 111 |
|
104 | 112 |
|
@@ -855,6 +863,26 @@ def __init__(self, *args, **kwargs): |
855 | 863 | ) |
856 | 864 | if self.instance.has_attachments_files: |
857 | 865 | self.fields["attachments_file_storage"].disabled = True |
| 866 | + self.fields["are_attachments_versioned"].disabled = True |
| 867 | + |
| 868 | + def clean_are_attachments_versioned(self): |
| 869 | + value = self.cleaned_data["are_attachments_versioned"] |
| 870 | + |
| 871 | + if value: |
| 872 | + return value |
| 873 | + |
| 874 | + # attachments can not be unversioned if attachments are stored on S3. |
| 875 | + attachment_storage_value = self.cleaned_data["attachments_file_storage"] |
| 876 | + attachment_storage = storages[attachment_storage_value] |
| 877 | + |
| 878 | + if isinstance(attachment_storage, QfcS3Boto3Storage): |
| 879 | + raise ValidationError( |
| 880 | + _( |
| 881 | + "The '{}' attachments file storage is not compatible with unversioned attachment files." |
| 882 | + ).format(attachment_storage_value) |
| 883 | + ) |
| 884 | + |
| 885 | + return value |
858 | 886 |
|
859 | 887 |
|
860 | 888 | class ProjectAdmin(QFieldCloudModelAdmin): |
@@ -899,6 +927,7 @@ class ProjectAdmin(QFieldCloudModelAdmin): |
899 | 927 | "file_storage", |
900 | 928 | "file_storage_migrated_at", |
901 | 929 | "attachments_file_storage", |
| 930 | + "are_attachments_versioned", |
902 | 931 | "is_attachment_download_on_demand", |
903 | 932 | "project_files", |
904 | 933 | ) |
|
0 commit comments