{= # # # check_snapon_operation_state.cfv # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.util.encoding"; debug_message("\n#### check_snapon_operation_state.cfv START \n\n"); # We check the state of the current snapon operation task and return # is_active_task and is_complete string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); string page_token = v.fp.page_token; string profile_name = internal.profile_name; # # Check RBAC permissions # if ((is_root_admin or get_config_feature_permission(session_id, profile_name, "snapons", "edit")) and get_is_valid_page_token(session_id, "snapons", page_token)) then ( string snapon_name_to_be_checked = v.fp.snapon_name_to_be_checked; bool is_attach_snapon = v.fp.is_attach_snapon; string task_id = v.fp.task_id; string error_message; # # # Check if snapon task is active and completed # # # # Make sure the task exists # bool task_exists = false; bool is_active_task = false; bool task_completed = false; bool snapon_exists_in_profile; int count = 0; node task_info; # Create rooted task_item node delete_node("v.check_snapon_operation_state_task_item"); v.check_snapon_operation_state_task_item = ""; node task_item = "v.check_snapon_operation_state_task_item"; while (!task_exists and (count < 15)) ( sleep_milliseconds(1000); task_info = get_task_info(); if (task_info?{task_id}) then ( task_exists = true; # Clone single task so that we can delete the task_info node clone_node(task_info{task_id}, task_item); debug_message("\n" . node_as_string(task_item) . "\n"); ); # Clean up delete_node(task_info); count++; ); debug_message("#### check_snapon_operation_state.cfv - task_exists: " . task_exists . "\n"); # # # Check if the task completed # # if (task_exists) then ( is_active_task = (task_item?{"active"} and @task_item{"active"}); debug_message("#### check_snapon_operation_state.cfv - is_active_task: " . is_active_task . "\n"); if (!is_active_task) then ( # Check if the snapon item has been added or removed from the profiles snapons node snapon_exists_in_profile = (?("profiles." . profile_name . ".snapons." . snapon_name_to_be_checked)); debug_message("#### check_snapon_operation_state.cfv - profile_name: " . profile_name . "\n"); debug_message("#### check_snapon_operation_state.cfv - snapon_name_to_be_checked: " . snapon_name_to_be_checked . "\n"); debug_message("#### check_snapon_operation_state.cfv - snapon_exists_in_profile: " . snapon_exists_in_profile . "\n"); debug_message("\n" . node_as_string("profiles." . profile_name . ".snapons") . "\n"); if ((is_attach_snapon and snapon_exists_in_profile) or (!is_attach_snapon and !snapon_exists_in_profile)) then ( task_completed = true; ); ); debug_message("\n#### task_item:\n" . node_as_string(task_item) . "\n"); if (task_item?{"error_message"}) then ( # error_message = @task_item{"error_message"}; error(@task_item{"error_message"}); ); ) else ( # There is no task node for the current task. error(lang_admin.snapons.no_task_for_snapon_operation); ); # Clean up delete_node(task_item); # # # Response # # string dat = "{"; dat .= add_json("taskId", task_id, "string"); dat .= add_json("isActiveTask", is_active_task, "bool"); dat .= add_json("taskCompleted", task_completed, "bool"); dat .= add_json("errorMessage", error_message, "string"); dat = close_json(dat); debug_message("#### dat:\n" . dat . "\n"); "snapons.checkSnaponOperationStateResponse(" . dat . ")\n"; ) else ( # No permission to access this resource (URL) display_no_permission_html(); ); debug_message("\n#### check_snapon_operation_state.cfv END \n\n"); =}