Comments 0.4.5: Approve and Restore do what they say, and moderation holes closed
Comments 0.4.5 is a quality sweep of the module. The main fix: on the moderation page, Approve and Restore had been wired to each other’s actions, so approving a pending comment did nothing while saying it had worked.
Restore, in turn, published a deleted comment that had never been approved. Both now do what their label says, approving a deleted comment is refused, and each moderation action reports its real outcome instead of always flashing success. Bulk actions go through the same checks as single rows.
Also fixed:
- A logged-out visitor could run Giphy searches on the site’s API key, and a thread kept accepting writes after an admin turned comments off.
- A crafted comment could rename a host record its author had no rights to.
- Malformed events could crash the page hosting a thread.
- The module’s JavaScript hooks did nothing after a LiveView navigation.
- Edit, Delete and Reply were invisible on touch screens; they now show without hover.
- Status badges now show the translated status, and “Edit” is translated.
- A thread no longer runs role queries for every comment on each render.
Full release notes: Comments 0.4.5
0.4.5 · 29 August 2026
A quality sweep across the module (#41) and the post-merge review pass over it. Four of the fixes below close moderation and quota holes that a hidden control was the only thing standing in front of.
Fixed
-
Approve and Restore were wired to each other’s context functions (
Web.Index). With moderation on, Approve calledrestore_comment/2, which setspending— so approving a pending comment did nothing while flashing “Comment approved”, in the one configuration where approving is the point. Restore calledapprove_comment/2and published a deleted comment that had never been approved, the exact bugrestore_comment/2exists to prevent. The audit trail was inverted to match. -
approve_comment/2now refuses a soft-deleted comment with{:error, :comment_deleted}— approving must never mean undeleting. The row menu hides Approve on a deleted row andbulk_approve/2counted such rows as failures, but the single-row handler took whatever uuid the event carried, so a replayedapprovepublished a deleted comment anyway. The rule now lives at the one place every caller passes through; userestore_comment/2to bring a deleted comment back. -
The four single-row moderation handlers reported success unconditionally. Approve/Hide/Delete/Restore discarded the context’s return value and always flashed “Comment approved”. Since
Activity.log_comment/3only logs its{:ok, _}clause, a failed moderation left no audit row, no log line, and told the admin it had worked. All four now route through one helper that flashes the outcome and logs failures. The bulk path was given the same treatment: each bulk action goes through the same context function as its single-row menu item, so bulk Approve no longer publishes deleted comments or logscomment_updatedin place of the moderation action. -
giphy_searchwas reachable by a logged-out visitor, who could drive outbound calls to Giphy with query strings of their choosing against the host’s quota — the picker never renders for them, but the component’s cid is addressable by anyone who can see the page. It now asks the samecan_post?questionadd_commentdoes, and joins the module’s write gate, so a thread left open after an admin turned comments off can no longer bill the host for searches either. -
save_decorationprivilege escalation. The permission check asked “do you own this COMMENT?”, while the host record it renames is selected by looking the comment’s own client-suppliedmetadataup in the host’s decorations map. Posting a comment withmetadata[annotation_uuid]set to someone else’s record, then saving a decoration, renamed a record you have no rights to. Decoration keys are now dropped from client-supplied metadata, keyed on the newdecoration_keysattr — a static declaration, because the decorations registry is built from data and is empty in precisely the window a planted comment needs. Thesend_updatepayload also carriesactor_uuidnow, so the host can answer the question the component cannot. -
Six handlers crashed the host LiveView on a malformed payload —
update_comment_draft,giphy_search,add_commentonmetadata=foo, andtoggle_like/toggle_dislike/reply_to/begin_decoration_editreachingto_string/1on a map, closed at the one choke point (find_comment_in_tree/2).save_edittook a non-binary body intoString.trim/1.create_comment/4raised on a malformedparent_uuidinstead of returning a changeset error. -
The JS hooks were dead on every LiveView navigation. Both registered themselves from an inline
<script>, which works on a hard page load and does nothing on a navigation: morphdom does not execute an inserted script and the LiveSocket hooks map is fixed at construction. They now ship viajs_sources/0and are namespaced (PhoenixKitCommentsInsertAtCursor,PhoenixKitCommentsAudioRecorder), since the fold intowindow.PhoenixKitHooksis last-write-wins across every module’s bundle. -
The module kill switch never reached embedded threads. The component defaulted
enabledtotrue, so hosts embedding it without passingenabled=kept accepting writes after an admin turned comments off — and reading the setting into an assign was not enough either, because aphx-submitreacheshandle_event/3directly andupdate/2does not run first. The gate now asks at event time. -
Edits and deletes made from an embedded thread recorded no actor. The admin page threaded
actor_uuidinto the activity log; the component’s own edit and delete paths passed no opts at all, so the path ordinary users take logged “a comment was deleted” with nobody attached. -
Three “the database may be gone” guards only caught raises. An unowned checkout raises but a dead pool exits, so
enabled?/0,broadcast_change/3andnotify_resource_handler/4did not hold in the case they were written for — the last runs arbitrary host code after the comment has committed, so an exiting handler killed the LiveView for a comment that saved fine. The settings reads on the render path and the post-commit reaction hook got the same treatment.count_comments/3andcount_all_comments/1degraded to zeros silently and now log. -
Role checks cost up to eight queries per comment, recursively per reply, on every re-render — hundreds of role queries per render on a fifty-comment thread. Resolved once per update instead, and re-resolved rather than frozen, so a host that mounts with
current_user: niland sends the user afterwards no longer renders every comment for a stranger. -
link_with_annotation/2appended a client-setannotation_uuidto an href an admin clicks with no format check, so?annotation=x&status=yrode along as extra query params. Now cast withEcto.UUID.cast/1. -
Settings-save errors logged
Exception.message/1, and Ecto exceptions in that class interpolate the offending value — which on that path can be the Giphy API key. The struct name only, now. -
approve_comment/2andhide_comment/2wrote two audit rows each.
Changed
-
Comment card actions are reachable on touch devices. Edit, Delete and Reply are revealed by
group-hover, which a device with no hover never matches — so on a phone or tablet they rendered at zero opacity with no way to reveal them. A[@media(hover:none)]variant now shows them at rest. Nothing changes for a mouse. -
Status badges printed the raw DB enum next to a filter dropdown showing the translated word — a Russian admin saw “Опубликовано” in the filter and “published” in the badge. Resource-type filter labels used
String.capitalize/1, renderingCatalogue_item_supplierwhere the module’s ownhumanize_resource_type/1rendersCatalogue Item Supplier. -
gettext("Edit")had reached no catalogue at all — renamed from"Edit comment"and never re-extracted, soet/rurendered English. Invisible to a.po-vs-.pocheck by construction. Re-extracted, and the fuzzy entriesmix gettext.mergeguessed wrong (ignored at runtime, so they would have rendered English regardless) corrected by hand. -
create_comment/4documents:statusas server-side only. An explicit:statusoverrides the moderation default, so a host forwarding raw user params lets a commenter skip the queue. Behaviour unchanged — dropping it from the cast is a breaking API change — but the hazard is now on record beside:inserted_atand:allow_empty_content. -
phx-disable-withadded to Delete, Remove-resource-path and Reset-defaults.
Added
-
A LiveView test harness, and the first tests to use it. The module had no
Phoenix.LiveViewTestanywhere: the approve/restore swap and the missing actor threading were both invisible to a suite that only tested the context functions, which were correct in isolation. Adds a test endpoint, router, layouts and a host page that embedsCommentsComponentthe way a consuming app does, plus activity-log assertions. Note thatActivity.log/2rescuesDBConnection.OwnershipErrorto:ok, so these run under a shared sandbox or they would pass vacuously. -
Dependency lockfile refresh (no source changes).
Comments 0.4.5. Install or update: {:phoenix_kit_comments, "~> 0.4"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.