Document Permissions
You can modify the behaviour of doc.has_permission
document method for any DocType and add custom permission checking logic using the has_permission
hook.
app/hooks.py
has_permission = {
"Event": "app.permissions.event_has_permission",
}
The method will be passed the doc
, user
and permission_type
as arguments. It should return True
or a False
value. If None
is returned, it will fallback to default behaviour.
app/permissions.py
def event_has_permission(doc, user=None, permission_type=None):
# when reading a document allow if event is Public
if permission_type == "read" and doc.event_type == "Public":
return True
# when writing a document allow if event owned by user
if permission_type == "write" and doc.owner == user:
return True
return False
This from frappe documentation, I implemented *has permission * hook like the example but I always got none value for permission_type parameter, So I can’t modify the logic as I want , So I wonder if there is any dependency should I inject on my code, or anything I have to take care about ? Thank you