Repository navigation
[pull] master from inventree:master - #144
Merged
Merged
Conversation
* Model permission tweaks * Update CHANGELOG * Update plugin docs * Add warning
* Fix ApiFormFIeldType docstring * Case fix * Add sub-forms for company creation * Tweak component def * Add new company for manufacturer-part and supplier-part * Create new parameter template directly from parameter view * Add tooltip * Add playwright tests * Consolidate translation * Revert to left side * Fix title case --------- Co-authored-by: Matthias Mair <code@mjmair.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )
Greptile Summary
This PR syncs upstream InvenTree changes that introduce two main features: (1) inline "create new" buttons on related-model fields (supplier, customer, manufacturer, parameter template) so users can create records without leaving the form, and (2) a plugin escape-hatch in the backend permission system via a
check_user_permissionclassmethod on plugin-defined models. It also fixes a rules-of-hooks violation by convertingInlineCreateButtonfrom a plain function to a proper React component.Confidence Score: 5/5
Safe to merge; remaining findings are P2 style/robustness suggestions that do not block functionality.
All identified issues are P2: one style concern about non-reactive Zustand state access and one hardening suggestion for exception handling in the plugin permission fallback. Neither causes incorrect behavior under normal conditions, and the core feature additions are well-structured with new test coverage.
No files require special attention beyond the two inline P2 comments.
Important Files Changed
check_user_permissionclassmethod for plugin models not covered by the standard ruleset; result is cached but the call is unguarded against plugin exceptions.InlineCreateButtonfrom a plain function (invalid hooks usage) to a proper React component with props, fixing a rules-of-hooks violation; also renamessetValuefromPKtosetValueFromPK.useParameterTemplateFieldshook for reuse and adds inline supplier creation for the template field (staff only), but usesuseUserState.getState()non-reactively inside the hook.addCreateFieldsto supplier and manufacturer related fields, enabling inline creation of companies with pre-setis_supplier/is_manufacturerflags.addCreateFieldsto the supplier field on purchase order forms for inline supplier creation.addCreateFieldsto the customer field on sales order forms for inline customer creation.useMemofield definition with the newly extracteduseParameterTemplateFieldshook for DRY reuse.stevenuser(staff) and adds coverage for the new inline parameter-template creation button.check_user_permissionclassmethod API for plugin-defined models, including a code example and a warning about the default-deny behaviour.ApiFormFieldType: adds entries formodelRenderer,child/children,addCreateFields,read_only,headers, andadjustValue, and removes the obsoleteonKeyDownentry.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[check_user_permission called] --> B{User active & not None?} B -- No --> Z[Return False] B -- Yes --> C{Superuser?} C -- Yes --> Y[Return True] C -- No --> D{Table in ruleset ignore list?} D -- Yes --> Y D -- No --> E{Table in ruleset models?} E -- Yes --> F{check_user_role passes?} F -- Yes --> Y F -- No --> G[Check RULESET_CHANGE_INHERIT] G --> H[Generate permission_name] E -- No --> H H --> I{Session cache hit?} I -- Yes --> X[Return cached result] I -- No --> J[user.has_perm permission_name] J --> K{result is False?} K -- No --> L[Cache & Return True] K -- Yes --> M{model has check_user_permission?} M -- No --> N[Cache False & Return False] M -- Yes --> O[Call model.check_user_permission] O --> P[Cache result & Return]Comments Outside Diff (2)
src/backend/InvenTree/users/permissions.py, line 200-201 (link)No error handling around plugin
check_user_permissioncallIf a plugin's
check_user_permissionimplementation raises an exception (e.g., a query error or programming bug in the plugin), the exception will propagate out of the standard permission check, potentially breaking permission enforcement for all callers. A baretry/exceptthat falls back toFalsewould isolate plugin faults.src/frontend/src/forms/CommonForms.tsx, line 129 (link)useUserState.getState()used inside a hook instead of the reactive hook formuseUserState.getState()returns a one-time snapshot and does not subscribe the component to future user-state changes. If the user'sisStaffstatus were to change during the session, theaddCreateFieldsvalue inside theuseMemowould remain stale until the component unmounts and remounts. The standard Zustand hook calluseUserState()correctly re-renders on state changes.Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "[UI] More sub-forms (#11785)" | Re-trigger Greptile