Ash FrameworkAF
Ash Framework3y ago
34 replies
barnabasj

Ambiguous Call during Compile because of Extension

I'm creating an extension and I tried adding an actions option to it, but it won't compile the resources anymore because it cant tell which actions function to use.

  == Compilation error in file test/support/policy.ex ==
** (CompileError) test/support/policy.ex:52: function actions/1 imported from both Demo.Extensions.Rbac.Rbac.Role.Options and Ash.Resource.Dsl, call is ambiguous
    expanding macro: Demo.Extensions.Rbac.Rbac.Role.role/3
    test/support/policy.ex:51: PolicyTestSupport.RootResource (module)
    expanding macro: Demo.Extensions.Rbac.rbac/1
    test/support/policy.ex:48: PolicyTestSupport.RootResource (module)


Extension definition:

 @role %Spark.Dsl.Entity{
    name: :role,
    describe: "If the check is true, the request is forbidden, otherwise run remaining checks.",
    target: Role,
    args: [:role, :fields],
    links: [],
    schema: [
      role: [
        type: :atom,
        required: true,
        doc: """
        The role this config is for
        """
      ],
      fields: [
        type: {:list, :atom},
        required: true,
        doc: """
        The fields the role has access to
        """
      ],
      allowed_actions: [
        type: {:list, :atom},
        required: false,
        doc: """
        The actions the role has access to
        """
      ]
    ],
    examples: [
      "role :user, [:id, :name]"
    ]
  }

  @rbac %Spark.Dsl.Section{
    name: :rbac,
    describe: @moduledoc,
    examples: [
      """
      rbac do
        bypass :admin
        role :user, [:name] do
          actions [:read]
        end
      end
      """
    ],
    schema: [
      bypass: [
        type: :atom,
        doc: "Role that is allowed to bypass authorization"
      ],
      public?: [
        type: :boolean,
        doc: "Allow all access",
        default: false
      ]
    ],
    entities: [
      @role
    ]
  }
Was this page helpful?