-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
Feature flexible resource filters #2091
Merged
tvdeyen
merged 13 commits into
AlchemyCMS:main
from
robinboening:feature_flexible_resource_filters
Jul 9, 2021
Merged
Feature flexible resource filters #2091
tvdeyen
merged 13 commits into
AlchemyCMS:main
from
robinboening:feature_flexible_resource_filters
Jul 9, 2021
Commits on Jul 5, 2021
-
Make resource filtering more flexible
this commit introduces a breaking change for apps using the class method `alchemy_resource_filters` in their models used in custom modules. The change introduces a new data structure for defining filters. It allows to set up multiple filters in two different ways: * where the filter name is assumed to be a scope on the model and the values are passed as the argument * where the filter values are assumed to be scopes on the model (basically as it was until now) Example: ``` class Mymodel < ApplicationRecord scope :by_language, ->(lang) { where(language: lang) } scope :published, -> { where(published: true) } scope :drafts, -> { not.published } def self.alchemy_resource_filters [ { name: :by_language, values: distinct.pluck(:language) }, { name: :status, values: %w[published drafts] } ] end end ``` Both, the name and the values can be translated. Since the filter values are passed into the `options_for_select` helper, they can be provided in two ways: array of strings/symbols, or as an array of arrays. In the first case Alchemy will lookup a translation in `alchemy.filters.<name_of_filter>.values` whereas in the second case the provided values will just be passed to into `options_for_select` directly. There are two security measures in place against filter param tempering: 1. Arriving filter values must match the values defined in the model. If the value doesn't exist, the parameter gets rejected and the value won't be send to the model. 2. Rails' strong parameters is used for the case where someone tempered with the parameter names. If a name and doesn't match one of the defined filter names in the model it won't get the permission to pass.
Configuration menu - View commit details
-
Copy full SHA for 161c792 - Browse repository at this point
Copy the full SHA 161c792View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1d60447 - Browse repository at this point
Copy the full SHA 1d60447View commit details -
Configuration menu - View commit details
-
Copy full SHA for 46705ff - Browse repository at this point
Copy the full SHA 46705ffView commit details
Commits on Jul 7, 2021
-
Configuration menu - View commit details
-
Copy full SHA for b3c69ac - Browse repository at this point
Copy the full SHA b3c69acView commit details -
Configuration menu - View commit details
-
Copy full SHA for f7e3d9a - Browse repository at this point
Copy the full SHA f7e3d9aView commit details -
Configuration menu - View commit details
-
Copy full SHA for b9bc437 - Browse repository at this point
Copy the full SHA b9bc437View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8296e47 - Browse repository at this point
Copy the full SHA 8296e47View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2e0a870 - Browse repository at this point
Copy the full SHA 2e0a870View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7b58c6e - Browse repository at this point
Copy the full SHA 7b58c6eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 20aad20 - Browse repository at this point
Copy the full SHA 20aad20View commit details
Commits on Jul 8, 2021
-
support but deprecate legacy alchemy_resource_filters data structure
This commit is supposed to be reverted after Alchemy v6.0 is released.
Configuration menu - View commit details
-
Copy full SHA for 4af2611 - Browse repository at this point
Copy the full SHA 4af2611View commit details
Commits on Jul 9, 2021
-
Configuration menu - View commit details
-
Copy full SHA for 762c6a6 - Browse repository at this point
Copy the full SHA 762c6a6View commit details -
Configuration menu - View commit details
-
Copy full SHA for 46a501c - Browse repository at this point
Copy the full SHA 46a501cView commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.