Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: read-only form for multiple role access in the same workflow state #21008

Merged
merged 8 commits into from
May 16, 2023
24 changes: 14 additions & 10 deletions frappe/public/js/frappe/model/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ frappe.workflow = {
},
get_document_state: function (doctype, state) {
frappe.workflow.setup(doctype);
return frappe.get_children(frappe.workflow.workflows[doctype], "states", {
state: state,
})[0];
var allow_edit = $.map(frappe.get_children(frappe.workflow.workflows[doctype], "states", { state: state }) || [],
function (d) {
return d.allow_edit;
});
return allow_edit
bhavesh95863 marked this conversation as resolved.
Show resolved Hide resolved
},
is_self_approval_enabled: function (doctype) {
return frappe.workflow.workflows[doctype].allow_self_approval;
Expand All @@ -55,14 +57,16 @@ frappe.workflow = {
var state =
doc[state_fieldname] || frappe.workflow.get_default_state(doctype, doc.docstatus);

var allow_edit = state
? frappe.workflow.get_document_state(doctype, state) &&
frappe.workflow.get_document_state(doctype, state).allow_edit
: null;

if (!frappe.user_roles.includes(allow_edit)) {
return true;
var allow_edit_roles = state ? frappe.workflow.get_document_state(doctype, state) : null;
var read_only = true
if (allow_edit_roles) {
allow_edit_roles.forEach(allow_edit => {
if (frappe.user_roles.includes(allow_edit)) {
read_only = false;
}
});
}
return read_only
bhavesh95863 marked this conversation as resolved.
Show resolved Hide resolved
}
return false;
},
Expand Down