- Use walrus operator where possible
- Drop redundant checks - we anyway can't iterate over an empty list
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
* feat: allow wildcard for doctype in permission hooks
* fix: pass doctype to permission query
* fix: combine methods instead of alternate
* test: wildcard has_permssion hook
* test: wildcard has_permssion make note public
* fix: fetch list of hooks once
frappe.permission.has_permission won't accept raise_exception anymore,
it was extremely misleading argument and actual purpose of the argument
was to print perm check logs.
BREAKING CHANGE:
before: `has_permission` hooks need to explicitly return "False" to block a user.
after: `has_permission` hook need to explicitly return "True" (or truthy) value to allow user. They will be blocked otherwise.
Why? Everything related to permission should be block by default and allow if some checks pass.
* feat: permission debugger
This PR adds a virtual doctype that can run has_permission for
doctype-docname-user-ptype combinations and spit out detailed log for
why/where some permissionw as denied or granted.
This isn't supposed to be programatic, it's just textual dump of what code is doing.
IMO a better debugger can be written but that will require extensive
rewrite of perm checks first. All debugging, error messages in current
systems are bolted on top with hacks to avoid messing with
implementation.
* fix: capture UP pass check
* fix: reset docname on changing doctype
* fix: docname is optional
* fix: debug doctype perms
Right now if you have if-owner rule on doctype then whatever you change
will only apply to last inserted rule because we don't check if-owner
value
Long term better fix: Identify with perm rule name instead of arbitrary
"primary keys" defined in code.
- Create a doctype
- Pick any role and only allow owner to create, read, write.
- after_insert hook re-save the document
- This will fail because there's a function call to `frappe.only_has_select_perm` which doesn't pass the is_owner, this is likely acceptable if document is not available.
Fix: cache should be separate for is_owner
Triggered from but not caused by https://github.com/frappe/frappe/pull/20810
* feat: Disable Sharing globally
- Checkbox in System Settings
- If disabled, avoid share UI render
- Share APIs return None (non-obstructing) if share APIs are invoked
* feat: Settings checkbox must toggle share permission globally
- Treat feature like a perm toggler. Essentially noone is allowed to explicity share anything
- Implicit sharing via `ignore_share_permissions` is allowed. Devs can decide where sharing should happen under the hood
- UI is made read only and not hidden. Users must see who doc is already shared with
- Make sure perm APIs used by share feature return false if sharing is disabled
- Rename checkbox to `Disable Document Sharing`
* test: (server side) Impact of disabling sharing on APIs
- Also, fix missed system setting rename in `assign_to`
* fix: Inform assigner if assignee lacks perms and sharing is disabled
- misc: readable conditions
* fix: throw instead of msgprint
* fix: Typo and appropriate message for `throw`
---------
Co-authored-by: Ankush Menat <ankush@frappe.io>