How to give permissions to User on Tasks in Projects based on Department?

prerequisite
created employee and filled the user_id field

create query_condition server script for both Project and Task respectively.

Query condition server script for Project doctype

department = frappe.db.get_value('Employee',{'user_id':frappe.user},'department')
conditions = """ department = '%s')""" %(department)

for Task

department = frappe.db.get_value('Employee',{'user_id':frappe.user},'department')
conditions = """ department = '%s')""" %(department)