Skip to content

57 igniter configuration#24

Merged
dawidsawczuk merged 3 commits into
masterfrom
57-add-igniter-installer
Apr 27, 2026
Merged

57 igniter configuration#24
dawidsawczuk merged 3 commits into
masterfrom
57-add-igniter-installer

Conversation

@dawidsawczuk

Copy link
Copy Markdown
Contributor

Pull Request

Description

This PR adds Igniter installer support to permit_ecto, enabling mix permit_ecto.install for automated project setup. The task generates an authorization module configured for Ecto and a permissions module with a starter can/1 function. It also serves as a composable sub task invoked by mix permit.install from the permit package.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Performance improvement
  • Code refactoring
  • Test improvements
  • CI/CD improvements

Related Issues

Closes #57.

Changes Made

  • Added {:igniter, "~> 0.5", optional: true} to deps.
  • Removed :only restriction from jason dependency (required by Igniter's transitive dep on req).
  • Added Mix.Tasks.PermitEcto.Install Igniter task (lib/mix/tasks/permit_ecto.install.ex):
    • Generates .Authorization module with use Permit.Ecto configured with the detected/specified repo.
    • Generates .Authorization.Permissions module with use Permit.Ecto.Permissions and a stub can/1.
    • Auto detects Ecto repo via Igniter.Libs.Ecto.list_repos/1 with fallback to .Repo.
    • Handles multiple repos gracefully (uses first, notifies user to pass --repo).
    • All module names customizable via --authorization-module, --permissions-module, --actions-module, --repo.
    • Prints a post-install notice with a usage example for defining permissions.
    • Falls back gracefully when Igniter is not installed.
  • Added 7 Igniter tests covering default generation, custom repo, custom module names, and custom actions
    module.

Testing

Test Environment

  • Elixir version: 1.18.4
  • OTP version: 28

Test Cases

  • All existing tests pass
  • New tests added for new functionality at appropriate levels
  • Manual testing performed

Test Commands Run

mix test
mix credo --strict
mix dialyzer

Documentation

  • Updated README.md (if applicable)
  • Updated documentation comments (with examples for new features)
  • Updated CHANGELOG.md (if applicable)

Code Quality

  • Code follows the existing style conventions
  • Self-review of the code has been performed
  • Code has been commented, particularly in hard-to-understand areas
  • No new linting warnings introduced
  • No new Dialyzer warnings introduced

Backward Compatibility

  • This change is backward compatible
  • This change includes breaking changes (please describe below)
  • Migration guide provided for breaking changes

Breaking Changes

The jason dependency had its :only restriction removed (only: [:dev, :test] -> unrestricted). This is necessary because Igniter transitively depends on req which needs jason at compile time. Since jason was already a dependency and is commonly available in all environments, this should not affect existing users.

Performance Impact

  • No performance impact
  • Performance improvement
  • Potential performance regression (please describe)

Security Considerations

  • No security impact
  • Security improvement
  • Potential security impact (please describe)

Additional Notes

Repo auto-detection uses Igniter.Libs.Ecto.list_repos/1 which scans for modules using Ecto.Repo. Falls back to .Repo with a notice if none found. This task is also composable, permit.install from the permit package composes this task when --no-ecto is not set.

Screenshots/Examples

Default install (auto-detects repo)

mix permit_ecto.install

With explicit repo

mix permit_ecto.install --repo MyApp.CustomRepo

Generated lib/my_app/authorization.ex:

  defmodule MyApp.Authorization do
    use Permit.Ecto,
      permissions_module: MyApp.Authorization.Permissions,
      repo: MyApp.Repo
  end

Generated lib/my_app/authorization/permissions.ex:

  defmodule MyApp.Authorization.Permissions do
    use Permit.Ecto.Permissions, actions_module: Permit.Actions.CrudActions

    def can(_user) do
      permit()
    end
  end

Checklist

  • I have read the Contributing Guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Reviewer Notes


@codecov

codecov Bot commented Mar 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/mix/tasks/permit_ecto.install.ex 83.33% 4 Missing ⚠️
Files with missing lines Coverage Δ
lib/mix/tasks/permit_ecto.install.ex 83.33% <83.33%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dawidsawczuk dawidsawczuk changed the title feat: igniter configuration 57 igniter configuration Mar 30, 2026
@dawidsawczuk dawidsawczuk marked this pull request as ready for review March 30, 2026 12:53
Comment thread mix.exs Outdated
Comment thread mix.exs Outdated
@dawidsawczuk dawidsawczuk merged commit 9d1eb70 into master Apr 27, 2026
10 checks 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.

2 participants