How should permission_query_conditions be combined when multiple Frappe apps define them for the same DocType? #206366
🏷️ Discussion TypeBug BodyI'm working on a Frappe setup with multiple custom apps. I noticed an issue when more than one app defines permission_query_conditions for the same DocType. For example, suppose App A and App B both define permission conditions for Sales Invoice. Instead of behaving like: App A condition OR App B condition the resulting behavior seems to effectively require both conditions: App A condition AND App B condition This can unintentionally restrict the records a user can access. What is the recommended way to handle this when multiple apps need to contribute to the permissions of the same DocType? Should the permission_query_conditions from different apps be explicitly merged into a single function? If so, what is the recommended upgrade-safe approach for combining the conditions from multiple hooks.py / permissions.py implementations without one app overriding another? Guidelines
|
Replies: 2 comments 2 replies
|
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
Recommended ApproachWhen multiple Frappe apps define For example, if App A and App B both define permission conditions for The effective condition is essentially: This can unintentionally make the permission too restrictive. If the intended business logic is OR, the conditions need to be explicitly combined into a single permission function: This produces: For multiple custom apps, avoid relying on hook ordering or allowing one app to overwrite another. If several apps need to contribute permission logic for the same DocType, use a deliberate composition strategy and keep the individual conditions separate from the final function that combines them. The important point is that For an upgrade-safe implementation, keep the customization in your own app(s), avoid modifying Frappe/ERPNext core, and avoid depending on the order in which apps are installed or their hooks are loaded. |
Recommended Approach
When multiple Frappe apps define
permission_query_conditionsfor the same DocType, the conditions are combined with AND, not OR.For example, if App A and App B both define permission conditions for
Sales Invoice:The effective condition is essentially:
This can unintentionally make the permission too restrictive.
If the intended business logic is OR, the conditions need to be expli…