Skip to content

[Feature]: Remove compile-time dependency on permissions module #46

@maltoe

Description

@maltoe

Problem description

Hi 👋

first of all, thank you for this great library! We are currently adding it to our application and are really happy with the framework it provides us with so far. 👍

We noticed that use Permit, permissions_module: MyApp.Permissions introduces a compile-time dependency from our MyApp.Authorization to MyApp.Permissions, which is unfortunate as the latter has quite a few runtime dependencies to schema & context modules of our app, and hence every change to e.g. MyApp.User causes MyApp.Authorization to be recompiled.

It appears that the reason for this compile-time dependency is the way you access the actions_module through the permissions module at compile-time in order to generate a matching set of predicate functions.

permit/lib/permit.ex

Lines 117 to 118 in 4d1c407

Macro.expand(permissions_module, __CALLER__).actions_module()
|> Permit.Actions.list_groups()

Proposed solution

We'd like to ask you to consider removing this compile-time dependency in favor of another explicit actions_module option in Permit.__using__/1. Arguably introduces some redundancy and potential for mismatch between the values given to both modules, but it's a "one-time surprise" type of issue vs. yet another file that needlessly gets recompiled frequently (yes, we used to have a lot of them 🙂 ).

To keep backwards compatibility, you could make it optional and fallback to the access through permissions module:

    actions_module =
      case Keyword.get(opts, :actions_module) do
        nil -> Macro.expand(permissions_module, __CALLER__).actions_module()
        module -> Macro.expand(module, __CALLER__)
      end

Checklist

  • I have searched for existing issues before creating this one
  • I have checked the roadmap in the README
  • This is a feature request, not a bug report or question. For general questions, please use Elixir Slack's Permit channel.

[edit] ☝️ actually, this could be related to #23 and/or #24 but not sure

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions