Skip to content

Commit

Permalink
fix: read-only form for multiple role access in the same workflow sta…
Browse files Browse the repository at this point in the history
…te (#21008)

(cherry picked from commit eea57db)
  • Loading branch information
bhavesh95863 authored and mergify[bot] committed May 16, 2023
1 parent 4de6990 commit b4ffb62
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions frappe/public/js/frappe/model/workflow.js
Expand Up @@ -36,11 +36,13 @@ frappe.workflow = {
frappe.workflow.setup(doc.doctype);
return frappe.xcall("frappe.model.workflow.get_transitions", { doc: doc });
},
get_document_state: function (doctype, state) {
get_document_state_roles: function (doctype, state) {
frappe.workflow.setup(doctype);
return frappe.get_children(frappe.workflow.workflows[doctype], "states", {
state: state,
})[0];
let workflow_states =
frappe.get_children(frappe.workflow.workflows[doctype], "states", { state: state }) ||
[];
let allow_edit_list = workflow_states.map((d) => d.allow_edit);
return allow_edit_list;
},
is_self_approval_enabled: function (doctype) {
return frappe.workflow.workflows[doctype].allow_self_approval;
Expand All @@ -55,14 +57,13 @@ 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
let allow_edit_roles = state
? frappe.workflow.get_document_state_roles(doctype, state)
: null;

if (!frappe.user_roles.includes(allow_edit)) {
return true;
}
let has_common_role = frappe.user_roles.some((role) =>
allow_edit_roles.includes(role)
);
return !has_common_role;
}
return false;
},
Expand Down

0 comments on commit b4ffb62

Please sign in to comment.