{= # # # # save_reports.cfv (Reports and Reports Menu) # # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.util.update_reports_menu_labels"; include "templates.config_pages.reports.save_reports_util"; debug_message("#### save_reports.cfv"); # KHP-RC - currently we save all reports, regardless if it has been modified or not! # We have to change this, respectively we have to know which reports have been # modified so that we can clear the appropriate reports in sessions_cache.web_browser_sessions! string profile_name = internal.profile_name; string session_id = volatile.session_id; bool is_root_admin = get_is_root_admin(); string page_token = v.fp.page_token; # # Check RBAC permissions # if ((is_root_admin or get_config_feature_permission(session_id, profile_name, "reports", "edit")) and get_is_valid_page_token(session_id, "reports", page_token)) then ( debug_message("\n" . node_as_string("v.fp") . "\n"); node profile = "profiles." . profile_name; node new_reports = "v.fp.reports"; node deleted_reports = "v.fp.deleted_reports"; node new_reports_menu = "v.fp.reports_menu"; # debug_message("\n" . node_as_string(new_reports) . "\n"); # debug_message("#### number of new_reports: " . num_subnodes(new_reports) . "\n"); node existing_reports = profile . ".statistics.reports"; node existing_reports_menu = profile . ".statistics.reports_menu"; # # # # Handle reports # # # bool clear_reports_in_web_browser_sessions = false; if (num_subnodes(new_reports) > 0) then ( # # # Finalize new_reports data # Note, this part requires the labels of existing report data, # so we don't yet delete existing reports. # # save_reports_finalize_new_reports(existing_reports, new_reports); # # Delete existing reports # save_reports_remove_subnodes(existing_reports); # # Clone new reports to reports # clone_node(new_reports, profile . ".statistics.reports"); clear_reports_in_web_browser_sessions = true; ) else ( # # Delete existing reports # save_reports_remove_subnodes(existing_reports); ); # # # # Handle reports_menu # # # # Delete existing menu items save_reports_remove_subnodes(existing_reports_menu); if (num_subnodes(new_reports_menu) > 0) then ( save_reports_finalize_new_reports_menu(new_reports_menu); clone_node(new_reports_menu, profile . ".statistics.reports_menu"); # # Add labels to reports_menu (see templates.util.update_reports_menu_labels() for details) # update_reports_menu_labels(profile . ".statistics.reports_menu", profile . ".statistics.reports"); ); save_node(profile); # # # # Handle deleted_reports # # # # KHP-RC, handle dependencies of deleted reports # Deleted reports are tracked in client, available in node "deleted_reports" # # # # clear_reports_in_web_browser_sessions # # # # KHP-RC, we should only clear modified reports and not all, see above KHP-RC info for details. # For the time being we clear all reports in web_browser_sessions string session_profile_path = "sessions_cache." . session_id . ".profiles." . profile_name; if (?(session_profile_path . ".web_browser_sessions")) then ( node web_browser_sessions = session_profile_path . ".web_browser_sessions"; node web_browser_session; foreach web_browser_session web_browser_sessions ( if (web_browser_session?{"reports"}) then ( delete_node(web_browser_session{"reports"}); save_node(web_browser_session); ); ); ); # # # Send response # # 'saveReportChangesResponse()\n'; ) else ( # No permission to access this resource (URL) display_no_permission_html(); ); =}