Add editor exclusion defaults and newsletter filtering controls.
This makes it possible to exclude specific editors (e.g. Aranzinger) from edited-article results by default, including dashboard generation and scheduled SMTP runs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
26
app/main.py
26
app/main.py
@@ -36,6 +36,7 @@ from app.services.newsletter import (
|
||||
create_plain_text,
|
||||
create_subject,
|
||||
filter_articles,
|
||||
parse_excluded_users,
|
||||
parse_display_options,
|
||||
parse_highlights,
|
||||
resolve_period,
|
||||
@@ -117,6 +118,7 @@ async def _run_scheduled_send_if_due() -> None:
|
||||
editor_tip="",
|
||||
highlight_list=[],
|
||||
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"]:
|
||||
# Kein Versand ohne Inhalt; erneuter Versuch beim nächsten Intervall.
|
||||
@@ -360,6 +362,7 @@ def _empty_filters() -> dict:
|
||||
"period": "last_month",
|
||||
"article_type": "new",
|
||||
"category": "",
|
||||
"excluded_users": settings.default_excluded_users,
|
||||
"display": DEFAULT_DISPLAY,
|
||||
"editor_tip": "",
|
||||
"highlights": "",
|
||||
@@ -376,6 +379,7 @@ async def _generate_newsletter(
|
||||
editor_tip: str,
|
||||
highlight_list: list[str],
|
||||
contact_email: str = "",
|
||||
excluded_users_raw: str = "",
|
||||
) -> dict:
|
||||
p = resolve_period(period_mode, days)
|
||||
result = {
|
||||
@@ -390,11 +394,12 @@ async def _generate_newsletter(
|
||||
"subject": "",
|
||||
}
|
||||
try:
|
||||
excluded_users = parse_excluded_users(excluded_users_raw)
|
||||
articles = await wiki_service.get_recent_changes(
|
||||
days=p["days"], article_type=article_type, start=p["start"], end=p["end"]
|
||||
)
|
||||
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"])
|
||||
result.update(
|
||||
{
|
||||
@@ -402,9 +407,15 @@ async def _generate_newsletter(
|
||||
"articles_new": new_articles,
|
||||
"articles_edited": edited_articles,
|
||||
"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),
|
||||
"raw_html": create_html(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, p["month_label"], contact_email),
|
||||
"outlook_html": create_outlook_html(filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, p["month_label"], contact_email),
|
||||
"plain_text": create_plain_text(
|
||||
filtered, p["days"], display, category, editor_tip, highlight_list, p["label"], prange, article_type, contact_email, excluded_users
|
||||
),
|
||||
"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:
|
||||
@@ -444,6 +455,7 @@ async def dashboard_generate(
|
||||
days: int = Form(30),
|
||||
article_type: str = Form("all"),
|
||||
category: str = Form(""),
|
||||
excluded_users: str = Form(""),
|
||||
show_date: str | None = Form(None),
|
||||
show_user: str | None = Form(None),
|
||||
show_category: str | None = Form(None),
|
||||
@@ -474,6 +486,7 @@ async def dashboard_generate(
|
||||
editor_tip=editor_tip,
|
||||
highlight_list=highlight_list,
|
||||
contact_email=contact_email,
|
||||
excluded_users_raw=excluded_users,
|
||||
)
|
||||
|
||||
context = _base_context(request, current_user, db)
|
||||
@@ -491,6 +504,7 @@ async def dashboard_generate(
|
||||
"period": period,
|
||||
"article_type": article_type,
|
||||
"category": category,
|
||||
"excluded_users": excluded_users,
|
||||
"display": display,
|
||||
"editor_tip": editor_tip,
|
||||
"highlights": highlights,
|
||||
@@ -511,6 +525,7 @@ async def send_now(
|
||||
days: int = Form(30),
|
||||
article_type: str = Form("all"),
|
||||
category: str = Form(""),
|
||||
excluded_users: str = Form(""),
|
||||
show_date: str | None = Form(None),
|
||||
show_user: str | None = Form(None),
|
||||
show_category: str | None = Form(None),
|
||||
@@ -541,6 +556,7 @@ async def send_now(
|
||||
editor_tip=editor_tip,
|
||||
highlight_list=highlight_list,
|
||||
contact_email=contact_email,
|
||||
excluded_users_raw=excluded_users,
|
||||
)
|
||||
|
||||
send_result: dict[str, str]
|
||||
@@ -585,6 +601,7 @@ def update_smtp_settings(
|
||||
gen_days: str = Form("30"),
|
||||
gen_article_type: str = Form("all"),
|
||||
gen_category: str = Form(""),
|
||||
gen_excluded_users: str = Form(""),
|
||||
db: Session = Depends(get_db),
|
||||
admin: User = Depends(get_admin_user),
|
||||
):
|
||||
@@ -631,6 +648,7 @@ def update_smtp_settings(
|
||||
gen_article_type = "all"
|
||||
set_config(db, "smtp.gen_article_type", gen_article_type)
|
||||
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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user