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(PWA): fetch HR Settings from API instead of documentResource to avoid permission issues #1861

Merged
merged 1 commit into from
Jun 7, 2024
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
16 changes: 10 additions & 6 deletions frontend/src/components/CheckInPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="flex flex-col bg-white rounded w-full py-6 px-4 border-none">
<h2 class="text-lg font-bold text-gray-900">Hey, {{ employee?.data?.first_name }} 👋</h2>

<template v-if="HRSettings.doc?.allow_employee_checkin_from_mobile_app">
<template v-if="settings.data?.allow_employee_checkin_from_mobile_app">
<div class="font-medium text-sm text-gray-500 mt-1.5" v-if="lastLog">
Last {{ lastLogType }} was at {{ lastLogTime }}
</div>
Expand All @@ -27,7 +27,7 @@
</div>

<ion-modal
v-if="HRSettings.doc?.allow_employee_checkin_from_mobile_app"
v-if="settings.data?.allow_employee_checkin_from_mobile_app"
ref="modal"
trigger="open-checkin-modal"
:initial-breakpoint="1"
Expand All @@ -43,7 +43,7 @@
</div>
</div>

<template v-if="HRSettings.doc?.allow_geolocation_tracking">
<template v-if="settings.data?.allow_geolocation_tracking">
<span v-if="locationStatus" class="font-medium text-gray-500 text-sm">
{{ locationStatus }}
</span>
Expand Down Expand Up @@ -71,10 +71,9 @@
</template>

<script setup>
import { createListResource, toast, FeatherIcon } from "frappe-ui"
import { createResource, createListResource, toast, FeatherIcon } from "frappe-ui"
import { computed, inject, ref, onMounted, onBeforeUnmount } from "vue"
import { IonModal, modalController } from "@ionic/vue"
import { HRSettings } from "@/data/HRSettings"

const DOCTYPE = "Employee Checkin"

Expand All @@ -86,6 +85,11 @@ const latitude = ref(0)
const longitude = ref(0)
const locationStatus = ref("")

const settings = createResource({
url: "hrms.api.get_hr_settings",
auto: true,
})

const checkins = createListResource({
doctype: DOCTYPE,
fields: ["name", "employee", "employee_name", "log_type", "time", "device_id"],
Expand Down Expand Up @@ -150,7 +154,7 @@ const fetchLocation = () => {
const handleEmployeeCheckin = () => {
checkinTimestamp.value = dayjs().format("YYYY-MM-DD HH:mm:ss")

if (HRSettings.doc?.allow_geolocation_tracking) {
if (settings.data?.allow_geolocation_tracking) {
fetchLocation()
}
}
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/data/HRSettings.js

This file was deleted.

10 changes: 10 additions & 0 deletions hrms/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ def get_all_employees() -> list[dict]:
)


# HR Settings
@frappe.whitelist()
def get_hr_settings() -> dict:
settings = frappe.db.get_singles_dict("HR Settings", cast=True)
return frappe._dict(
allow_employee_checkin_from_mobile_app=settings.allow_employee_checkin_from_mobile_app,
allow_geolocation_tracking=settings.allow_geolocation_tracking,
)


# Notifications
@frappe.whitelist()
def get_unread_notifications_count() -> int:
Expand Down
Loading