Skip to content

Commit

Permalink
Merge pull request #3095 from ONE-F-M/version-15
Browse files Browse the repository at this point in the history
master to staging
  • Loading branch information
mymi14s authored Jan 24, 2024
2 parents 5ca36fb + 35eb36e commit 89231a6
Show file tree
Hide file tree
Showing 25 changed files with 1,024 additions and 1,165 deletions.
2 changes: 1 addition & 1 deletion job_applicant_magic_link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"autoprefixer": "^10.4.2",
"postcss": "^8.4.5",
"tailwindcss": "^3.0.15",
"vite": "^2.9.16"
"vite": "^2.9.17"
}
}
8 changes: 4 additions & 4 deletions job_applicant_magic_link/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1778,10 +1778,10 @@ util@^0.10.3:
dependencies:
inherits "2.0.3"

vite@^2.9.16:
version "2.9.16"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.9.16.tgz#daf7ba50f5cc37a7bf51b118ba06bc36e97898e9"
integrity sha512-X+6q8KPyeuBvTQV8AVSnKDvXoBMnTx8zxh54sOwmmuOdxkjMmEJXH2UEchA+vTMps1xw9vL64uwJOWryULg7nA==
vite@^2.9.17:
version "2.9.17"
resolved "https://registry.yarnpkg.com/vite/-/vite-2.9.17.tgz#6b770525e12fa2a2e3a0fa0d028d304f4f7dc7d4"
integrity sha512-XxcRzra6d7xrKXH66jZUgb+srThoPu+TLJc06GifUyKq9JmjHkc1Numc8ra0h56rju2jfVWw3B3fs5l3OFMvUw==
dependencies:
esbuild "^0.14.27"
postcss "^8.4.13"
Expand Down
4 changes: 3 additions & 1 deletion one_fm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
from frappe.automation.doctype.assignment_rule.assignment_rule import AssignmentRule
from one_fm.overrides.assignment_rule import do_assignment
from one_fm.overrides.goal import get_childrens
from one_fm.overrides.frappe.oauth import OAuthWebRequestValidatorOverride


__version__ = '15.0.0'


frappe.oauth.OAuthWebRequestValidator = OAuthWebRequestValidatorOverride
StockController.make_batches = make_batches_with_supplier_batch_id
Interview.validate_overlap = validate_interview_overlap
PaymentEntry.add_party_gl_entries = add_party_gl_entries_
Expand Down Expand Up @@ -93,3 +94,4 @@
ShiftAssignment = ShiftAssignmentOverride
get_children = get_childrens
AssignmentRule.do_assignment = do_assignment

