-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
158 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule AshAdmin.ShowResourcesTransformer do | ||
Check warning on line 1 in lib/ash_admin/show_resources_transformer.ex GitHub Actions / ash-ci / mix credo --strict
|
||
use Spark.Dsl.Transformer | ||
|
||
def transform(dsl) do | ||
module = Spark.Dsl.Transformer.get_persisted(dsl, :module) | ||
all_resources = Ash.Domain.Info.resources(dsl) | ||
|
||
resources = | ||
case AshAdmin.Domain.show_resources(dsl) do | ||
[:*] -> | ||
all_resources | ||
|
||
resources -> | ||
case Enum.find(resources, &(&1 not in all_resources)) do | ||
nil -> | ||
resources | ||
|
||
bad_resource -> | ||
raise Spark.Error.DslError, | ||
module: module, | ||
path: [:admin, :show_resources], | ||
message: "#{inspect(bad_resource)} is not a valid resource in #{inspect(module)}" | ||
end | ||
end | ||
|
||
{:ok, Spark.Dsl.Transformer.set_option(dsl, [:admin], :show_resources, resources)} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,91 @@ | ||
defmodule AshAdmin.Test.AshAdminTest do | ||
@moduledoc false | ||
use ExUnit.Case, async: true | ||
|
||
test "all resources are shown by default", _ do | ||
defmodule Domain do | ||
@moduledoc false | ||
use Ash.Domain, | ||
extensions: [AshAdmin.Domain] | ||
|
||
admin do | ||
show? true | ||
end | ||
|
||
resources do | ||
resource AshAdmin.Test.Post | ||
resource AshAdmin.Test.Comment | ||
end | ||
end | ||
|
||
assert AshAdmin.Domain.show_resources(Domain) === [ | ||
AshAdmin.Test.Post, | ||
AshAdmin.Test.Comment | ||
] | ||
end | ||
|
||
test "all resources are shown when :* option is selected", _ do | ||
defmodule Domain do | ||
@moduledoc false | ||
use Ash.Domain, | ||
extensions: [AshAdmin.Domain] | ||
|
||
admin do | ||
show? true | ||
show_resources :* | ||
end | ||
|
||
resources do | ||
resource AshAdmin.Test.Post | ||
resource AshAdmin.Test.Comment | ||
end | ||
end | ||
|
||
assert AshAdmin.Domain.show_resources(Domain) === [ | ||
AshAdmin.Test.Post, | ||
AshAdmin.Test.Comment | ||
] | ||
end | ||
|
||
test "selected resources are shown", _ do | ||
defmodule Domain do | ||
@moduledoc false | ||
use Ash.Domain, | ||
extensions: [AshAdmin.Domain] | ||
|
||
admin do | ||
show? true | ||
show_resources AshAdmin.Test.Post | ||
end | ||
|
||
resources do | ||
resource AshAdmin.Test.Post | ||
resource AshAdmin.Test.Comment | ||
end | ||
end | ||
|
||
assert AshAdmin.Domain.show_resources(Domain) === [ | ||
AshAdmin.Test.Post | ||
] | ||
end | ||
|
||
test "if shown resrouces option not eixsting resource providede error", _ do | ||
assert_raise(Spark.Error.DslError, "[AshAdmin.Test.AshAdminTest.Domain]\n admin -> show_resources:\n SomeRandom is not a valid resource in AshAdmin.Test.AshAdminTest.Domain", fn -> | ||
defmodule Domain do | ||
@moduledoc false | ||
use Ash.Domain, | ||
extensions: [AshAdmin.Domain] | ||
|
||
admin do | ||
show? true | ||
show_resources [AshAdmin.Test.Post, SomeRandom] | ||
end | ||
|
||
resources do | ||
resource AshAdmin.Test.Post | ||
resource AshAdmin.Test.Comment | ||
end | ||
end | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule AshAdmin.Test.Comment do | ||
@moduledoc false | ||
use Ash.Resource, | ||
domain: AshAdmin.Test.Domain, | ||
data_layer: Ash.DataLayer.Ets | ||
|
||
attributes do | ||
uuid_primary_key(:id) | ||
|
||
attribute :body, :string do | ||
allow_nil?(false) | ||
public?(true) | ||
end | ||
end | ||
end |