Fix HTTP 500 on the create pages with ?return=detail
UserCreate and AliasCreate used BackToUsersMixin and BackToAliasesMixin, which access self.user or self.alias for ?return=detail. Neither exists on the create pages, so the request failed with an AttributeError. Both views now define their own back link with the target they already used without the parameter: the user list and the user's detail page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
91eaef7f93
commit
5b87d9ff03
2 files changed
+10
-8
No files matched your search
@@ -1,22 +1,22 @@
|
|||||||
from flask import flash
|
from flask import flash, url_for
|
||||||
|
|
||||||
from max.db import EmailAlreadyExists, create_alias, get_domains
|
from max.db import EmailAlreadyExists, create_alias, get_domains
|
||||||
from max.permissions import AllowAdminOrSelf
|
from max.permissions import AllowAdminOrSelf
|
||||||
from max.translations import t
|
from max.translations import t
|
||||||
|
|
||||||
from ..base_alias_views import BackToAliasesMixin
|
|
||||||
from ..base_user_views import FetchUserTemplateGetView
|
from ..base_user_views import FetchUserTemplateGetView
|
||||||
from ..check_email_mixin import CheckEmailMixin
|
from ..check_email_mixin import CheckEmailMixin
|
||||||
|
|
||||||
|
|
||||||
class AliasCreate(
|
class AliasCreate(AllowAdminOrSelf, CheckEmailMixin, FetchUserTemplateGetView):
|
||||||
AllowAdminOrSelf, CheckEmailMixin, BackToAliasesMixin, FetchUserTemplateGetView
|
|
||||||
):
|
|
||||||
template_name = "alias/create.html"
|
template_name = "alias/create.html"
|
||||||
|
|
||||||
def get_webpagetitle(self):
|
def get_webpagetitle(self):
|
||||||
return f"Create new alias for {self.user.email}"
|
return f"Create new alias for {self.user.email}"
|
||||||
|
|
||||||
|
def get_back_text_and_url(self):
|
||||||
|
return self.user.email, url_for("user-detail", user_id=self.user.id)
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
error = False
|
error = False
|
||||||
email = self.request.form.get("email")
|
email = self.request.form.get("email")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from flask import flash
|
from flask import flash, url_for
|
||||||
|
|
||||||
from max.auth import hash_password
|
from max.auth import hash_password
|
||||||
from max.db import EmailAlreadyExists, create_user, get_domains
|
from max.db import EmailAlreadyExists, create_user, get_domains
|
||||||
@@ -6,11 +6,10 @@ from max.permissions import AllowAdmin
|
|||||||
from max.translations import t
|
from max.translations import t
|
||||||
from max.views import BaseTemplateGetView
|
from max.views import BaseTemplateGetView
|
||||||
|
|
||||||
from ..base_user_views import BackToUsersMixin
|
|
||||||
from ..check_email_mixin import CheckEmailMixin
|
from ..check_email_mixin import CheckEmailMixin
|
||||||
|
|
||||||
|
|
||||||
class UserCreate(AllowAdmin, CheckEmailMixin, BackToUsersMixin, BaseTemplateGetView):
|
class UserCreate(AllowAdmin, CheckEmailMixin, BaseTemplateGetView):
|
||||||
template_name = "user/create.html"
|
template_name = "user/create.html"
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
@@ -134,3 +133,6 @@ class UserCreate(AllowAdmin, CheckEmailMixin, BackToUsersMixin, BaseTemplateGetV
|
|||||||
|
|
||||||
def get_webpagetitle(self):
|
def get_webpagetitle(self):
|
||||||
return t("Create new user")
|
return t("Create new user")
|
||||||
|
|
||||||
|
def get_back_text_and_url(self):
|
||||||
|
return t("User list"), url_for("user-list")
|
||||||
Reference in new issue
Block a user