diff --git a/adhocracy-plus/config/settings/base.py b/adhocracy-plus/config/settings/base.py index 3ec17682f..9ba86c72d 100644 --- a/adhocracy-plus/config/settings/base.py +++ b/adhocracy-plus/config/settings/base.py @@ -16,6 +16,7 @@ # Link to a dokuwiki instance containing a manual for aplus # Leave blank to disable +# For guest users this is hardcoded in indicator.html APLUS_MANUAL_URL = "" # Application definition @@ -42,6 +43,7 @@ "allauth", "allauth.account", "allauth.socialaccount", + "guest_user", "rules.apps.AutodiscoverRulesConfig", "easy_thumbnails", "parler", @@ -280,6 +282,7 @@ "rules.permissions.ObjectPermissionBackend", "django.contrib.auth.backends.ModelBackend", "allauth.account.auth_backends.AuthenticationBackend", + "guest_user.backends.GuestBackend", ) ACCOUNT_ADAPTER = "apps.users.adapters.AccountAdapter" @@ -719,3 +722,13 @@ }, }, } + +GUEST_USER = { + "NAME_GENERATOR": "guest_user.functions.generate_uuid_username", +} + + +GUEST_USER_REQUIRED_ANON_URL = "/accounts/guests/login" +# Redirects below when guest user is required but currently regular user. +# Currently only guest dashboard views use this, so redirects to user profile. +GUEST_USER_REQUIRED_USER_URL = "/account/profile/" diff --git a/apps/account/views.py b/apps/account/views.py index ae6f66232..40b3fc0a5 100644 --- a/apps/account/views.py +++ b/apps/account/views.py @@ -12,18 +12,20 @@ from apps.users.models import User from apps.users.utils import set_session_language +from guest_user.functions import is_guest_user +from guest_user.mixins import GuestUserRequiredMixin, RegularUserRequiredMixin + from . import forms from .emails import AccountDeletionEmail -class AccountView(RedirectView): +class AccountView(RegularUserRequiredMixin, RedirectView): permanent = False pattern_name = "account_profile" # Placeholder View to be replaced if we want to use a custom account # dashboard function overview. - -class ProfileUpdateView(LoginRequiredMixin, SuccessMessageMixin, generic.UpdateView): +class ProfileUpdateView(LoginRequiredMixin, SuccessMessageMixin, RegularUserRequiredMixin, generic.UpdateView): model = User template_name = "a4_candy_account/profile.html" form_class = forms.ProfileForm diff --git a/apps/augmentedreality/api.py b/apps/augmentedreality/api.py index 584621357..a1401e3e4 100644 --- a/apps/augmentedreality/api.py +++ b/apps/augmentedreality/api.py @@ -1,7 +1,14 @@ +from guest_user.mixins import AllowGuestUserMixin + from adhocracy4.comments_async.api import CommentViewSet +from adhocracy4.ratings.api import RatingViewSet + + +class CombinedRatingViewSet(AllowGuestUserMixin, RatingViewSet): + http_method_names = ["post", "patch"] -class CombinedCommentViewSet(CommentViewSet): +class CombinedCommentViewSet(AllowGuestUserMixin, CommentViewSet): def get_queryset(self): comments = super().get_queryset() return comments diff --git a/apps/augmentedreality/migrations/0005_alter_scene_content_type.py b/apps/augmentedreality/migrations/0005_alter_scene_content_type.py new file mode 100644 index 000000000..5e40bdbef --- /dev/null +++ b/apps/augmentedreality/migrations/0005_alter_scene_content_type.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.18 on 2025-07-01 15:42 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("contenttypes", "0002_remove_content_type_name"), + ("arpas_augmentedreality", "0004_alter_arobject_scene"), + ] + + operations = [ + migrations.AlterField( + model_name="scene", + name="content_type", + field=models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="scenes", + to="contenttypes.contenttype", + ), + ), + ] diff --git a/apps/augmentedreality/models.py b/apps/augmentedreality/models.py index 521decaa9..0fa8c9444 100644 --- a/apps/augmentedreality/models.py +++ b/apps/augmentedreality/models.py @@ -25,7 +25,9 @@ def validate_item_content_type(content_type): class Scene(models.Model): - content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) + content_type = models.ForeignKey( + ContentType, on_delete=models.CASCADE, related_name="scenes" + ) object_id = models.PositiveIntegerField() item = GenericForeignKey("content_type", "object_id") diff --git a/apps/augmentedreality/urls.py b/apps/augmentedreality/urls.py index b241ab5e9..bc7a83439 100644 --- a/apps/augmentedreality/urls.py +++ b/apps/augmentedreality/urls.py @@ -1,8 +1,10 @@ from adhocracy4.api import routers as a4routers from .api import CombinedCommentViewSet +from .api import CombinedRatingViewSet ct_router = a4routers.ContentTypeDefaultRouter() -ct_router.register(r"arpas_comments", CombinedCommentViewSet, basename="arpas_comments") +ct_router.register(r"arpas-comments", CombinedCommentViewSet, basename="arpas-comments") +ct_router.register(r"arpas-ratings", CombinedRatingViewSet, basename="arpas-ratings") urlpatterns = ct_router.urls diff --git a/apps/userdashboard/views.py b/apps/userdashboard/views.py index 7a287402f..60bccd13e 100644 --- a/apps/userdashboard/views.py +++ b/apps/userdashboard/views.py @@ -3,6 +3,7 @@ from django.shortcuts import get_object_or_404 from django.urls import reverse from django.views import generic +from guest_user.mixins import RegularUserRequiredMixin from adhocracy4.actions.models import Action from adhocracy4.comments.models import Comment @@ -18,6 +19,7 @@ class UserDashboardBaseMixin( LoginRequiredMixin, + RegularUserRequiredMixin, generic.base.ContextMixin, generic.base.TemplateResponseMixin, generic.base.View, diff --git a/apps/users/models.py b/apps/users/models.py index 1cb0959b9..a23d003b9 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -126,6 +126,7 @@ class User(auth_models.AbstractBaseUser, auth_models.PermissionsMixin): objects = auth_models.UserManager() USERNAME_FIELD = "username" + PASSWORD_FIELD = "username" # for django-guest-user REQUIRED_FIELDS = ["email"] def get_projects_follow_list(self, exclude_private_projects=False): diff --git a/apps/users/templates/a4_candy_users/indicator.html b/apps/users/templates/a4_candy_users/indicator.html index 7bf6a34c2..26b8d5a4f 100644 --- a/apps/users/templates/a4_candy_users/indicator.html +++ b/apps/users/templates/a4_candy_users/indicator.html @@ -1,65 +1,77 @@ -{% load i18n static thumbnail settings %} +{% load i18n static thumbnail settings guest_user %} {% if request.user.is_authenticated %} -