return 404 when accessing not existing account

This commit is contained in:
imperosol
2024-10-08 15:30:35 +02:00
parent 58d3a7ee2c
commit b0884c6b04
2 changed files with 23 additions and 6 deletions

View File

@ -632,6 +632,12 @@ class UserAccountBase(UserTabsMixin, DetailView):
return super().dispatch(request, *arg, **kwargs)
raise PermissionDenied
def get_object(self, queryset=None):
obj = super().get_object(queryset)
if not hasattr(obj, "customer"):
raise Http404(_("User has no account"))
return obj
class UserAccountView(UserAccountBase):
"""Display a user's account."""
@ -671,11 +677,6 @@ class UserAccountDetailView(UserAccountBase, YearMixin, MonthMixin):
template_name = "core/user_account_detail.jinja"
def get(self, request, *args, **kwargs):
if not hasattr(self.get_object(), "customer"):
raise Http404(_("This user has no account"))
return super().get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
kwargs = super().get_context_data(**kwargs)
kwargs["profile"] = self.object