feat: add durable mail delivery outbox
This commit is contained in:
@@ -4,7 +4,13 @@ from typing import Any
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from govoplan_core.core.modules import DocumentationCondition, DocumentationContext, DocumentationLink, DocumentationTopic
|
||||
from govoplan_core.core.modules import (
|
||||
DocumentationCondition,
|
||||
DocumentationConfigurationDecision,
|
||||
DocumentationContext,
|
||||
DocumentationLink,
|
||||
DocumentationTopic,
|
||||
)
|
||||
from govoplan_mail.backend.mail_profiles import (
|
||||
EffectiveMailProfilePolicy,
|
||||
MailProfileError,
|
||||
@@ -35,6 +41,60 @@ def documentation_topics(context: DocumentationContext) -> tuple[DocumentationTo
|
||||
return tuple(topics)
|
||||
|
||||
|
||||
def documentation_configuration_states(
|
||||
context: DocumentationContext,
|
||||
keys: tuple[str, ...],
|
||||
) -> dict[str, DocumentationConfigurationDecision]:
|
||||
if "mail_profile_policy" not in keys:
|
||||
return {}
|
||||
principal = context.principal
|
||||
tenant_id = str(getattr(principal, "tenant_id", "") or "")
|
||||
session = context.session
|
||||
if not tenant_id or not isinstance(session, Session):
|
||||
return {
|
||||
"mail_profile_policy": DocumentationConfigurationDecision(
|
||||
key="mail_profile_policy",
|
||||
state="unavailable",
|
||||
reason="The effective tenant policy cannot be evaluated in this context.",
|
||||
)
|
||||
}
|
||||
try:
|
||||
policy = effective_mail_profile_policy_for_scope(
|
||||
session,
|
||||
tenant_id=tenant_id,
|
||||
scope_type="tenant",
|
||||
)
|
||||
except MailProfileError:
|
||||
return {
|
||||
"mail_profile_policy": DocumentationConfigurationDecision(
|
||||
key="mail_profile_policy",
|
||||
state="unavailable",
|
||||
reason="The effective tenant policy could not be evaluated.",
|
||||
)
|
||||
}
|
||||
tenant_sources = [
|
||||
source
|
||||
for source in policy.source_policies
|
||||
if source.get("scope_type") == "tenant"
|
||||
]
|
||||
explicitly_configured = any(
|
||||
bool(source.get("applied_fields"))
|
||||
for source in tenant_sources
|
||||
)
|
||||
return {
|
||||
"mail_profile_policy": DocumentationConfigurationDecision(
|
||||
key="mail_profile_policy",
|
||||
state="enabled" if explicitly_configured else "inherited",
|
||||
source="tenant" if explicitly_configured else "system default",
|
||||
reason=(
|
||||
"A tenant policy is configured."
|
||||
if explicitly_configured
|
||||
else "The tenant uses the inherited system policy."
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
def _tenant_mail_policy_topic(context: DocumentationContext) -> DocumentationTopic | None:
|
||||
principal = context.principal
|
||||
tenant_id = str(getattr(principal, "tenant_id", "") or "")
|
||||
|
||||
Reference in New Issue
Block a user