Merge dev into main for release
This commit is contained in:
@@ -28,3 +28,6 @@ ADMIN_BOOTSTRAP_RESET=false
|
|||||||
EDITOR_TIP_MAX_LENGTH=10000
|
EDITOR_TIP_MAX_LENGTH=10000
|
||||||
# Maximale Länge für Highlights
|
# Maximale Länge für Highlights
|
||||||
HIGHLIGHTS_MAX_LENGTH=5000
|
HIGHLIGHTS_MAX_LENGTH=5000
|
||||||
|
# Standardmäßig ausgeschlossene Bearbeiter (kommagetrennt)
|
||||||
|
# Beispiel: Aranzinger, Testuser
|
||||||
|
DEFAULT_EXCLUDED_USERS=Aranzinger
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class Settings(BaseSettings):
|
|||||||
admin_bootstrap_reset: bool = False
|
admin_bootstrap_reset: bool = False
|
||||||
editor_tip_max_length: int = 10000
|
editor_tip_max_length: int = 10000
|
||||||
highlights_max_length: int = 5000
|
highlights_max_length: int = 5000
|
||||||
|
default_excluded_users: str = "Aranzinger"
|
||||||
|
|
||||||
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
|
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
|
||||||
|
|
||||||
|
|||||||
26
app/main.py
26
app/main.py
@@ -36,6 +36,7 @@ from app.services.newsletter import (
|
|||||||
create_plain_text,
|
create_plain_text,
|
||||||
create_subject,
|
create_subject,
|
||||||
filter_articles,
|
filter_articles,
|
||||||
|
parse_excluded_users,
|
||||||
parse_display_options,
|
parse_display_options,
|
||||||
parse_highlights,
|
parse_highlights,
|
||||||
resolve_period,
|
resolve_period,
|
||||||
@@ -117,6 +118,7 @@ async def _run_scheduled_send_if_due() -> None:
|
|||||||
editor_tip="",
|
editor_tip="",
|
||||||
highlight_list=[],
|
highlight_list=[],
|
||||||
contact_email=settings_snapshot.get("reply_to") or settings_snapshot.get("from_email", ""),
|
contact_email=settings_snapshot.get("reply_to") or settings_snapshot.get("from_email", ""),
|
||||||
|
excluded_users_raw=settings_snapshot.get("gen_excluded_users", ""),
|
||||||
)
|
)
|
||||||
if gen["wiki_error"] or not gen["articles"]:
|
if gen["wiki_error"] or not gen["articles"]:
|
||||||
# Kein Versand ohne Inhalt; erneuter Versuch beim nächsten Intervall.
|
# Kein Versand ohne Inhalt; erneuter Versuch beim nächsten Intervall.
|
||||||
@@ -360,6 +362,7 @@ def _empty_filters() -> dict:
|
|||||||
"period": "last_month",
|
"period": "last_month",
|
||||||
"article_type": "new",
|
"article_type": "new",
|
||||||
"category": "",
|
"category": "",
|
||||||
|
"excluded_users": settings.default_excluded_users,
|
||||||
"display": DEFAULT_DISPLAY,
|
"display": DEFAULT_DISPLAY,
|
||||||
"editor_tip": "",
|
"editor_tip": "",
|
||||||
"highlights": "",
|
"highlights": "",
|
||||||
@@ -376,6 +379,7 @@ async def _generate_newsletter(
|
|||||||
editor_tip: str,
|
editor_tip: str,
|
||||||
highlight_list: list[str],
|
highlight_list: list[str],
|
||||||
contact_email: str = "",
|
contact_email: str = "",
|
||||||
|
excluded_users_raw: str = "",
|
||||||
) -> dict:
|
) -> dict:
|
||||||
p = resolve_period(period_mode, days)
|
p = resolve_period(period_mode, days)
|
||||||
result = {
|
result = {
|
||||||
@@ -390,11 +394,12 @@ async def _generate_newsletter(
|
|||||||
"subject": "",
|
"subject": "",
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
|
excluded_users = parse_excluded_users(excluded_users_raw)
|
||||||
articles = await wiki_service.get_recent_changes(
|
articles = await wiki_service.get_recent_changes(
|
||||||
days=p["days"], article_type=article_type, start=p["start"], end=p["end"]
|
days=p["days"], article_type=article_type, start=p["start"], end=p["end"]
|
||||||
)
|
)
|
||||||
filtered = filter_articles(articles, category_filter=category or None)
|
filtered = filter_articles(articles, category_filter=category or None)
|
||||||
new_articles, edited_articles = split_articles_by_type(filtered)
|
new_articles, edited_articles = split_articles_by_type(filtered, excluded_edited_users=excluded_users)
|
||||||
prange = (p["start_str"], p["end_str"])
|
prange = (p["start_str"], p["end_str"])
|
||||||
result.update(
|
result.update(
|
||||||
{
|
{
|
||||||
@@ -402,9 +407,15 @@ async def _generate_newsletter(
|
|||||||
"articles_new": new_articles,
|
"articles_new": new_articles,
|
||||||
"articles_edited": edited_articles,
|
"articles_edited": edited_articles,
|
||||||
"subject": create_subject(p["month_label"], p["days"]),
|
"subject": create_subject(p["month_label"], p["days"]),
|
||||||
"plain_text": create_plain_text(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, contact_email),
|
"plain_text": create_plain_text(
|
||||||
"raw_html": create_html(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, p["month_label"], contact_email),
|
filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, contact_email, excluded_users
|
||||||
"outlook_html": create_outlook_html(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, p["month_label"], contact_email),
|
),
|
||||||
|
"raw_html": create_html(
|
||||||
|
filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, p["month_label"], contact_email, excluded_users
|
||||||
|
),
|
||||||
|
"outlook_html": create_outlook_html(
|
||||||
|
filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, p["month_label"], contact_email, excluded_users
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
except WikiFetchError as exc:
|
except WikiFetchError as exc:
|
||||||
@@ -444,6 +455,7 @@ async def dashboard_generate(
|
|||||||
days: int = Form(30),
|
days: int = Form(30),
|
||||||
article_type: str = Form("all"),
|
article_type: str = Form("all"),
|
||||||
category: str = Form(""),
|
category: str = Form(""),
|
||||||
|
excluded_users: str = Form(""),
|
||||||
show_date: str | None = Form(None),
|
show_date: str | None = Form(None),
|
||||||
show_user: str | None = Form(None),
|
show_user: str | None = Form(None),
|
||||||
show_category: str | None = Form(None),
|
show_category: str | None = Form(None),
|
||||||
@@ -474,6 +486,7 @@ async def dashboard_generate(
|
|||||||
editor_tip=editor_tip,
|
editor_tip=editor_tip,
|
||||||
highlight_list=highlight_list,
|
highlight_list=highlight_list,
|
||||||
contact_email=contact_email,
|
contact_email=contact_email,
|
||||||
|
excluded_users_raw=excluded_users,
|
||||||
)
|
)
|
||||||
|
|
||||||
context = _base_context(request, current_user, db)
|
context = _base_context(request, current_user, db)
|
||||||
@@ -491,6 +504,7 @@ async def dashboard_generate(
|
|||||||
"period": period,
|
"period": period,
|
||||||
"article_type": article_type,
|
"article_type": article_type,
|
||||||
"category": category,
|
"category": category,
|
||||||
|
"excluded_users": excluded_users,
|
||||||
"display": display,
|
"display": display,
|
||||||
"editor_tip": editor_tip,
|
"editor_tip": editor_tip,
|
||||||
"highlights": highlights,
|
"highlights": highlights,
|
||||||
@@ -511,6 +525,7 @@ async def send_now(
|
|||||||
days: int = Form(30),
|
days: int = Form(30),
|
||||||
article_type: str = Form("all"),
|
article_type: str = Form("all"),
|
||||||
category: str = Form(""),
|
category: str = Form(""),
|
||||||
|
excluded_users: str = Form(""),
|
||||||
show_date: str | None = Form(None),
|
show_date: str | None = Form(None),
|
||||||
show_user: str | None = Form(None),
|
show_user: str | None = Form(None),
|
||||||
show_category: str | None = Form(None),
|
show_category: str | None = Form(None),
|
||||||
@@ -541,6 +556,7 @@ async def send_now(
|
|||||||
editor_tip=editor_tip,
|
editor_tip=editor_tip,
|
||||||
highlight_list=highlight_list,
|
highlight_list=highlight_list,
|
||||||
contact_email=contact_email,
|
contact_email=contact_email,
|
||||||
|
excluded_users_raw=excluded_users,
|
||||||
)
|
)
|
||||||
|
|
||||||
send_result: dict[str, str]
|
send_result: dict[str, str]
|
||||||
@@ -585,6 +601,7 @@ def update_smtp_settings(
|
|||||||
gen_days: str = Form("30"),
|
gen_days: str = Form("30"),
|
||||||
gen_article_type: str = Form("all"),
|
gen_article_type: str = Form("all"),
|
||||||
gen_category: str = Form(""),
|
gen_category: str = Form(""),
|
||||||
|
gen_excluded_users: str = Form(""),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
admin: User = Depends(get_admin_user),
|
admin: User = Depends(get_admin_user),
|
||||||
):
|
):
|
||||||
@@ -631,6 +648,7 @@ def update_smtp_settings(
|
|||||||
gen_article_type = "all"
|
gen_article_type = "all"
|
||||||
set_config(db, "smtp.gen_article_type", gen_article_type)
|
set_config(db, "smtp.gen_article_type", gen_article_type)
|
||||||
set_config(db, "smtp.gen_category", gen_category.strip())
|
set_config(db, "smtp.gen_category", gen_category.strip())
|
||||||
|
set_config(db, "smtp.gen_excluded_users", gen_excluded_users.strip())
|
||||||
return RedirectResponse(url="/dashboard", status_code=status.HTTP_302_FOUND)
|
return RedirectResponse(url="/dashboard", status_code=status.HTTP_302_FOUND)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -76,11 +76,21 @@ def filter_articles(
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def split_articles_by_type(articles: list[dict[str, Any]]) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
|
def parse_excluded_users(raw: str | None) -> set[str]:
|
||||||
|
if not raw:
|
||||||
|
return set()
|
||||||
|
return {part.strip().lower() for part in raw.split(",") if part.strip()}
|
||||||
|
|
||||||
|
|
||||||
|
def split_articles_by_type(
|
||||||
|
articles: list[dict[str, Any]],
|
||||||
|
excluded_edited_users: set[str] | None = None,
|
||||||
|
) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
|
||||||
sorted_articles = sorted(articles, key=lambda a: a.get("timestamp", ""), reverse=True)
|
sorted_articles = sorted(articles, key=lambda a: a.get("timestamp", ""), reverse=True)
|
||||||
new_articles: list[dict[str, Any]] = []
|
new_articles: list[dict[str, Any]] = []
|
||||||
edited_articles: list[dict[str, Any]] = []
|
edited_articles: list[dict[str, Any]] = []
|
||||||
new_titles: set[str] = set()
|
new_titles: set[str] = set()
|
||||||
|
excluded_edited_users = excluded_edited_users or set()
|
||||||
|
|
||||||
for item in sorted_articles:
|
for item in sorted_articles:
|
||||||
title = item.get("title", "")
|
title = item.get("title", "")
|
||||||
@@ -93,8 +103,11 @@ def split_articles_by_type(articles: list[dict[str, Any]]) -> tuple[list[dict[st
|
|||||||
seen_edited: set[str] = set()
|
seen_edited: set[str] = set()
|
||||||
for item in sorted_articles:
|
for item in sorted_articles:
|
||||||
title = item.get("title", "")
|
title = item.get("title", "")
|
||||||
|
editor = str(item.get("user", "")).strip().lower()
|
||||||
if not title or title in new_titles or title in seen_edited:
|
if not title or title in new_titles or title in seen_edited:
|
||||||
continue
|
continue
|
||||||
|
if editor in excluded_edited_users:
|
||||||
|
continue
|
||||||
edited_articles.append(item)
|
edited_articles.append(item)
|
||||||
seen_edited.add(title)
|
seen_edited.add(title)
|
||||||
|
|
||||||
@@ -204,9 +217,10 @@ def create_plain_text(
|
|||||||
period: tuple[str, str] | None = None,
|
period: tuple[str, str] | None = None,
|
||||||
article_type: str = "all",
|
article_type: str = "all",
|
||||||
contact_email: str = "",
|
contact_email: str = "",
|
||||||
|
excluded_edited_users: set[str] | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
display = display or DEFAULT_DISPLAY
|
display = display or DEFAULT_DISPLAY
|
||||||
new_articles, edited_articles = split_articles_by_type(articles)
|
new_articles, edited_articles = split_articles_by_type(articles, excluded_edited_users=excluded_edited_users)
|
||||||
show_new = article_type in ("all", "new")
|
show_new = article_type in ("all", "new")
|
||||||
show_edited = article_type in ("all", "edited")
|
show_edited = article_type in ("all", "edited")
|
||||||
period_start, period_end = period if period else _period_range(days)
|
period_start, period_end = period if period else _period_range(days)
|
||||||
@@ -308,9 +322,10 @@ def create_html(
|
|||||||
article_type: str = "all",
|
article_type: str = "all",
|
||||||
month_label: str | None = None,
|
month_label: str | None = None,
|
||||||
contact_email: str = "",
|
contact_email: str = "",
|
||||||
|
excluded_edited_users: set[str] | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
display = display or DEFAULT_DISPLAY
|
display = display or DEFAULT_DISPLAY
|
||||||
new_articles, edited_articles = split_articles_by_type(articles)
|
new_articles, edited_articles = split_articles_by_type(articles, excluded_edited_users=excluded_edited_users)
|
||||||
show_new = article_type in ("all", "new")
|
show_new = article_type in ("all", "new")
|
||||||
show_edited = article_type in ("all", "edited")
|
show_edited = article_type in ("all", "edited")
|
||||||
period_start, period_end = period if period else _period_range(days)
|
period_start, period_end = period if period else _period_range(days)
|
||||||
@@ -707,10 +722,11 @@ def create_outlook_html(
|
|||||||
article_type: str = "all",
|
article_type: str = "all",
|
||||||
month_label: str | None = None,
|
month_label: str | None = None,
|
||||||
contact_email: str = "",
|
contact_email: str = "",
|
||||||
|
excluded_edited_users: set[str] | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Word/Outlook-kompatibles HTML mit font-Tags und bgcolor (überlebt Einfügen in Outlook)."""
|
"""Word/Outlook-kompatibles HTML mit font-Tags und bgcolor (überlebt Einfügen in Outlook)."""
|
||||||
display = display or DEFAULT_DISPLAY
|
display = display or DEFAULT_DISPLAY
|
||||||
new_articles, edited_articles = split_articles_by_type(articles)
|
new_articles, edited_articles = split_articles_by_type(articles, excluded_edited_users=excluded_edited_users)
|
||||||
show_new = article_type in ("all", "new")
|
show_new = article_type in ("all", "new")
|
||||||
show_edited = article_type in ("all", "edited")
|
show_edited = article_type in ("all", "edited")
|
||||||
period_start, period_end = period if period else _period_range(days)
|
period_start, period_end = period if period else _period_range(days)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from typing import Sequence
|
|||||||
|
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from app.core.config import settings
|
||||||
from app.core.email_utils import parse_recipient_list
|
from app.core.email_utils import parse_recipient_list
|
||||||
from app.models.system import SendLog
|
from app.models.system import SendLog
|
||||||
from app.services.config_store import get_config
|
from app.services.config_store import get_config
|
||||||
@@ -40,6 +41,7 @@ def get_smtp_settings(db: Session) -> dict[str, str]:
|
|||||||
"gen_days": get_config(db, "smtp.gen_days", "30"),
|
"gen_days": get_config(db, "smtp.gen_days", "30"),
|
||||||
"gen_article_type": get_config(db, "smtp.gen_article_type", "new"),
|
"gen_article_type": get_config(db, "smtp.gen_article_type", "new"),
|
||||||
"gen_category": get_config(db, "smtp.gen_category", ""),
|
"gen_category": get_config(db, "smtp.gen_category", ""),
|
||||||
|
"gen_excluded_users": get_config(db, "smtp.gen_excluded_users", settings.default_excluded_users),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,11 @@
|
|||||||
<label>Kategorie (optional)
|
<label>Kategorie (optional)
|
||||||
<input type="text" name="category" value="{{ filters.category }}" placeholder="z. B. Linux">
|
<input type="text" name="category" value="{{ filters.category }}" placeholder="z. B. Linux">
|
||||||
</label>
|
</label>
|
||||||
|
<label>Bearbeiter ausschließen (optional)
|
||||||
|
<input type="text" name="excluded_users" value="{{ filters.excluded_users }}" placeholder="z. B. Aranzinger, Testuser">
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<p class="hint">Nur bei „Bearbeitete Artikel“ relevant: Benutzer in dieser Liste werden aus den bearbeiteten Artikeln entfernt.</p>
|
||||||
<label>Artikel-Auswahl
|
<label>Artikel-Auswahl
|
||||||
<select name="article_type">
|
<select name="article_type">
|
||||||
<option value="all" {% if filters.article_type == 'all' %}selected{% endif %}>Alle (neue & bearbeitete)</option>
|
<option value="all" {% if filters.article_type == 'all' %}selected{% endif %}>Alle (neue & bearbeitete)</option>
|
||||||
@@ -135,6 +139,7 @@
|
|||||||
<input type="hidden" name="period" value="{{ filters.period }}">
|
<input type="hidden" name="period" value="{{ filters.period }}">
|
||||||
<input type="hidden" name="days" value="{{ filters.days }}">
|
<input type="hidden" name="days" value="{{ filters.days }}">
|
||||||
<input type="hidden" name="category" value="{{ filters.category }}">
|
<input type="hidden" name="category" value="{{ filters.category }}">
|
||||||
|
<input type="hidden" name="excluded_users" value="{{ filters.excluded_users }}">
|
||||||
<input type="hidden" name="article_type" value="{{ filters.article_type }}">
|
<input type="hidden" name="article_type" value="{{ filters.article_type }}">
|
||||||
<input type="hidden" name="show_date" value="{{ 'true' if filters.display.show_date else 'false' }}">
|
<input type="hidden" name="show_date" value="{{ 'true' if filters.display.show_date else 'false' }}">
|
||||||
<input type="hidden" name="show_user" value="{{ 'true' if filters.display.show_user else 'false' }}">
|
<input type="hidden" name="show_user" value="{{ 'true' if filters.display.show_user else 'false' }}">
|
||||||
@@ -339,6 +344,10 @@
|
|||||||
<input type="text" name="gen_category" value="{{ smtp.gen_category }}">
|
<input type="text" name="gen_category" value="{{ smtp.gen_category }}">
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<label>Bearbeiter ausschließen (optional)
|
||||||
|
<input type="text" name="gen_excluded_users" value="{{ smtp.gen_excluded_users }}" placeholder="z. B. Aranzinger, Testuser">
|
||||||
|
</label>
|
||||||
|
<p class="hint" style="margin-top:-0.2rem;">Diese Benutzer werden bei „Bearbeitete Artikel“ ignoriert (gilt für den geplanten Versand).</p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<button type="submit">Einstellungen speichern</button>
|
<button type="submit">Einstellungen speichern</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user