Add active_admin_import_context convention for controller-provided context#211
Merged
Add active_admin_import_context convention for controller-provided context#211
Conversation
This was referenced Apr 8, 2026
…ntext Controllers can define an `active_admin_import_context` method returning a hash; it is merged into the import model after form params so values the controller is authoritative about (parent.id, current_user.id, request attributes, etc.) cannot be overridden by tampered form fields. This supersedes PR #137 by offering a general-purpose hook that works for nested belongs_to imports and any other controller-derived state.
91bd319 to
ae2be23
Compare
Replaces `build_template_object` and `apply_import_context` with a single `prepare_import_model` orchestrator that handles the whole pipeline: build the template object → assign form params (if any) → apply context. Both `:import` and `:do_import` collection actions now call one method instead of two, and the form-params extraction is encapsulated inside the helper instead of being duplicated at the call site.
This was referenced Apr 8, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Introduces a convention method
active_admin_import_contextthat controllers can define to provide extra attributes for the import model. The returned hash is merged into the model after form params, so controller-authoritative values (e.g.parent.id,current_user.id,request.remote_ip) cannot be overridden by tampered form fields.Why a convention method instead of a new Importer arg?
current_user,parent, etc.) — open-ended hashcurrent_admin, Pundit scopes, etc.) since the user picks what to exposeImporter#initializebelongs_toimports can't be bypassed by submitting a different parent id in the formSupersedes / closes
belongs_toparent accessbefore_batch_importcurrent_userinside callbacksTest plan
request.remote_ipflows through context → stored onPostrecordsPostCommentimports getpost_id: parent.idautomatically