40 changes: 37 additions & 3 deletions one_fm/api/v1/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def login(client_id: str = None, grant_type: str = None, employee_id: str = None
try:
site = frappe.utils.cstr(frappe.local.conf.app_url)
username = frappe.db.get_value("Employee", {'employee_id': employee_id}, 'user_id')

if not username:
return response("Unauthorized", 401, None, "Invalid employee ID")

Expand All @@ -86,7 +86,6 @@ def login(client_id: str = None, grant_type: str = None, employee_id: str = None
headers = {'Accept': 'application/json'}
session = requests.Session()
auth_api = site + "api/method/frappe.integrations.oauth2.get_token"

auth_api_response = session.post(
auth_api,
data=args, headers=headers
Expand Down Expand Up @@ -473,4 +472,39 @@ def set_password(employee_user_id, new_password):
message = {
'message': _('Password Updated!')
}
return response("Success", 200, message)
return response("Success", 200, message)

@frappe.whitelist(allow_guest=True)
def user_login(employee_id, password):
try:
username = frappe.db.get_value("Employee", {'employee_id': employee_id}, 'user_id')
if not username:
return response("Unauthorized", 401, None, "Invalid employee ID")
auth = frappe.auth.LoginManager()
auth.authenticate(user=username, pwd=password)
auth.post_login()
msg={'status':200, 'text':frappe.local.response.message, 'user': frappe.session.user}
user = frappe.get_doc('User', frappe.session.user)
if(user.api_key and user.api_secret):
msg['token'] = f"token {user.api_key}:{user.get_password('api_secret')}"
else:
session_user = frappe.session.user
frappe.set_user('Administrator')
generate_keys(user.name)
user.reload()
msg['token'] = f"token {user.api_key}:{user.get_password('api_secret')}"
frappe.set_user(session_user)
user, user_roles, user_employee = get_current_user_details()
msg.update(user_employee)
msg.update({"roles": user_roles})
if "Operations Manager" in user_roles or "Projects Manager" in user_roles or "Site Supervisor" in user_roles:
msg.update({"supervisor": 1})
else:
msg.update({"supervisor": 0})
response("success", 200, msg)
except frappe.exceptions.AuthenticationError:
print('auth eror')
response("error", 401, None, frappe.local.response.message)
except Exception as e:
print(frappe.get_traceback(), 'Email Login')
response("error", 500, None, str(e))
40 changes: 21 additions & 19 deletions one_fm/api/v1/face_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

# setup channel for face recognition
face_recognition_service_url = frappe.local.conf.face_recognition_service_url
options = [('grpc.max_message_length', 100 * 1024 * 1024* 10)]
channels = [
grpc.secure_channel(i, grpc.ssl_channel_credentials()) for i in face_recognition_service_url
grpc.secure_channel(i, grpc.ssl_channel_credentials(), options=options) for i in face_recognition_service_url
]

# setup stub for face recognition
Expand Down Expand Up @@ -49,37 +50,38 @@ def enroll(employee_id: str = None, video: str = None) -> dict:
try:
doc = frappe.get_doc("Employee", {"user_id": frappe.session.user})
# Setup channel
face_recognition_enroll_service_url = frappe.local.conf.face_recognition_enroll_service_url
channel = grpc.secure_channel(face_recognition_enroll_service_url, grpc.ssl_channel_credentials())
# setup stub
stub = enroll_pb2_grpc.FaceRecognitionEnrollmentServiceStub(channel)
# request body
req = enroll_pb2.EnrollRequest(
username = frappe.session.user,
user_encoded_video = video,
)

res = stub.FaceRecognitionEnroll(req)
data = {'employee':doc.name, 'log_type':'Enrollment', 'verification':res.enrollment,
'message':res.message, 'data':res.data, 'source': 'Enroll'}
#frappe.enqueue('one_fm.operations.doctype.face_recognition_log.face_recognition_log.create_face_recognition_log',**{'data':data})
if res.enrollment == "FAILED":
return response(res.message, 400, None, res.data)
# face_recognition_enroll_service_url = frappe.local.conf.face_recognition_enroll_service_url
# channel = grpc.secure_channel(face_recognition_enroll_service_url, grpc.ssl_channel_credentials(), options=[('grpc.max_message_length', 100 * 1024 * 1024* 10)])
# # setup stub
# stub = enroll_pb2_grpc.FaceRecognitionEnrollmentServiceStub(channel)
# # request body
# req = enroll_pb2.EnrollRequest(
# username = frappe.session.user,
# user_encoded_video = video,
# )

# res = stub.FaceRecognitionEnroll(req)
# data = {'employee':doc.name, 'log_type':'Enrollment', 'verification':res.enrollment,
# 'message':res.message, 'data':res.data, 'source': 'Enroll'}
# #frappe.enqueue('one_fm.operations.doctype.face_recognition_log.face_recognition_log.create_face_recognition_log',**{'data':data})
# if res.enrollment == "FAILED":
# return response(res.message, 400, None, res.data)

doc.enrolled = 1
doc.save(ignore_permissions=True)
update_onboarding_employee(doc)
frappe.db.commit()

return response("Success", 201, "User enrolled successfully.")
return response("Success", 201, "User enrolled successfully.<br>Please wait for 10sec, you will be redirected to checkin.")

except Exception as error:
frappe.log_error(message=error, title="Enrollment")
return response("Internal Server Error", 500, None, error)


@frappe.whitelist()
def verify_checkin_checkout(employee_id: str = None, video : str = None, log_type: str = None,
skip_attendance: str = None, latitude: str = None, longitude: str = None):
skip_attendance: str = None, latitude: str = None, longitude: str = None):
"""This method verifies user checking in/checking out.
Args:
Expand Down
1 change: 1 addition & 0 deletions one_fm/api/v1/leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def get_leave_balance(employee_id: str = None, leave_type: str = None) -> dict:
error (str): Any error handled.
}
"""
return response("Success", 200, [])
if not employee_id:
return response("Bad Request", 400, None, "employee_id required.")

Expand Down
Loading

0 comments on commit 89231a6

Please sign in to comment.