Skip to content

[Feature]: Use module attributes to map events to action names #37

@vincentvanbush

Description

@vincentvanbush

Problem description

Currently, the event_mapping/0 callback is an arguably inconvenient way to map handle_event event names to Permit action names.

We would like to explore more convenient alternatives that allow the developer to keep the mapping closer to the event handler definition itself, for better code readability.

Proposed solution

A combination of private and public module attributes controlled using a before_compile callback could be used to facilitate the new method of mapping, while at the same time preserving backwards compatibility.

Alternatives considered

No response

Use case

Implementing LiveViews with events authorized using Permit.Phoenix.LiveView.

Desired API/code example

@permit_action :update
def handle_event("save", %{"article" => article_params}, socket) do
  article = socket.assigns.loaded_resource
  # ...
end

Component

LiveView

Priority (1-3)

3 - High - Blocking my work

Additional Context

No response

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.

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