varvet / pundit

Minimal authorization through OO design and pure Ruby classes
MIT License
8.27k stars 629 forks source link

feat: Add customizable permit description #760

Closed barelyknown closed 4 months ago

barelyknown commented 1 year ago

In this common example, the default description is noisy and doesn't add any information:

πŸ”ˆ Default output:

ActionItemPolicy
  show?
    grants access to a customer manager member
    when the user is a customer operations member
      when there is no relationship to the action item
        is expected not to permit #<User id: 2, email_address: "test+user2@x-b-e.com", mobile_number: nil, created_at: "2023-02-18 14:3...ation_event_at: nil, release_note_feed_token: nil, opt_out_of_check_in_request_notifications: false> and #<ActionItem id: 2, title: "Fix all the things!", responsible_organization_type: "Customer", responsi...quires_xbe_feature: false, meeting_id: nil, created_by_id: nil, project_id: nil, root_cause_id: nil>

This PR enables you to customize the description.

Pundit::RSpec::Matchers.description do
  "permit the user"
end

πŸ’† Customized output:

ActionItemPolicy
  show?
    grants access to a customer manager member
    when the user is a customer operations member
      when there is no relationship to the action item
        is expected not to permit the user
Burgestrand commented 1 year ago

Thank you! I'm positive about this feature, but I'm not sure about the interface. I also need to borrow myself some time to test it out before I'm willing to merge it.

Pundit::RSpec::Matchers.description = ->(user, record) { "permit user with role #{user.role}" }
bf4 commented 1 year ago

I merged my branch from https://github.com/varvet/pundit/pull/761 into this one

Burgestrand commented 4 months ago

Hi! Merged in #806