Skip to content

Derive can/1 rules from Ash domain resources#4

Merged
vincentvanbush merged 9 commits into
masterfrom
2-ash-spirit-resource-permissions
Jun 2, 2026
Merged

Derive can/1 rules from Ash domain resources#4
vincentvanbush merged 9 commits into
masterfrom
2-ash-spirit-resource-permissions

Conversation

@vincentvanbush

Copy link
Copy Markdown
Contributor

Resolves #2.

@vincentvanbush vincentvanbush changed the title 2 ash spirit resource permissions Derive can/1 rules from Ash domain resources May 29, 2026
@vincentvanbush vincentvanbush force-pushed the 2-ash-spirit-resource-permissions branch 4 times, most recently from ef508e3 to af95429 Compare June 1, 2026 08:42
@vincentvanbush vincentvanbush force-pushed the 1-derive-permit-action-names-from-ash-domain-resources branch from 6d12b70 to ffe5d26 Compare June 1, 2026 10:09
@vincentvanbush vincentvanbush force-pushed the 2-ash-spirit-resource-permissions branch from aefe8e6 to b5415d7 Compare June 1, 2026 10:10
@vincentvanbush vincentvanbush force-pushed the 1-derive-permit-action-names-from-ash-domain-resources branch from ffe5d26 to 199b585 Compare June 1, 2026 10:25
Introduces an "Ash spirit" alternative to writing Permit permission rules
by deriving them directly from Ash resource declarations.

New DSL on any resource using the Permit.Ash.Resource extension:

    permit do
      for_actor %{role: :admin} do
        all()
      end
      for_actor %{id: user_id, role: :owner} do
        read()
        update(user_id: user_id)
      end
    end

The Spark transformer generates a __permit_rules__/1 function on each
resource so that Permit.Ash.DomainPermissions can aggregate them:

    defmodule MyApp.Permissions do
      use Permit.Ash.DomainPermissions,
        domain: MyApp.Domain,
        actions_module: MyApp.AshActions
    end

The generated can/1 iterates all domain resources, calls
__permit_rules__/1 on each, and merges the rules into a
%Permit.Permissions{} struct compatible with Permit.ResolverBase.
The :all sentinel action expands to every group in the actions module.
@vincentvanbush vincentvanbush force-pushed the 2-ash-spirit-resource-permissions branch from b5415d7 to 964c7fe Compare June 1, 2026 10:25
@vincentvanbush vincentvanbush linked an issue Jun 1, 2026 that may be closed by this pull request
3 tasks
@vincentvanbush vincentvanbush changed the base branch from 1-derive-permit-action-names-from-ash-domain-resources to master June 2, 2026 15:32
@vincentvanbush vincentvanbush merged commit af1f981 into master Jun 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Derive can/1 rules from Ash domain resources

2 participants