fix: properly accept private attributes in admin

This commit is contained in:
Zach Daniel 2024-04-12 12:40:51 -04:00
parent 6e18a3ae53
commit 2abf162c2e
6 changed files with 9027 additions and 45 deletions

View file

@ -1,20 +1,3 @@
defmodule AshAdmin do
@moduledoc false
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
# Define workers and child supervisors to be supervised
# worker(AshAdmin.Worker, [arg1, arg2, arg3]),
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: AshAdmin.Supervisor]
Supervisor.start_link(children, opts)
end
end

View file

@ -1459,12 +1459,8 @@ defmodule AshAdmin.Components.Resource.Form do
[]
end
def relationships(resource, action, nil) do
resource
|> Ash.Resource.Info.relationships()
|> Enum.filter(&(&1.writable? && &1.public?))
|> only_accepted(action)
|> sort_relationships()
def relationships(_resource, _action, _) do
[]
end
defp sort_relationships(relationships) do
@ -1523,7 +1519,7 @@ defmodule AshAdmin.Components.Resource.Form do
attributes =
resource
|> Ash.Resource.Info.attributes()
|> Enum.filter(&(&1.writable? && &1.public?))
|> Enum.filter(& &1.writable?)
|> Enum.reject(&(&1.name == :autogenerated_id))
|> only_accepted(action)
|> Enum.reject(fn attribute ->
@ -1630,12 +1626,8 @@ defmodule AshAdmin.Components.Resource.Form do
defp only_accepted(attributes, %{type: :read}), do: attributes
defp only_accepted(attributes, %{accept: nil, reject: reject}) do
Enum.filter(attributes, &(&1.name not in reject || []))
end
defp only_accepted(attributes, %{accept: accept, reject: reject}) do
Enum.filter(attributes, &(&1.name in accept && &1.name not in (reject || [])))
defp only_accepted(attributes, %{accept: accept}) do
Enum.filter(attributes, &(&1.name in accept))
end
defp actions(resource, type) do

14
mix.exs
View file

@ -96,12 +96,14 @@ defmodule AshAdmin.MixProject do
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger],
mod: {AshAdmin, []}
]
if Mix.env() == :text do
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger],
mod: {AshAdmin, []}
]
end
end
# Run "mix help deps" to learn about dependencies.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

13
test/support/test_app.ex Normal file
View file

@ -0,0 +1,13 @@
defmodule AshAdmin.TestApp do
@moduledoc false
def start(_type, _args) do
children = [
AshPostgres.TestRepo
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: AshPostgres.Supervisor]
Supervisor.start_link(children, opts)
end
end