diff --git a/passbook/core/models.py b/passbook/core/models.py index 82b055d6a..531045d84 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -194,9 +194,7 @@ class Policy(UUIDModel, CreatedUpdatedModel): objects = InheritanceManager() def __str__(self): - if self.name: - return self.name - return f"{self.name} action {self.action}" + return f"Policy {self.name}" def passes(self, request: PolicyRequest) -> PolicyResult: """Check if user instance passes this policy""" diff --git a/passbook/policies/engine.py b/passbook/policies/engine.py index bc661bea1..3d9cbf69e 100644 --- a/passbook/policies/engine.py +++ b/passbook/policies/engine.py @@ -13,12 +13,13 @@ from passbook.policies.struct import PolicyRequest, PolicyResult LOGGER = get_logger() + class PolicyProcessInfo: """Dataclass to hold all information and communication channels to a process""" process: PolicyProcess connection: Connection - result: PolicyResult = None + result: PolicyResult policy: Policy def __init__(self, process: PolicyProcess, connection: Connection, policy: Policy): @@ -91,9 +92,7 @@ class PolicyEngine: """Get policy-checking result""" messages: List[str] = [] for proc_info in self.__processes: - # passing = (policy_action == Policy.ACTION_ALLOW and policy_result) or \ - # (policy_action == Policy.ACTION_DENY and not policy_result) - LOGGER.debug("Result", passing=proc_info.result.passing) + LOGGER.debug("Result", policy=proc_info.policy, passing=proc_info.result.passing) if proc_info.result.messages: messages += proc_info.result.messages if not proc_info.result.passing: diff --git a/passbook/policies/process.py b/passbook/policies/process.py index c12375359..5d912e8b6 100644 --- a/passbook/policies/process.py +++ b/passbook/policies/process.py @@ -40,7 +40,7 @@ class PolicyProcess(Process): policy_result = PolicyResult(False, str(exc)) # Invert result if policy.negate is set if self.policy.negate: - policy_result = not policy_result + policy_result.passing = not policy_result.passing LOGGER.debug("Got result", policy=self.policy, result=policy_result, process="PolicyProcess") key = cache_key(self.policy, self.request.user) diff --git a/passbook/policies/reputation/forms.py b/passbook/policies/reputation/forms.py index 53d2e53eb..f173d234b 100644 --- a/passbook/policies/reputation/forms.py +++ b/passbook/policies/reputation/forms.py @@ -1,5 +1,6 @@ """passbook reputation request forms""" from django import forms +from django.utils.translation import gettext_lazy as _ from passbook.core.forms.policies import GENERAL_FIELDS from passbook.policies.reputation.models import ReputationPolicy @@ -16,3 +17,6 @@ class ReputationPolicyForm(forms.ModelForm): 'name': forms.TextInput(), 'value': forms.TextInput(), } + labels = { + 'check_ip': _('Check IP'), + } diff --git a/passbook/policies/struct.py b/passbook/policies/struct.py index 4381031c7..957f75623 100644 --- a/passbook/policies/struct.py +++ b/passbook/policies/struct.py @@ -1,4 +1,4 @@ -"""policy structs""" +"""policy structures""" from __future__ import annotations from typing import TYPE_CHECKING, List diff --git a/passbook/root/settings.py b/passbook/root/settings.py index f829520aa..4bca8701c 100644 --- a/passbook/root/settings.py +++ b/passbook/root/settings.py @@ -118,7 +118,7 @@ CACHES = { } DJANGO_REDIS_IGNORE_EXCEPTIONS = True DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True -SESSION_ENGINE = "django.contrib.sessions.backends.cached_db" +SESSION_ENGINE = "django.contrib.sessions.backends.cache" SESSION_CACHE_ALIAS = "default" MIDDLEWARE = [