gitea user and pswd, some pages removed, logs

This commit is contained in:
JiriUhlir
2026-06-17 11:39:52 +02:00
parent 23bbcad835
commit 7897e3b876
18 changed files with 601 additions and 457 deletions
+73
View File
@@ -434,6 +434,79 @@ def get_job_logs_after(job_id: int, last_log_id: int = 0, limit: int = 100):
return [dict(row) for row in rows]
def _job_log_filters(query: str | None, stream: str | None, job_id: int | None) -> tuple[str, list[Any]]:
filters = []
params: list[Any] = []
if query:
filters.append("l.message LIKE ?")
params.append(f"%{query}%")
if stream:
filters.append("l.stream = ?")
params.append(stream)
if job_id:
filters.append("l.job_id = ?")
params.append(job_id)
where_sql = f"WHERE {' AND '.join(filters)}" if filters else ""
return where_sql, params
def search_job_logs(
query: str | None = None,
stream: str | None = None,
job_id: int | None = None,
limit: int = 100,
offset: int = 0,
):
"""Globální prohlížeč logů: hledá řádky napříč všemi úlohami a vrací je i s kontextem úlohy
(typ, cíl, stav) seřazené od nejnovějších, aby se šlo proklikat na konkrétní řádek úlohy."""
run_migrations()
con = get_connection()
where_sql, params = _job_log_filters(query, stream, job_id)
rows = con.execute(
f"""
SELECT
l.id,
l.job_id,
l.stream,
l.message,
l.created_at,
j.type AS job_type,
j.target_type AS target_type,
j.target_id AS target_id,
j.status AS job_status
FROM job_logs l
JOIN jobs j ON j.id = l.job_id
{where_sql}
ORDER BY l.id DESC
LIMIT ? OFFSET ?
""",
(*params, limit, offset),
).fetchall()
con.close()
return [dict(row) for row in rows]
def count_job_logs(
query: str | None = None,
stream: str | None = None,
job_id: int | None = None,
) -> int:
run_migrations()
con = get_connection()
where_sql, params = _job_log_filters(query, stream, job_id)
row = con.execute(
f"""
SELECT COUNT(*) AS count
FROM job_logs l
JOIN jobs j ON j.id = l.job_id
{where_sql}
""",
params,
).fetchone()
con.close()
return int(row["count"] or 0) if row else 0
def has_active_deploy_job(target_type: str, target_id: str):
run_migrations()
con = get_connection()
+2
View File
@@ -25,6 +25,7 @@ def ensure_user_columns(con) -> None:
provider_subject TEXT,
avatar_url TEXT,
gitea_user_id INTEGER,
gitea_username TEXT,
gitea_sync_status TEXT NOT NULL DEFAULT 'not_required',
gitea_sync_error TEXT,
gitea_synced_at TEXT
@@ -50,6 +51,7 @@ def ensure_user_columns(con) -> None:
"provider_subject": "TEXT",
"avatar_url": "TEXT",
"gitea_user_id": "INTEGER",
"gitea_username": "TEXT",
"gitea_sync_status": "TEXT NOT NULL DEFAULT 'not_required'",
"gitea_sync_error": "TEXT",
"gitea_synced_at": "TEXT",
+21
View File
@@ -22,6 +22,7 @@ def list_users() -> list[dict[str, Any]]:
provider_subject_select = "provider_subject" if "provider_subject" in columns else "NULL AS provider_subject"
avatar_url_select = "avatar_url" if "avatar_url" in columns else "NULL AS avatar_url"
gitea_user_id_select = "gitea_user_id" if "gitea_user_id" in columns else "NULL AS gitea_user_id"
gitea_username_select = "gitea_username" if "gitea_username" in columns else "NULL AS gitea_username"
gitea_sync_status_select = "gitea_sync_status" if "gitea_sync_status" in columns else "'not_required' AS gitea_sync_status"
gitea_sync_error_select = "gitea_sync_error" if "gitea_sync_error" in columns else "NULL AS gitea_sync_error"
gitea_synced_at_select = "gitea_synced_at" if "gitea_synced_at" in columns else "NULL AS gitea_synced_at"
@@ -42,6 +43,7 @@ def list_users() -> list[dict[str, Any]]:
{provider_subject_select},
{avatar_url_select},
{gitea_user_id_select},
{gitea_username_select},
{gitea_sync_status_select},
{gitea_sync_error_select},
{gitea_synced_at_select}
@@ -63,6 +65,7 @@ def get_user(user_id: int) -> dict[str, Any] | None:
provider_subject_select = "provider_subject" if "provider_subject" in columns else "NULL AS provider_subject"
avatar_url_select = "avatar_url" if "avatar_url" in columns else "NULL AS avatar_url"
gitea_user_id_select = "gitea_user_id" if "gitea_user_id" in columns else "NULL AS gitea_user_id"
gitea_username_select = "gitea_username" if "gitea_username" in columns else "NULL AS gitea_username"
gitea_sync_status_select = "gitea_sync_status" if "gitea_sync_status" in columns else "'not_required' AS gitea_sync_status"
gitea_sync_error_select = "gitea_sync_error" if "gitea_sync_error" in columns else "NULL AS gitea_sync_error"
gitea_synced_at_select = "gitea_synced_at" if "gitea_synced_at" in columns else "NULL AS gitea_synced_at"
@@ -83,6 +86,7 @@ def get_user(user_id: int) -> dict[str, Any] | None:
{provider_subject_select},
{avatar_url_select},
{gitea_user_id_select},
{gitea_username_select},
{gitea_sync_status_select},
{gitea_sync_error_select},
{gitea_synced_at_select}
@@ -164,6 +168,23 @@ def delete_user(user_id: int) -> None:
con.close()
def set_gitea_username(user_id: int, gitea_username: str) -> None:
"""Uloží vlastní Gitea uživatelské jméno (handle). Prázdná hodnota = vrácení na automatické portal-{id}."""
run_migrations()
con = get_connection()
con.execute(
"""
UPDATE users
SET gitea_username = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
""",
((gitea_username or "").strip() or None, user_id),
)
con.commit()
con.close()
def update_gitea_sync_state(
user_id: int,
status: str,