Ignore file was silencing every warning under lib/towerops/**. Root cause was plt_add_deps: :apps_direct missing Plug/Phoenix/Oban/Decimal /Redix/ssl/public_key — hundreds of false `unknown_function` warnings were being papered over. Expand plt_add_apps to cover the common deps, narrow the ignore file to real dep-PLT gaps only, and fix two concrete bugs uncovered by the change: - ScopedResource.fetch_preload/4: spec was atom() | [atom()] but callers pass keyword lists (e.g. [rules: :targets]). - ToweropsNative: tag NIF stubs with @dialyzer :nowarn_function so dialyzer trusts the @spec instead of the fallback body. Remaining 328 real warnings surface for follow-up.
30 lines
903 B
Elixir
30 lines
903 B
Elixir
defmodule ToweropsWeb.ScopedResource do
|
|
@moduledoc """
|
|
Shared helpers for loading organization-scoped resources.
|
|
"""
|
|
|
|
alias Towerops.Repo
|
|
|
|
@spec fetch(module(), Ecto.UUID.t(), Ecto.UUID.t()) ::
|
|
{:ok, struct()} | {:error, :not_found | :forbidden}
|
|
def fetch(schema, id, organization_id) do
|
|
case Repo.get(schema, id) do
|
|
nil ->
|
|
{:error, :not_found}
|
|
|
|
%{organization_id: ^organization_id} = resource ->
|
|
{:ok, resource}
|
|
|
|
%{organization_id: _other_org_id} ->
|
|
{:error, :forbidden}
|
|
end
|
|
end
|
|
|
|
@spec fetch_preload(module(), Ecto.UUID.t(), Ecto.UUID.t(), atom() | list() | keyword()) ::
|
|
{:ok, struct()} | {:error, :not_found | :forbidden}
|
|
def fetch_preload(schema, id, organization_id, preloads) do
|
|
with {:ok, resource} <- fetch(schema, id, organization_id) do
|
|
{:ok, Repo.preload(resource, preloads)}
|
|
end
|
|
end
|
|
end
|