Skip to content

Commit

Permalink
fix: make request action sheet permission sensitive
Browse files Browse the repository at this point in the history
(cherry picked from commit 7aa26e6)
  • Loading branch information
ruchamahabal authored and mergify[bot] committed Jun 12, 2024
1 parent 7c77140 commit aa6d4c4
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions frontend/src/components/RequestActionSheet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
/>
<div
v-else-if="['Open', 'Draft'].includes(document?.doc?.[approvalField])"
v-else-if="['Open', 'Draft'].includes(document?.doc?.[approvalField]) && hasPermission('approval')"
class="flex w-full flex-row items-center justify-between gap-3 sticky bottom-0 border-t z-[100] p-4"
>
<Button
Expand Down Expand Up @@ -111,7 +111,8 @@
<div
v-else-if="
document?.doc?.docstatus === 0 &&
['Approved', 'Rejected'].includes(document?.doc?.[approvalField])
['Approved', 'Rejected'].includes(document?.doc?.[approvalField]) &&
hasPermission('submit')
"
class="flex w-full flex-row items-center justify-between gap-3 sticky bottom-0 border-t z-[100] p-4"
>
Expand All @@ -125,7 +126,7 @@
</div>
<div
v-else-if="document?.doc?.docstatus === 1"
v-else-if="document?.doc?.docstatus === 1 && hasPermission('cancel')"
class="flex w-full flex-row items-center justify-between gap-3 sticky bottom-0 border-t z-[100] p-4"
>
<Button
Expand Down Expand Up @@ -210,6 +211,24 @@ const attachedFiles = createResource({
},
})
const docPermissions = createResource({
url: "frappe.client.get_doc_permissions",
params: { doctype: props.modelValue.doctype, docname: props.modelValue.name },
auto: true,
})
const permittedWriteFields = createResource({
url: "hrms.api.get_permitted_fields_for_write",
params: { doctype: props.modelValue.doctype },
auto: true,
})
function hasPermission(action) {
if (action === "approval")
return permittedWriteFields.data?.includes(approvalField.value)
return docPermissions.data?.permissions[action]
}
const currency = computed(() => {
let docCurrency = document?.doc?.currency
Expand Down

0 comments on commit aa6d4c4

Please sign in to comment.