Rework of d61fbd3's dialyzer suppression: the 4 warnings from
LiveTable.LiveResource's macro expansion are now fixed at the
root rather than hidden via .dialyzer_ignore.exs.
Changes:
- Delete .dialyzer_ignore.exs and remove ignore_warnings from
mix.exs. No more hidden suppressions.
- New MicrowavepropWeb.LiveTableResource shim that wraps
use LiveTable.LiveResource and overrides:
* maybe_subscribe/1 — explicit :ok = on Phoenix.PubSub.subscribe/2
(previously discarded, tripping :unmatched_return).
* handle_info/2 — explicit _ = on File.rm, Process.send_after.
Switch all 4 LiveTable-using LiveViews (contact_live/index,
beacon_live/index, admin/contact_edit_live, user_management_live/index)
to use MicrowavepropWeb.LiveTableResource instead.
- New priv/dep_patches/live_table-0.4.1.patch adds _ = in front of
LiveTable.LiveSelectHelpers.restore_live_select_from_params/2 in
the dep's macro-expanded handle_params/3. The call's return was
silently discarded, tripping the fourth warning per LiveView.
- New lib/mix/tasks/deps.patch.ex applies every
priv/dep_patches/*.patch to its target dep idempotently after
mix deps.get. Wired into the :setup alias + overridden
mix deps.get so the patch survives cache regeneration in CI.
- Other modified files in this commit are the spec-coverage
additions from the parallel agent pass (beacons.ex,
commercial.ex, propagation.ex, weather.ex, narr_client.ex,
run_timing.ex, 3 workers) — tighter specs for bounds, tuple
shapes, schema-typed params. Dialyzer remains at 0 after
the changes.
Upstream TODO: send a PR for the live_table `_ =` fix. Once
merged and released, drop the patch + mix task + bump the dep.
mix dialyzer --format short | grep ^lib/ | wc -l -> 0
mix test: 2165 tests, 2 pre-existing flakes (MapLive timestamp +
PropagationPrune ScoresFile), 0 regressions.
103 lines
2.6 KiB
Elixir
103 lines
2.6 KiB
Elixir
defmodule MicrowavepropWeb.UserManagementLive.Index do
|
|
@moduledoc false
|
|
use MicrowavepropWeb, :live_view
|
|
use MicrowavepropWeb.LiveTableResource, schema: Microwaveprop.Accounts.User
|
|
|
|
alias Microwaveprop.Accounts
|
|
|
|
def table_options do
|
|
%{exports: %{formats: [:csv]}}
|
|
end
|
|
|
|
@impl true
|
|
def mount(_params, _session, socket) do
|
|
{:ok, assign(socket, :page_title, "Users")}
|
|
end
|
|
|
|
def fields do
|
|
[
|
|
id: %{label: "ID", hidden: true},
|
|
callsign: %{label: "Callsign", sortable: true, searchable: true},
|
|
name: %{label: "Name", sortable: true, searchable: true},
|
|
email: %{label: "Email", sortable: true, searchable: true},
|
|
is_admin: %{label: "Admin", sortable: true, renderer: &admin_badge/1},
|
|
confirmed_at: %{label: "Confirmed", sortable: true, renderer: &confirmed_cell/1}
|
|
]
|
|
end
|
|
|
|
def filters, do: []
|
|
|
|
def actions do
|
|
[
|
|
edit: fn %{record: user} ->
|
|
assigns = %{user: user}
|
|
|
|
~H"""
|
|
<.link navigate={~p"/users/#{@user.id}/edit"} class="btn btn-xs btn-ghost">Edit</.link>
|
|
"""
|
|
end,
|
|
delete: fn %{record: user} ->
|
|
assigns = %{user: user}
|
|
|
|
~H"""
|
|
<.link
|
|
phx-click={JS.push("delete", value: %{id: @user.id})}
|
|
data-confirm={"Delete user #{@user.callsign}? This cannot be undone."}
|
|
class="btn btn-xs btn-ghost text-error"
|
|
>
|
|
Delete
|
|
</.link>
|
|
"""
|
|
end
|
|
]
|
|
end
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<Layouts.app flash={@flash} current_scope={@current_scope} max_width="max-w-6xl">
|
|
<.header>
|
|
Users
|
|
<:subtitle>Manage registered accounts and admin flags.</:subtitle>
|
|
</.header>
|
|
|
|
<.live_table
|
|
fields={fields()}
|
|
filters={filters()}
|
|
options={@options}
|
|
streams={@streams}
|
|
actions={actions()}
|
|
/>
|
|
</Layouts.app>
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def handle_event("delete", %{"id" => id}, socket) do
|
|
user = Accounts.get_user!(id)
|
|
|
|
if user.id == socket.assigns.current_scope.user.id do
|
|
{:noreply, put_flash(socket, :error, "You cannot delete your own account here.")}
|
|
else
|
|
{:ok, _} = Accounts.delete_user(user)
|
|
{:noreply, stream_delete(socket, :resources, user)}
|
|
end
|
|
end
|
|
|
|
defp admin_badge(true) do
|
|
assigns = %{}
|
|
|
|
~H|<span class="badge badge-primary badge-sm">admin</span>|
|
|
end
|
|
|
|
defp admin_badge(_), do: Phoenix.HTML.raw("<span class=\"opacity-50\">—</span>")
|
|
|
|
defp confirmed_cell(nil) do
|
|
assigns = %{}
|
|
|
|
~H|<span class="opacity-50">pending</span>|
|
|
end
|
|
|
|
defp confirmed_cell(%DateTime{} = dt), do: Calendar.strftime(dt, "%Y-%m-%d")
|
|
defp confirmed_cell(_), do: ""
|
|
end
|