I have a doctype with 3 workflow states namely Draft, Submitted, Approved. Also I have 3 level of users named user1, user2, user3. I want to control the visibility of the documents in the doctype list based on the current workflow state as user1 can see only draft & approved documents, user2 can see only Submitted documents and user3 only approved documents. I was able to achieve this in the list with client side script manipulating the filters. But this can be overridden by the user by clearing the filters. In form view also I was able to achieve this.
Is there a solution for this in frape framework level
frappe.db.get_all should be used under “controlled” circumstances from backend…
Desk (Frappe interface) always check permission system.
I’d recommend to use role permission as much you can do it … it’s really easy manage visibility for different user “levels”. In addition, framework provide even more tools: user permission (specific access to particular documents), permission levels for fields, etc …
Anyway, every use case would be different …
Hope this helps.
Still no effect. It has both get_permission_query_conditions and has_permission. has_permission executes for form level access even without hooks. But even with hooks get_permission_query_conditions is not getting invoked by the platform.
My code is below
def get_permission_query_conditions(user):
if not user:
user = frappe.session.user
roles = frappe.get_roles(user)
conditions = ""
if "Head Level User" in roles:
conditions = " workflow_state IN ('Technical Verified', 'Verified by SO')"
elif "Tech Manager" in roles:
conditions = " workflow_state = 'Submitted'"
else:
# Regular users can only see their own documents
conditions = f" owner = '{user}'"
return " and".conditions
def has_permission(doc, ptype):
user = frappe.session.user
#frappe.msgprint("has_permission")
roles = frappe.get_roles(user)
if "Head Level User" in roles:
return doc.workflow_state in ['Technical Verified', 'Verified by SO']
elif "Tech Manager" in roles:
return doc.workflow_state == 'Submitted'
else:
return doc.owner == user
yes the code was json.modified but still no effect
def get_permission_query_conditions(user):
frappe.msgprint("has_permission")
if not user:
user = frappe.session.user
roles = frappe.get_roles(user)
conditions = []
if "Head Level User" in roles:
conditions.append("workflow_state IN ('Technical Verified', 'Verified by SO')")
elif "Tech Manager" in roles:
conditions.append(" workflow_state = 'Submitted'")
else:
# Regular users can only see their own documents
conditions.append(f" owner = '{user}'")
#frappe.msgprint("Condition")
return " and ".join(conditions)
It’s working well on my side, both listview and document access… can you share hooks.py section for permissions? Any errors on error log or browser console? I assume you are working under development environment … are you tried to debug with print or breakpoint?