Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/components/CheckInPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const checkins = createListResource({
checkins.reload()

const lastLog = computed(() => {
if (checkins.list.loading || !checkins.data) return {}
if (!checkins.data?.length) return {}
return checkins.data[0]
})

Expand Down
4 changes: 4 additions & 0 deletions hrms/hr/doctype/leave_application/leave_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ frappe.ui.form.on("Leave Application", {
args: {
employee: frm.doc.employee,
date: frm.doc.from_date || frm.doc.posting_date,
leave_application: frm.is_new() ? null : frm.doc.name,
},
callback: function (r) {
if (!r.exc && r.message["leave_allocation"]) {
Expand Down Expand Up @@ -219,6 +220,7 @@ frappe.ui.form.on("Leave Application", {
to_date: frm.doc.to_date,
leave_type: frm.doc.leave_type,
consider_all_leaves_in_the_allocation_period: 1,
leave_application: frm.is_new() ? null : frm.doc.name,
},
callback: function (r) {
if (!r.exc && r.message) {
Expand Down Expand Up @@ -256,6 +258,7 @@ frappe.ui.form.on("Leave Application", {
to_date: frm.doc.to_date,
half_day: frm.doc.half_day,
half_day_date: frm.doc.half_day_date,
leave_application: frm.is_new() ? null : frm.doc.name,
},
callback: function (r) {
if (r && r.message) {
Expand All @@ -273,6 +276,7 @@ frappe.ui.form.on("Leave Application", {
method: "hrms.hr.doctype.leave_application.leave_application.get_leave_approver",
args: {
employee: frm.doc.employee,
leave_application: frm.is_new() ? null : frm.doc.name,
},
callback: function (r) {
if (r && r.message) {
Expand Down
50 changes: 38 additions & 12 deletions hrms/hr/doctype/leave_application/leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ def validate_block_days(self):

def validate_balance_leaves(self):
precision = cint(frappe.db.get_single_value("System Settings", "float_precision")) or 2
leave_application = None if self.is_new() else self.name

if self.from_date and self.to_date:
self.total_leave_days = get_number_of_leave_days(
Expand All @@ -450,6 +451,7 @@ def validate_balance_leaves(self):
self.to_date,
self.half_day,
self.half_day_date,
leave_application=leave_application,
)

if self.total_leave_days <= 0:
Expand All @@ -467,6 +469,7 @@ def validate_balance_leaves(self):
self.to_date,
consider_all_leaves_in_the_allocation_period=True,
for_consumption=True,
leave_application=leave_application,
)
leave_balance_for_consumption = flt(
leave_balance.get("leave_balance_for_consumption"), precision
Expand Down Expand Up @@ -1010,10 +1013,11 @@ def get_number_of_leave_days(
half_day: int | str | None = None,
half_day_date: datetime.date | str | None = None,
holiday_list: str | None = None,
leave_application: str | None = None,
) -> float:
"""Returns number of leave days between 2 dates after considering half day and holidays
(Based on the include_holiday setting in Leave Type)"""
validate_leave_access(employee)
validate_leave_access(employee, leave_application)
number_of_days = date_diff(to_date, from_date) + 1

if cint(half_day) == 1:
Expand All @@ -1026,13 +1030,20 @@ def get_number_of_leave_days(
number_of_days -= 0.5

if not frappe.db.get_value("Leave Type", leave_type, "include_holiday"):
number_of_days = flt(number_of_days) - flt(get_holidays(employee, from_date, to_date))
number_of_days = flt(number_of_days) - flt(
get_holidays(employee, from_date, to_date, leave_application=leave_application)
)
return number_of_days


@frappe.whitelist()
def get_leave_details(employee: str, date: str | datetime.date, for_salary_slip: bool = False) -> dict:
validate_leave_access(employee)
def get_leave_details(
employee: str,
date: str | datetime.date,
for_salary_slip: bool = False,
leave_application: str | None = None,
) -> dict:
validate_leave_access(employee, leave_application)

allocation_records = get_leave_allocation_records(employee, date)
leave_allocation = {}
Expand All @@ -1047,6 +1058,7 @@ def get_leave_details(employee: str, date: str | datetime.date, for_salary_slip:
date,
to_date=to_date,
consider_all_leaves_in_the_allocation_period=False if for_salary_slip else True,
leave_application=leave_application,
)

leaves_taken = get_leaves_for_period(employee, d, allocation.from_date, to_date) * -1
Expand Down Expand Up @@ -1079,6 +1091,7 @@ def get_leave_balance_on(
to_date: datetime.date | None = None,
consider_all_leaves_in_the_allocation_period: bool = False,
for_consumption: bool = False,
leave_application: str | None = None,
) -> dict[str, float]:
"""
Returns leave balance till date
Expand All @@ -1092,8 +1105,10 @@ def get_leave_balance_on(
in this case leave_balance = 10 but leave_balance_for_consumption = 1
if True, returns a dict eg: {'leave_balance': 10, 'leave_balance_for_consumption': 1}
else, returns leave_balance (in this case 10)
:param leave_application: leave application name, used to allow access for users who can read this
specific leave application even without Employee read permission
"""
validate_leave_access(employee)
validate_leave_access(employee, leave_application)

if not to_date:
to_date = nowdate()
Expand Down Expand Up @@ -1392,9 +1407,14 @@ def get_leave_entries(employee, leave_type, from_date, to_date):


@frappe.whitelist()
def get_holidays(employee: str, from_date: str | datetime.date, to_date: str | datetime.date) -> int:
def get_holidays(
employee: str,
from_date: str | datetime.date,
to_date: str | datetime.date,
leave_application: str | None = None,
) -> int:
"""get holidays between two dates for the given employee"""
validate_leave_access(employee)
validate_leave_access(employee, leave_application)
holidays = get_holiday_dates_between_range(employee, from_date, to_date)
return len(holidays)

Expand Down Expand Up @@ -1585,8 +1605,8 @@ def get_approved_leaves_for_period(employee, leave_type, from_date, to_date):


@frappe.whitelist()
def get_leave_approver(employee: str) -> str:
validate_leave_access(employee)
def get_leave_approver(employee: str, leave_application: str | None = None) -> str:
validate_leave_access(employee, leave_application)
return get_employee_leave_approver(employee)


Expand Down Expand Up @@ -1618,11 +1638,17 @@ def get_leave_approver_and_mandatory(employee: str) -> dict:
}


def validate_leave_access(employee):
def validate_leave_access(employee, leave_application=None):
employee_user = frappe.db.get_value("Employee", employee, "user_id")
leave_approver = get_employee_leave_approver(employee)

if frappe.session.user not in (employee_user, leave_approver) and (
not frappe.has_permission("Employee", "read", employee)
if (
frappe.session.user not in (employee_user, leave_approver)
and not frappe.has_permission("Employee", "read", employee)
and not (
leave_application
and frappe.db.get_value("Leave Application", leave_application, "employee") == employee
and frappe.has_permission("Leave Application", "read", leave_application)
)
):
frappe.throw(_("Not permitted"), frappe.PermissionError)
59 changes: 59 additions & 0 deletions hrms/hr/doctype/leave_application/test_leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,65 @@ def test_leave_approver_with_restricted_employee_access(self):
leave_application.submit()
self.assertEqual(leave_application.docstatus, 1)

def test_leave_access_for_workflow_reviewer_without_employee_permission(self):
reviewer_user = "reviewer_without_employee_access@example.com"
reviewer_employee = make_employee(reviewer_user, "_Test Company")
add_user_permission("Employee", reviewer_employee, reviewer_user, hide_descendants=1)

target_employee_user = "employee_reviewed_by_workflow@example.com"
target_employee = make_employee(target_employee_user, "_Test Company")
make_allocation_record(target_employee, from_date="2026-04-01", to_date="2027-03-31")

frappe.set_user(target_employee_user)
leave_application = make_leave_application(
target_employee,
from_date="2026-04-20",
to_date="2026-04-20",
leave_type="_Test Leave Type",
status="Draft",
submit=False,
)
# simulates access granted via workflow review, without a leave_approver
frappe.share.add_docshare("Leave Application", leave_application.name, reviewer_user, read=1)

frappe.set_user(reviewer_user)
self.assertRaises(
frappe.PermissionError,
frappe.get_doc("Employee", target_employee).check_permission,
"read",
)
self.assertRaises(
frappe.PermissionError,
get_leave_details,
target_employee,
leave_application.from_date,
)

leave_details = get_leave_details(
target_employee,
leave_application.from_date,
leave_application=leave_application.name,
)
self.assertTrue(leave_details["leave_allocation"])

# a leave application shared with the reviewer must not unlock a different employee's data
make_allocation_record(reviewer_employee, from_date="2026-04-01", to_date="2027-03-31")
own_leave_application = make_leave_application(
reviewer_employee,
from_date="2026-04-21",
to_date="2026-04-21",
leave_type="_Test Leave Type",
status="Draft",
submit=False,
)
self.assertRaises(
frappe.PermissionError,
get_leave_details,
target_employee,
leave_application.from_date,
leave_application=own_leave_application.name,
)


def create_carry_forwarded_allocation(employee, leave_type, date=None):
date = date or nowdate()
Expand Down
Loading