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

improvement: apply policy scope on has many search query #1824

Merged
merged 5 commits into from
Jul 4, 2023

Conversation

Paul-Bob
Copy link
Contributor

@Paul-Bob Paul-Bob commented Jul 4, 2023

Description

Fixes #1808

Scope example

class UserPolicy < ApplicationPolicy

  # . . .

  # . . .

  class Scope < Scope
    def resolve
      scope.where("first_name like ?", "%a%")
    end
  end
end

Before

When searching on a has many field, the policy scope was not being applied, returning all association records.

before.webm

After

Now the policy scope is being applied on the search result.

after.webm

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

@Paul-Bob Paul-Bob self-assigned this Jul 4, 2023
@codeclimate
Copy link

codeclimate bot commented Jul 4, 2023

Code Climate has analyzed commit 5dc0d23 and detected 0 issues on this pull request.

View more on Code Climate.

@useattractor
Copy link

useattractor bot commented Jul 4, 2023

improvement: apply policy scope on has many search query 🔗

Stats

Language Score Trend
Ruby 8.41 (from 8.4) 📈 0.13%
JavaScript 28.35 (from 28.35) 📉 0.0%

Trends

Most Improved Largest Declines
Ruby No decreases for Ruby detected app/controllers/avo/search_controller.rb
JavaScript No decreases for JavaScript detected No increases for JavaScript detected

To-Dos

New to Refactor Refactored
Ruby No new To-Dos for Ruby detected No completed To-Dos for Ruby detected
JavaScript No new To-Dos for JavaScript detected No completed To-Dos for JavaScript detected

@adrianthedev
Copy link
Collaborator

Can we also add some tests?

@useattractor
Copy link

useattractor bot commented Jul 4, 2023

improvement: apply policy scope on has many search query 🔗

Stats

Language Score Trend
Ruby 8.42 (from 8.4) 📈 0.22%
JavaScript 28.35 (from 28.35) 📉 0.0%

Trends

Most Improved Largest Declines
Ruby No decreases for Ruby detected app/controllers/avo/search_controller.rb
JavaScript No decreases for JavaScript detected No increases for JavaScript detected

To-Dos

New to Refactor Refactored
Ruby No new To-Dos for Ruby detected No completed To-Dos for Ruby detected
JavaScript No new To-Dos for JavaScript detected No completed To-Dos for JavaScript detected

@useattractor
Copy link

useattractor bot commented Jul 4, 2023

improvement: apply policy scope on has many search query 🔗

Stats

Language Score Trend
Ruby 8.43 (from 8.4) 📈 0.36%
JavaScript 28.35 (from 28.35) 📉 0.0%

Trends

Most Improved Largest Declines
Ruby No decreases for Ruby detected app/controllers/avo/search_controller.rb
JavaScript No decreases for JavaScript detected No increases for JavaScript detected

To-Dos

New to Refactor Refactored
Ruby No new To-Dos for Ruby detected No completed To-Dos for Ruby detected
JavaScript No new To-Dos for JavaScript detected No completed To-Dos for JavaScript detected

@useattractor
Copy link

useattractor bot commented Jul 4, 2023

improvement: apply policy scope on has many search query 🔗

Stats

Language Score Trend
Ruby 8.43 (from 8.4) 📈 0.36%
JavaScript 28.35 (from 28.35) 📉 0.0%

Trends

Most Improved Largest Declines
Ruby No decreases for Ruby detected app/controllers/avo/search_controller.rb
JavaScript No decreases for JavaScript detected No increases for JavaScript detected

To-Dos

New to Refactor Refactored
Ruby No new To-Dos for Ruby detected No completed To-Dos for Ruby detected
JavaScript No new To-Dos for JavaScript detected No completed To-Dos for JavaScript detected

@useattractor
Copy link

useattractor bot commented Jul 4, 2023

improvement: apply policy scope on has many search query 🔗

Stats

Language Score Trend
Ruby 8.36 (from 8.33) 📈 0.37%
JavaScript 28.35 (from 28.35) 📉 0.0%

Trends

Most Improved Largest Declines
Ruby No decreases for Ruby detected app/controllers/avo/search_controller.rb
JavaScript No decreases for JavaScript detected No increases for JavaScript detected

To-Dos

New to Refactor Refactored
Ruby No new To-Dos for Ruby detected No completed To-Dos for Ruby detected
JavaScript No new To-Dos for JavaScript detected No completed To-Dos for JavaScript detected

@Paul-Bob Paul-Bob merged commit 3bef387 into main Jul 4, 2023
@Paul-Bob Paul-Bob deleted the improvement/apply_scope_on_searchable_table branch July 4, 2023 13:48
@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2023

This PR has been merged into main. The functionality will be available in the next release.

Please check the release guide for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

searchable option partially bypasses the scope in has_many association
2 participants