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
97 changes: 0 additions & 97 deletions .github/workflows/ci.yml

This file was deleted.

58 changes: 0 additions & 58 deletions .github/workflows/linter.yml

This file was deleted.

10 changes: 6 additions & 4 deletions checktrack_connector/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,14 @@ def check_tenant_exists(email):

# Step 1: Get access token using hardcoded credentials
auth_url = f"{USER_API_URL}/login"
admin_email = conf.get("checktrack_admin_email")
admin_password = conf.get("checktrack_admin_password")
auth_payload = {
"email": "jaympatel9294@gmail.com",
"password": "0hr3VuNoyqcgy1Su"
"email": admin_email,
"password": admin_password
}
HEADERS = {"Content-Type": "application/json"}

try:
auth_response = requests.post(auth_url, headers=HEADERS, json=auth_payload)

Expand All @@ -752,7 +754,7 @@ def check_tenant_exists(email):

if not employee.get("company"):
return {"exists": False, "message": "Employee has no associated company."}

# Step 4: Get tenant_id from Company doctype
tenant_id = frappe.db.get_value("Company", employee.get("company"), "tenant_id")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ frappe.ui.form.on('CheckTrack Integration', {
frm.page.btn_primary.hide();
}
if (!frm.is_new()) {
showConnectionLoader(frm);

check_tenant_exists(frm, function(exists) {
hideConnectionLoader(frm);

if (exists) {

frm.fields.forEach(field => {
frm.set_df_property(field.df.fieldname, 'hidden', true);
if (field.df.fieldname !== 'name') { // Keep the name field visible
frm.set_df_property(field.df.fieldname, 'hidden', true);
}
});

frm.dashboard.clear_headline();
frm.dashboard.set_headline(
`<div class="alert alert-success" style="margin-bottom: 0px;">
<strong>${__("Connected to Checktrack")}</strong>
</div>`
);
frm.set_indicator(__('Connected to Frappe'), 'green');
frm.remove_custom_button('Connect');

} else {
Expand Down Expand Up @@ -131,11 +135,11 @@ frappe.ui.form.on('CheckTrack Integration', {

if (response.message) {
if (response.message.is_fully_integration) {
frappe.msgprint(__('Checktrack successfully integration.'));
frappe.msgprint(__('Checktrack successfully integrated.'));
frm.reload_doc();
}
} else {
frappe.msgprint(__('Failed to integrat!'));
frappe.msgprint(__('Failed to integrate!'));
}
})
.catch((error) => {
Expand All @@ -162,22 +166,78 @@ frappe.ui.form.on('CheckTrack Integration', {
});

function check_tenant_exists(frm, callback) {

frappe.call({
method: 'checktrack_connector.api.check_tenant_exists',
method: 'frappe.client.get_value',
args: {
email: frappe.session.user
doctype: 'User',
filters: { name: frappe.session.user },
fieldname: 'email'
},
callback: function (response) {
var exists = response.message && response.message.exists;
if (callback) callback(exists);
callback: function (r) {
const userEmail = r.message.email;
console.log("check_tenant_exists called with email:", userEmail);

frappe.call({
method: 'checktrack_connector.api.check_tenant_exists',
args: {
email: userEmail
},
callback: function (response) {
console.log("check_tenant_exists API response:", response);
var exists = response.message && response.message.exists;
console.log("Extracted exists value:", exists);
if (callback) callback(exists);
},
error: function(err) {
console.error("Error checking tenant exists:", err);
if (callback) callback(false);
}
});
},
error: function(err) {
console.error("Error checking tenant exists:", err);
console.error("Error getting user email:", err);
if (callback) callback(false);
}
});
}


function showConnectionLoader(frm) {
if (frm.fields_dict.email) {
frm.set_df_property('email', 'hidden', true);
}
if (frm.fields_dict.password) {
frm.set_df_property('password', 'hidden', true);
}

frm.dashboard.clear_headline();
frm.dashboard.set_headline(
`<div class="text-center" style="padding: 20px;">
<div class="spinner-border text-primary" role="status" style="width: 1.5rem; height: 1.5rem;">
<span class="sr-only">Loading...</span>
</div>
<div class="mt-2">
<strong>${__("Checking connection status...")}</strong>
</div>
</div>`
);

frm.disable_save();
}


function hideConnectionLoader(frm) {
if (frm.fields_dict.email) {
frm.set_df_property('email', 'hidden', false);
}
if (frm.fields_dict.password) {
frm.set_df_property('password', 'hidden', false);
}

frm.dashboard.clear_headline();

frm.enable_save();
}



18 changes: 17 additions & 1 deletion checktrack_connector/onboard_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def automated_import_users(tenant_id=None, integration_email=None):
# Check if we have any data to import (excluding header)
if len(data) <= 1:
return {
"status": "warning",
"status": "success",
"message": f"No users to import after skipping integration email(s). Skipped {skipped_count} email(s)."
}

Expand Down Expand Up @@ -235,6 +235,11 @@ def import_project(tenant_id, tenant_prefix, access_token,company_name):
projects = response.json()
if not isinstance(projects, list):
return {"status": "error", "message": "No project found for the provided tenant_id"}
if not projects or len(projects) == 0:
return {
"status": "success",
"message": "No projects found, so no need to import"
}
data = [
["project_name", "description","status","company","mongo_project_id"]
]
Expand Down Expand Up @@ -290,6 +295,17 @@ def import_project(tenant_id, tenant_prefix, access_token,company_name):
}
task_list = get_task(tenant_id=tenant_id, tenant_prefix=tenant_prefix, access_token=access_token)

# Check if get_task returned an error response
if isinstance(task_list, dict) and "status" in task_list and task_list["status"] == "error":
return {"status": "error", "message": "Failed to fetch tasks", "details": task_list.get("message")}

# Check if no tasks found (this is not an error, just no data to import)
if not task_list or len(task_list) == 0:
return {
"status": "success",
"message": "No tasks found, so no need to import tasks"
}

task_data = [
["task_name", "description","assign_to","project","workflow_status","company","mongo_task_id"]
]
Expand Down