-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #542 from coders4help/develop
Apply fixes for release
- Loading branch information
Showing
44 changed files
with
896 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,45 @@ | ||
# coding=utf-8 | ||
# Register your models here. | ||
import logging | ||
|
||
from django.contrib import messages | ||
from django.core.exceptions import PermissionDenied | ||
from django.http import HttpResponseRedirect | ||
from django.urls import reverse | ||
from django.utils.html import escape | ||
from django.utils.safestring import mark_safe | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class RedirectOnAdminPermissionDenied403: | ||
def __init__(self, get_response): | ||
self.get_response = get_response | ||
|
||
def __call__(self, request): | ||
response = self.get_response(request) | ||
return response | ||
|
||
def process_exception(self, request, exception): | ||
admin_index = reverse("admin:index") | ||
if ( | ||
hasattr(request, "user") | ||
and getattr(request.user, "is_authenticated", False) | ||
and getattr(request.user, "is_staff", False) | ||
and request.path != admin_index | ||
and request.path.startswith(admin_index) | ||
and isinstance(exception, PermissionDenied) | ||
): | ||
redirect_path = admin_index | ||
error_code = 403 | ||
error = _("Error {error_code}").format(error_code=error_code) | ||
permission_denied = _("Permission denied") | ||
error = f"{error}: {permission_denied}" | ||
note = _( | ||
"You are not allowed to do this and have been redirected to {redirect_path}." # noqa: E501 | ||
).format(redirect_path=redirect_path) | ||
messages.error( | ||
request, | ||
mark_safe(f"<strong>{note}</strong><br/> {error} - ") | ||
+ escape(f"{request.method} {request.path}"), | ||
) | ||
return HttpResponseRedirect(redirect_path) |
35 changes: 35 additions & 0 deletions
35
content/migrations/0005_alter_flatpagetranslation_language.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 4.0.3 on 2022-03-30 08:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("content", "0004_alter_flatpagetranslation_language"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="flatpagetranslation", | ||
name="language", | ||
field=models.CharField( | ||
choices=[ | ||
("uk", "Ukrainian"), | ||
("en", "English"), | ||
("de", "German"), | ||
("cs", "Czech"), | ||
("el", "Greek"), | ||
("fr", "French"), | ||
("hu", "Hungarian"), | ||
("pl", "Polish"), | ||
("pt", "Portuguese"), | ||
("ru", "Russian"), | ||
("sv", "Swedish"), | ||
("tr", "Turkish"), | ||
], | ||
max_length=20, | ||
verbose_name="language", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.