Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the policy class to the NotAuthorizedError message #812

Merged
merged 10 commits into from
Jun 17, 2024

Conversation

smitssjors
Copy link
Contributor

This PR fixes #681 and #647.

@Burgestrand
Copy link
Member

Hi! Thanks for updating the old PR!

This does not fix #647, but it does fix #681.

I'm not sure why the pull request templates we have didn't get proposed, but please have a look at it: https://github.com/varvet/pundit/blob/main/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md - this PR is missing a changelog entry 🙂

@smitssjors
Copy link
Contributor Author

I updated the PR to now actually take care of #647 and I updated the CHANGELOG.md

I did not get the template when I made the PR via the button in my fork. I did however read CONTRIBUTING.md so I added updating the CHANGELOG as a step to hopefully prevent these mistakes in the future.

@Burgestrand
Copy link
Member

The jruby failures are unrelated to this change. Something is up with the more recent jruby version on our GitHub CI pipeline.

@Burgestrand
Copy link
Member

Either way I think this should probably be good! I'll most likely merge this soon. Travelling to Baltic Ruby today though 😊

lib/pundit.rb Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
smitssjors and others added 2 commits June 17, 2024 13:38
Co-authored-by: Kim Burgestrand <kim@burgestrand.se>
Co-authored-by: Kim Burgestrand <kim@burgestrand.se>
@smitssjors
Copy link
Contributor Author

I think these changes are indeed better so I added them

@Burgestrand Burgestrand merged commit e5f8835 into varvet:main Jun 17, 2024
14 checks passed
@Burgestrand
Copy link
Member

Thank you!

@Burgestrand Burgestrand added this to the Next Pundit release milestone Jun 17, 2024
@smitssjors smitssjors deleted the better-error-message branch June 17, 2024 14:43
Burgestrand added a commit that referenced this pull request Aug 26, 2024
## Improve `NotAuthorizedError` message to include policy class (#812)

Default error message changed from:
> not allowed to destroy? this Comment

To include the policy class:
> not allowed to Project::Admin::CommentPolicy#destroy? this Comment

## Improve `NotAuthorizedError` when record is a class

Before:
> not allowed to index? this Class

After:
> not allowed to PostPolicy#index? Post

## Allow customizing rspec matcher description (#806)

Before:
> PostPolicy
>  update? and show?
>    is expected to permit #<User:0x0000000104aefd80> and #<Post:0x0000000104aef8d0 @user=#<User:0x0000000104aefd80>>

In `spec_helper.rb`:
```ruby
Pundit::RSpec::Matchers.description = ->(user, record) do
  "permit user with role #{user.role} to access record with ID #{record.id}"
end
```

After:
> PostPolicy
>  update? and show?
>    is expected to permit user with role admin to access record with ID 130

## Add support for filter_run_when_matching :focus with permissions helper (#820)

If your RSpec config has filter_run_when_matching :focus, you may tag the permissions helper like so:

```ruby
permissions :show?, :focus do
```
@Burgestrand Burgestrand mentioned this pull request Aug 26, 2024
6 tasks
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