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

🚨 enhancement: preview policy #3660

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

Paul-Bob
Copy link
Contributor

@Paul-Bob Paul-Bob commented Feb 12, 2025

Description

Fixes #3513

A new policy method is available: preview?.

This method determines whether a preview request is authorized.

🚨 Breaking Change: Previously, the preview endpoint was always authorized.
Now, access is denied unless the preview? policy method explicitly returns true.

Steps to Update

To maintain the previous behavior of preview fields, add the preview?
method returning true in your base policy class:

# app/policies/application_policy.rb
class ApplicationPolicy
  def preview? = true
end

You can now refine this method to restrict access for specific users or even default it to false. The example above simply ensures that behavior remains unchanged after upgrading.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Screenshots & recording

image

@Paul-Bob Paul-Bob added the Enhancement Not necessarily a feature, but something has improved label Feb 12, 2025
@Paul-Bob Paul-Bob self-assigned this Feb 12, 2025
@Paul-Bob Paul-Bob changed the title Enhancement/preview policy enhancement: preview policy Feb 12, 2025
Copy link

codeclimate bot commented Feb 12, 2025

Code Climate has analyzed commit 4dadef5 and detected 0 issues on this pull request.

View more on Code Climate.

@adrianthedev adrianthedev changed the title enhancement: preview policy 🚨 enhancement: preview policy Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking change Enhancement Not necessarily a feature, but something has improved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add preview? policy method
2 participants