Commit c3e36d48 authored by Open Science Conservation Fund's avatar Open Science Conservation Fund
Browse files

added demo mode storage quota validation mechinsm; fixed minor bugs; removed deprecated code

parent 13ba107e
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -181,12 +181,6 @@ CSRF_TRUSTED_ORIGINS = [
    "http://localhost:8042",
]

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = "Europe/Warsaw"

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en-us"
@@ -215,6 +209,8 @@ USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
TIME_ZONE = "UTC"
ADMIN_USE_TZ = True  # Django 4.0+ only; ensures admin always uses UTC

# Changed in Django 4.0: zoneinfo was made the default timezone implementation. You may continue to use pytz during
# the 4.x release cycle via the USE_DEPRECATED_PYTZ setting.
@@ -901,3 +897,7 @@ aiproviders_config_path = Path(
    "trapper/apps/media_classification/management/commands/aiproviders_config.json"
)
AI_PROVIDERS_CONFIG = PROJECT_ROOT / aiproviders_config_path

# Demo mode settings
DEMO_MODE = True  # str2bool(os.environ.get("DEMO_MODE", "false"))
DEMO_USER_STORAGE_QUOTA_BYTES = 50 * 1024 * 1024  # $ 50MB
+5 −1
Original line number Diff line number Diff line
@@ -127,7 +127,11 @@ class TrapperAdapter(DefaultAccountAdapter):
        if allauth_headless:
            request.session["is_citizen_science"] = True
        is_citizen_science = request.session.get("is_citizen_science", False)
        if not is_citizen_science and user.is_citizen_science:
        if (
            not is_citizen_science
            and user.is_citizen_science
            and not (user.is_staff or user.is_superuser)
        ):
            messages.add_message(
                request,
                messages.ERROR,
+12 −0
Original line number Diff line number Diff line
@@ -143,9 +143,11 @@ class TrapperUserAdmin(UserAdmin):
        "email",
        "first_name",
        "last_name",
        "is_superuser",
        "is_staff",
        "is_active",
        "is_citizen_science",
        "is_demo_user",
        "has_ftp",
        "gdpr_accepted",
        "tos_accepted",
@@ -154,9 +156,12 @@ class TrapperUserAdmin(UserAdmin):
    list_select_related = ("userprofile",)
    search_fields = ("username", "email", "first_name", "last_name")
    list_filter = (
        "is_superuser",
        "is_staff",
        "is_active",
        "last_login",
        "is_citizen_science",
        "userprofile__demo",
        "userprofile__has_ftp_account",
        UserClassificationProjectFilter,
        UserClassificationProjectRoleFilter,
@@ -198,6 +203,13 @@ class TrapperUserAdmin(UserAdmin):
    def has_ftp(self, item):
        return item.userprofile.has_ftp_account

    @admin.display(
        boolean=True,
        description=_("Demo user"),
    )
    def is_demo_user(self, item):
        return item.userprofile.demo

    @admin.display(
        boolean=True,
        description="GDPR Accepted?",
+14 −3
Original line number Diff line number Diff line
@@ -8,9 +8,20 @@ class CustomAuthenticationBackend(AuthenticationBackend):
        allauth_headless = getattr(getattr(request, "allauth", None), "headless", None)

        user = super().authenticate(request, **credentials)
        # Citizen science cannot login to Expert
        if user and not allauth_headless and user.is_citizen_science:
        # Citizen science users cannot log in to the Expert Portal or use the API
        if (
            user
            and not allauth_headless
            and user.is_citizen_science
            and not (user.is_staff or user.is_superuser)
        ):
            # Check if this is a DRF API request by looking for DRF-specific attributes
            if hasattr(request, "accepted_renderer"):
                # This is a DRF request - return None to indicate auth failure (results in 401)
                return None
            else:
                # Regular Django web request - raise ValidationError for proper form handling
                raise ValidationError(
                _("Citizen science user cannot login to Expert Portal.")
                    _("Citizen science users cannot log in to the Expert Portal.")
                )
        return user
+10 −1
Original line number Diff line number Diff line
@@ -42,7 +42,16 @@ class UserProfileForm(BaseCrispyModelForm):

    class Meta:
        model = UserProfile
        exclude = ["user", "timezone"]
        fields = [
            "email",
            "username",
            "first_name",
            "last_name",
            "institution",
            "about_me",
            "system_notifications",
            "avatar",
        ]

    def get_avatar(self):
        """Prepare img tag containing user avatar"""
Loading