# # # # profiles_dashboard_util.cfv # # # include "templates.util.encoding"; # # # get_is_profile_dashboard_view_permission() # # subroutine(get_is_profile_dashboard_view_permission( node user_grants, string profile_name), ( # This checks if the user has permission to view the profiles dashboard # for the given profile. bool is_profile_dashboard_view_permission = false; if ((?(user_grants . ".all_profiles_grants.view_profiles_dashboard") and @(user_grants . ".all_profiles_grants.view_profiles_dashboard")) or (?(user_grants . ".profiles_grants." . profile_name . ".view_profiles_dashboard") and @(user_grants . ".profiles_grants." . profile_name . ".view_profiles_dashboard"))) then ( is_profile_dashboard_view_permission = true; ); # Return is_profile_dashboard_view_permission; )); # # # get_raw_report_field_label() # # subroutine(get_raw_report_field_label( string profile_name, string report_field_name), ( # This returns the raw language variable label of the report field. string raw_report_field_label; if (?("profiles." . profile_name . ".statistics.report_fields." . report_field_name)) then ( node report_field = "profiles." . profile_name . ".statistics.report_fields." . report_field_name; # Check custom label if (report_field?{"column_label"} and @report_field{"column_label"} ne "") then ( raw_report_field_label = @report_field{"column_label"}; ) else ( # Use regular label raw_report_field_label = @report_field{"label"}; ); ); # Return raw_report_field_label; )); # # # get_profiles_dashboard_view_column_profiles_dat() # # subroutine(get_profiles_dashboard_view_column_profiles_dat( bool is_root_admin, node user_grants, node column_profiles), ( string column_profiles_dat = "["; node item; string item_dat; string profile_name; string report_field_name; # raw_report_field_label is the raw language variable, it is # required when saving existing cell data. string raw_report_field_label; string report_field_label; foreach item column_profiles ( # Make sure the profile exists and the user # has profiles_dashboard view permission for this # profile. If the user has no profile permission then # ignore it. profile_name = @item{"profile_name"}; if (?("profiles." . profile_name) and (is_root_admin or get_is_profile_dashboard_view_permission(user_grants, profile_name))) then ( report_field_name = @item{"report_field"}; raw_report_field_label = ""; report_field_label = ""; # report_field_label may not yet exist in profiles_dashboard.cfg if (item?{"report_field_label"}) then ( raw_report_field_label = @item{"report_field_label"}; ) else if (report_field_name ne "") then ( # Get raw_report_field_label raw_report_field_label = get_raw_report_field_label(profile_name, report_field_name); ); report_field_label = get_expanded_label(raw_report_field_label); item_dat = "{"; item_dat .= add_json("profile_name", profile_name, "string"); item_dat .= add_json("show_label", (@item{"show_label"}), "bool"); item_dat .= add_json("label", (@item{"label"}), "string"); item_dat .= add_json("report_field", report_field_name, "string"); item_dat .= add_json("raw_report_field_label", raw_report_field_label, "string"); item_dat .= add_json("report_field_label", report_field_label, "string"); item_dat = close_json(item_dat); column_profiles_dat .= item_dat . ","; ); ); if (column_profiles_dat ne "[") then ( column_profiles_dat = replace_last(column_profiles_dat, ",", "]"); ) else ( column_profiles_dat .= "]"; ); # debug_message("#### column_profiles_dat: " . column_profiles_dat . "\n"); # return column_profiles_dat; )); # # # get_profiles_dashboard_view_column_dat() # # subroutine(get_profiles_dashboard_view_column_dat( bool is_root_admin, node user_grants, node column), ( string profile_name = @column{"profile_name"}; bool show_column_label = @column{"show_column_label"}; string column_label = @column{"column_label"}; bool show_cell_labels = @column{"show_cell_labels"}; string cell_label = @column{"cell_label"}; string report_field_name; # raw_report_field_label is the raw language variable, it is # required when saving existing cell data. string raw_report_field_label; string report_field_label; # Make sure the profile exists # TODO - We should use the already available profiles directory checksum and only # check for profile existence if the checksum is not up to date. # We could also check for report field existence and up to date report field labels if # the checksum is out of sync. if (profile_name ne "") then ( if (?("profiles." . profile_name)) then ( report_field_name = @column{"report_field"}; # Check report field existence if (report_field_name ne "" and ?("profiles." . profile_name . ".statistics.report_fields." . report_field_name)) then ( # Get raw_report_field_label report_field_label anyway, # it will be required in case of editing the column. # report_field_label may not yet exist in profiles_dashboard.cfg if (column?{"report_field_label"}) then ( raw_report_field_label = @column{"report_field_label"}; ) else ( raw_report_field_label = get_raw_report_field_label(profile_name, report_field_name); ); report_field_label = get_expanded_label(raw_report_field_label); ) else ( # Reset report field report_field_name = ""; ); ) else ( profile_name = ""; ); ); string profiles_dat = get_profiles_dashboard_view_column_profiles_dat(is_root_admin, user_grants, column{"profiles"}); string columns_dat = "{"; columns_dat .= add_json("profile_name", profile_name, "string"); columns_dat .= add_json("show_column_label", show_column_label, "bool"); columns_dat .= add_json("column_label", column_label, "string"); columns_dat .= add_json("show_cell_labels", show_cell_labels, "bool"); columns_dat .= add_json("cell_label", cell_label, "string"); columns_dat .= add_json("report_field", report_field_name, "string"); columns_dat .= add_json("raw_report_field_label", raw_report_field_label, "string"); columns_dat .= add_json("report_field_label", report_field_label, "string"); columns_dat .= add_json("profiles", profiles_dat, "obj"); columns_dat = close_json(columns_dat); # return columns_dat; )); # # # get_profiles_dashboard_view_dat() # # subroutine(get_profiles_dashboard_view_dat( bool is_root_admin, bool is_view_dashboard_permission, node user_grants), ( # This returns profiles_dashboard.cfg as JSON object. # The node LogAnalysisInfo/profiles_dashboard.cfg may not yet exist. node profiles_dashboard; if ((is_root_admin or is_view_dashboard_permission) and ?("profiles_dashboard")) then ( profiles_dashboard = "profiles_dashboard"; ) else ( # This is used if no view/edit dashboard permission # and if no profiles_dashboard file exists. profiles_dashboard = new_node(); ); bool show_database_info = if (profiles_dashboard?{"show_database_info"}) then (@profiles_dashboard{"show_database_info"}) else (false); string date_filter = if (profiles_dashboard?{"date_filter"}) then (@profiles_dashboard{"date_filter"}) else (""); string columns_dat = "["; if (profiles_dashboard?{"columns"}) then ( node columns = profiles_dashboard{"columns"}; node column; string column_dat; foreach column columns ( column_dat = get_profiles_dashboard_view_column_dat(is_root_admin, user_grants, column); columns_dat .= column_dat . ","; ); ); if (columns_dat eq "[") then ( columns_dat .= "]"; ) else ( columns_dat = replace_last(columns_dat, ",", "]"); ); string dashboard_view_dat = "{"; dashboard_view_dat .= add_json("show_database_info", show_database_info, "bool"); dashboard_view_dat .= add_json("date_filter", date_filter, "string"); dashboard_view_dat .= add_json("columns", columns_dat, "obj"); dashboard_view_dat = close_json(dashboard_view_dat); # return dashboard_view_dat; ));