Commit graph

249 commits

Author SHA1 Message Date
Akhil Narang
306c923986
chore: minor code cleanup
- 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>
2024-04-10 17:22:45 +05:30
Revant Nandgaonkar
7e16e902d9
feat: allow wildcard for doctype in permission hooks (#25729)
* 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
2024-04-10 11:44:37 +05:30
Ankush Menat
99952880cc fix!: Don't let users with write access to UP bypass UP
IDK why we truly need this, except maybe debugging sometimes. This just
causes confusion and people keep reporting this as security issue.
2024-04-05 18:55:27 +05:30
barredterra
b6f12db08c fix: translate doctype in user-facing error message 2024-02-24 02:39:29 +01:00
Ankush Menat
99bb5d0303
fix: Cast to string to handle int PK (#24988) 2024-02-21 13:27:38 +00:00
Raffael Meyer
fc64e8a0fb
feat: pass doctype as context when translating label (#24903) 2024-02-18 19:42:15 +05:30
Ankush Menat
72c2207e0f refactor: useless use of dict in frappe.get_doc 2024-02-10 12:52:38 +05:30
Akhil Narang
26ae0f3460
fix: ruff fixes
Signed-off-by: Akhil Narang <me@akhilnarang.dev>
2024-02-07 17:04:31 +05:30
Ankush Menat
de9ac89748 style: re-format with ruff 2024-02-05 18:53:33 +05:30
Gursheen Anand
f74939eb0c fix: skip strict user perms for single doctypes 2024-01-18 16:10:20 +05:30
Ankush Menat
447f02e8d3
fix!: Remove misleading "raise_exception" (#24266)
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.
2024-01-11 08:24:18 +00:00
Ankush Menat
5ef8577cff
fix!: Stricter requirement for permission hooks (#24253)
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.
2024-01-11 01:35:08 +05:30
Ankush Menat
b3532024b5 fix: Accept "Falsy" values from perm controllers 2024-01-10 15:43:06 +05:30
Ankush Menat
914406d31b feat: extend perm debugging to popular controllers
- [x] File
- [x] Communication
2024-01-10 15:16:52 +05:30
Ankush Menat
3a8fc90961
feat: permission debugger (#24239)
* 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
2024-01-10 09:29:13 +00:00
Ankush Menat
3349f2b6e6 fix: nested has_permission calls erase messages 2024-01-04 10:31:55 +05:30
Ankush Menat
04acd0bda4
fix: don't add fallback for child table (#24105) 2024-01-03 12:18:06 +00:00
Hussain Nagaria
8d2137c265 docs: consistent doc strings 2023-12-18 18:27:39 +05:30
barredterra
c35476256f refactor: simplify conditional logic
Command: `sourcery review --fix --enable de-morgan .`
2023-12-05 11:14:41 +01:00
Sagar Vora
c561369330 fix: avoid double translation 2023-09-28 11:46:44 +05:30
Ankush Menat
0381f836d6 fix: update correct role permission rule
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.
2023-09-18 13:45:20 +05:30
Ankush Menat
fb65ab1a4e fix: notify when rule already exists 2023-09-18 12:28:14 +05:30
Ankush Menat
1b406edd54 feat: Desk User role 2023-08-28 22:31:23 +05:30
barredterra
b553ed98d8 refactor: inline immediately returned variable
Inline a variable to a return in the case when the
variable being declared is immediately returned
2023-08-08 18:09:49 +02:00
Ankush Menat
ada2e20af3 fix: has_permission check on int pk 2023-07-31 16:42:31 +05:30
Ankush Menat
14798146c7
fix: Conditionally show extra info for perm error (#21660) 2023-07-12 22:22:34 +05:30
Ankush Menat
e4bae5c831 perf: faster doc shared checks
- If document, explicitly query document
- If checking doctype then put limit and only see if 1 record is
  returned.
2023-06-28 20:00:55 +05:30
Ankush Menat
0e92fc9bf5 fix: Clear cache after role perm manager 2023-06-19 16:29:35 +05:30
Ankush Menat
3005e66e45 refactor!: Drop previously deprecated code 2023-06-13 16:00:43 +05:30
Ankush Menat
98260b3c88
fix(UX): show perm server messages on file uploader (#21331) 2023-06-12 13:53:08 +05:30
Ankush Menat
fa6dc03cc8
refactor: frappe.cache() usage to frappe.cache (#21282) 2023-06-08 11:47:17 +05:30
Ankush Menat
d0a24e66c5
fix: incorrect caching of is_owner permissions (#21048)
- 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
2023-05-19 09:34:48 +05:30
Marica
90f8f945b4
feat: Disable Sharing globally (#20318)
* 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>
2023-03-28 18:13:37 +05:30
Ankush Menat
8446875257
refactor!: Remove "Set user permission" permtype (#20090)
This has never worked and setting user permission requires system
manager role always (because of permissions on list view)
2023-02-20 16:07:49 +05:30
Ankush Menat
3f1deeba67
fix: can't sign out due to missing roles (#19905) 2023-02-02 22:53:24 +05:30
Ankush Menat
1eab4e4253
fix: Convert doctype name to string (#19832) 2023-01-30 14:11:38 +05:30
Ritwik Puri
fabe3906aa
chore: remove deprecated check_admin_or_system_manager function (#19540) 2023-01-09 18:32:09 +05:30
jiangying
f18135b52b
chore: simplify frappe/permissions.py raise_exception condition assignment (#19518)
* simplify frappe/permissions.py raise_exception
2023-01-09 13:03:59 +05:30
Raffael Meyer
77ce90dc63
fix: user perm check message (#19165)
* fix: german translation for perm check message

* fix: all the translations  💬
2022-12-08 18:46:06 +05:30
Sagar Vora
73edbf7ff3 fix: validate parentfield while checking child perms 2022-12-04 20:06:26 +00:00
Sagar Vora
389e675764 fix: ensure correct parenttype when retrieving roles 2022-12-05 00:44:09 +05:30
Ankush Menat
2eec621e95 chore: db.get_all -> get_all
Reduces 1 pointless function call.
Function calls are also not "super cheap" in python.
2022-08-22 11:35:14 +05:30
Sagar Vora
c82b6e758e
Merge pull request #17681 from resilient-tech/fix-child-perm
refactor: improved child table permission check
2022-08-09 10:15:36 +00:00
Sagar Vora
7a19d65ea4 chore: improve docstring 2022-08-09 12:14:26 +05:30
vishdha
9a50c30586 fix: add_user_permission with applicale_for arg set not updating in user permission 2022-08-05 00:27:38 +02:00
Sagar Vora
53118367b2 fix: use warn util 2022-08-02 19:08:02 +05:30
Sagar Vora
56717602b4 fix: reverse logic for failing permission check 2022-08-02 04:09:01 +05:30
Sagar Vora
61ec026712 refactor: improve frappe.only_for 2022-08-01 22:10:25 +00:00
Sagar Vora
d6aa17cc14 chore: add deprecation warning everywhere verbose is used 2022-07-31 00:24:21 +05:30
Sagar Vora
2b873b34dd refactor: remove verbose parameter; add user parameter to Meta.get_permlevel_access 2022-07-30 23:52:20 +05:30