mirror of
https://github.com/ash-project/ash_admin.git
synced 2024-09-19 12:53:28 +12:00
fix: properly accept private attributes in admin
This commit is contained in:
parent
6e18a3ae53
commit
2abf162c2e
6 changed files with 9027 additions and 45 deletions
|
@ -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
|
||||
|
|
|
@ -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
14
mix.exs
|
@ -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
13
test/support/test_app.ex
Normal 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
|
Loading…
Reference in a new issue