iUUUUpdatexz
DevPlace CI / test (push) Failing after 1h2m3s

This commit is contained in:
2026-08-07 10:53:43 +02:00
parent b777a5b9d0
commit 21f6ae0615
57 changed files with 4050 additions and 165 deletions
+1
View File
@@ -153,6 +153,7 @@ The profile **Media** tab (`/profile/{username}?tab=media`, public) is a paginat
- `owns(item, user)` (= `content.is_owner`) - per-item ownership (e.g. each comment). Page-level detail templates keep using the `is_owner` **bool** passed in their context (post/gist/project/profile); do not call `is_owner(...)` as a function - that name is a context bool and shadows globals.
- `is_self(user, uid)` - "is this me" (profile follow vs edit, leaderboard highlight).
- `guest_disabled(user)` -> emits ` disabled aria-disabled="true" title="Log in to participate"` for guests (empty for members); `login_hint(user)` -> a small login link. Both return `Markup`.
- **Account enabled/disabled is `database.is_account_active(row)` - never read `is_active` inline.** `is_active` is a nullable column, so a row written before it existed (or by any insert that omits it) holds SQL `NULL`, and the obvious `bool(row.get("is_active"))` reads that as *disabled*. `.get("is_active", True)` is no better: the default only applies when the key is **absent**, and a `SELECT *` row always has the key with value `None`. The predicate is `is_active is None or bool(is_active)` - unknown means active, only an explicit `0`/`False` disables. This is the same NULL-vs-0 trap as the `COALESCE` rule for atomic updates. It gates session auth, API-key auth, Basic auth, the login and access-token routes, the devRant token/auth paths, the admin enable/disable toggle, and `_can_hold_primary_admin`; every one of them goes through this single function. A NULL row previously could not log in at all, and the admin toggle could not disable it. (The `is_active` on a `gateway_models` row is a different table with its own semantics and is deliberately not routed through this.)
- **Role values are stored capitalized:** `users.role` is exactly `"Admin"` or `"Member"` (first registered user is `"Admin"`, `auth.py`); `is_admin` compares `== "Admin"` case-sensitively. The CLI is the only lowercase surface (`devplace role set ... <member|admin>` writes `role.capitalize()`; `role get` prints `.lower()`). A lowercase role in the DB silently defeats every admin check - never write a raw lowercase role.
- **The shadow rule generalizes beyond `is_owner` to ANY Jinja global** (`is_admin`, `avatar_url`, `format_date`, `is_self`, `owns`, `guest_disabled`): `respond(req, tmpl, ctx, model=XOut)` hands the **same** `ctx` to the Pydantic model and the template, and a context key shadows the same-named global across the whole `base.html` chain. A bool named `is_admin` in the context makes `base.html`'s `{% if is_admin(user) %}` raise `TypeError: 'bool' object is not callable` - a 500 that only fires for the branch invoking the global (logged-in users, not guests, which is why guest-only smoke tests miss it). Name viewer/permission flags distinctly (`viewer_is_admin`) in both schema and context. Real issue fixed on `/issues/{number}`; regression-guarded by `tests/api/issues/create.py::test_issue_detail_renders_for_{member,admin}` (they render the page as an authenticated Member/Admin and assert 200 + the admin-only control).
- **Policy enforced everywhere:** guests see all non-admin content read-only with action controls **shown but disabled** (`guest_disabled` on vote/star/react/poll/bookmark/follow/comment submit; create FABs become `/auth/login` links via `.feed-fab.login-required`); members get full member actions; **role badges render only to admin viewers** (`{% if is_admin(user) %}` around every `*.role` label). Backend stays the real gate (`require_user`/`require_admin`).
+2 -1
View File
@@ -4,7 +4,7 @@ from .core import dataset, logging, Path, or_, defaultdict, datetime, timedelta,
from .core import refresh_snapshot, _local_cache_versions, _cache_version_cache, _cache_state_ready, _ensure_cache_state, get_cache_version, bump_cache_version, sync_local_cache, _index, _drop_index, _uid_index, get_table, _in_clause, _now_iso
from .atomic import conditional_update_row
from .settings import _settings_cache, get_setting, get_int_setting, set_setting, clear_settings_cache, internal_gateway_key
from .users import get_users_by_uids, _admins_cache, invalidate_admins_cache, get_admin_uids, set_user_timezone, set_last_seen, get_online_users, get_primary_admin_uid, search_users_by_username
from .users import get_users_by_uids, _admins_cache, invalidate_admins_cache, get_admin_uids, set_user_timezone, set_last_seen, get_online_users, get_primary_admin_uid, is_account_active, search_users_by_username
from .relations import _relations_cache, get_user_relations, get_blocked_uids, get_muted_uids, get_silenced_uids, invalidate_user_relations
from .pagination import PAGE_SIZE, paginate, interleave_by_author, paginate_diverse, get_user_post_count, clear_user_post_count, build_pagination
from .soft_delete import SOFT_DELETE_TABLES, ensure_soft_delete_columns, soft_delete, soft_delete_in, restore, purge, list_deleted, count_deleted, restore_event, purge_event
@@ -88,6 +88,7 @@ __all__ = [
"set_last_seen",
"get_online_users",
"get_primary_admin_uid",
"is_account_active",
"search_users_by_username",
"_relations_cache",
"get_user_relations",
+1
View File
@@ -19,6 +19,7 @@ NOTIFICATION_TYPES = [
{"key": "harvest_stolen", "label": "Farm raids", "description": "Someone steals a ready build from your Code Farm"},
{"key": "award", "label": "Awards", "description": "Someone gives you an award on your profile"},
{"key": "quiz_attempt", "label": "Quiz attempts", "description": "Someone completes one of your quizzes"},
{"key": "workspace", "label": "Dev workspaces", "description": "Idle, quota, retention and moderation notices for your dev workspaces"},
{"key": "system", "label": "System alerts", "description": "Platform infrastructure alerts (e.g. the AI gateway going down)"},
]
+99
View File
@@ -568,10 +568,109 @@ def init_db():
("boot_language", "none"),
("boot_script", ""),
("start_on_boot", 0),
("is_workspace", 0),
("workspace_owner_uid", ""),
("editor_port", 0),
("editor_host_port", 0),
("tunnel_name", ""),
("last_active_at", ""),
("idle_warned_at", ""),
("delete_warned_at", ""),
("disk_bytes", 0),
("disk_sampled_at", ""),
("egress_bytes", 0),
("request_count", 0),
("flagged_at", ""),
("flag_reason", ""),
("suspended_at", ""),
("suspended_by", ""),
):
if not instances.has_column(column):
instances.create_column_by_example(column, example)
tunnels = get_table("tunnels")
for column, example in (
("uid", ""),
("instance_uid", ""),
("project_uid", ""),
("user_uid", ""),
("hostname", ""),
("label", ""),
("container_port", 0),
("desired_state", "present"),
("status", "pending"),
("cert_status", ""),
("cert_checked_at", ""),
("request_count", 0),
("bytes_out", 0),
("last_request_at", ""),
("last_error", ""),
("last_synced_at", ""),
("created_at", ""),
("updated_at", ""),
):
if not tunnels.has_column(column):
tunnels.create_column_by_example(column, example)
quota_rules = get_table("workspace_quota_rules")
for column, example in (
("uid", ""),
("owner_kind", ""),
("owner_id", ""),
("label", ""),
("max_workspaces", 0),
("max_tunnels", 0),
("disk_quota_mb", 0),
("egress_quota_mb", 0),
("idle_stop_minutes", 0),
("retention_days", 0),
("created_at", ""),
("updated_at", ""),
):
if not quota_rules.has_column(column):
quota_rules.create_column_by_example(column, example)
flags = get_table("workspace_flags")
for column, example in (
("uid", ""),
("instance_uid", ""),
("user_uid", ""),
("kind", ""),
("severity", "warn"),
("detail", ""),
("metric_value", 0.0),
("threshold", 0.0),
("status", "open"),
("resolved_by", ""),
("resolved_at", ""),
("created_at", ""),
("updated_at", ""),
):
if not flags.has_column(column):
flags.create_column_by_example(column, example)
_index(db, "instances", "idx_instances_workspace", ["is_workspace", "status"])
_index(db, "instances", "idx_instances_workspace_owner", ["workspace_owner_uid"])
_index(db, "instances", "idx_instances_tunnel_name", ["tunnel_name"])
_index(db, "tunnels", "idx_tunnels_hostname", ["hostname"])
_index(db, "tunnels", "idx_tunnels_instance", ["instance_uid"])
_index(db, "tunnels", "idx_tunnels_user", ["user_uid"])
_index(db, "tunnels", "idx_tunnels_state", ["desired_state", "status"])
_index(
db,
"workspace_quota_rules",
"idx_workspace_quota_owner",
["owner_kind", "owner_id"],
)
_index(db, "workspace_flags", "idx_workspace_flags_open", ["status", "created_at"])
_index(
db,
"workspace_flags",
"idx_workspace_flags_instance",
["instance_uid", "kind"],
)
_index(db, "workspace_flags", "idx_workspace_flags_user", ["user_uid"])
_index(db, "instances", "idx_instances_project", ["project_uid"])
_index(db, "instances", "idx_instances_slug", ["slug"])
_index(db, "instances", "idx_instances_name", ["name"])
+2
View File
@@ -23,6 +23,8 @@ SOFT_DELETE_TABLES = [
"sessions",
"instances",
"instance_schedules",
"tunnels",
"workspace_flags",
"backup_schedules",
"devii_conversations",
"devii_tasks",
+6 -4
View File
@@ -74,13 +74,15 @@ def get_online_users(cutoff_iso: str, limit: int = 30) -> list:
)
def is_account_active(row) -> bool:
is_active = (row or {}).get("is_active")
return is_active is None or bool(is_active)
def _can_hold_primary_admin(row, tracks_active):
if row.get("deleted_at"):
return False
if not tracks_active:
return True
is_active = row.get("is_active")
return is_active is None or bool(is_active)
return not tracks_active or is_account_active(row)
def get_primary_admin_uid():