# # # get_profile_data_util.cfv # # # include "templates.util.profiles.get_permitted_profiles"; # # # # get_is_valid_profile() # # # subroutine(get_is_valid_profile( node profile), ( # This checks the profile to be a valid version 8.5+ profile. # The profile subnode "database.options.server.type" only exists since version 8 # and snapons exist since version 8.5. bool is_valid_profile = (?(profile . ".database.options.server.type") and profile?{"snapons"}); # return is_valid_profile; )); # # # # get_invalid_profile_version() # # # subroutine(get_invalid_profile_version( node profile), ( # This returns the profile version of invalid profiles # depending on the given subnodes of the profile. # It is used to indicate version 7 profiles which must be imported # or 8.0/8.1 profiles which must be converted to version 8.5. # # Returns # 7.0 for all versions prior 8.0 # 8.0 for all versions prior 8.5 string version = ""; if (?(profile . ".database.options.server.type") and !profile?{"snapons"}) then ( # This must be a 8.0 or 8.1 version version = "8.0"; ) else ( # This must be version 7.0 or unknown version = "7.0"; ); # return version; )); # # # database_type_to_number() # # subroutine(database_type_to_number( string database_type), ( # Returns an integer for database_type, it is used to save space. int type_num; if (database_type eq "" or database_type eq "internal_sql") then ( type_num = 0; ) else if (database_type eq "mysql") then ( type_num = 1; ) else if (database_type eq "odbc_mssql") then ( type_num = 2; ) else if (database_type eq "odbc_oracle") then ( type_num = 3; ) else ( # Throw an error error("Unknown database_type: " . database_type); ); # Return type_num; )); # # # # get_profile_item_dat() # # # subroutine(get_profile_item_dat( string user_node_name, string profile_name, node the_profile), ( string profile_label = @the_profile{"label"}; string database_type; string database_name; string default_date_filter; string created_by_user; string username; string version; # only required for invalid profiles # Make sure that the profile isn't from an older version bool is_valid_profile = get_is_valid_profile(the_profile); if (is_valid_profile) then ( database_name = @(the_profile . ".database.options.server.database_name"); database_type = @(the_profile . ".database.options.server.type"); default_date_filter = if (?(the_profile . ".statistics.miscellaneous.date_filter.df")) then (@(the_profile . ".statistics.miscellaneous.date_filter.df")) else (""); version = ""; # must be empty for valid profile username = ""; created_by_user = if (the_profile?{"created_by_user"} and (@the_profile{"created_by_user"} ne "")) then (@the_profile{"created_by_user"}) else ("root_admin"); if (created_by_user ne user_node_name) then ( # This profile has been created by another user, so we show the username # next to the profile name, i.e. "profile 1 (by user 2)" node users = "users"; if (users?{created_by_user}) then ( username = @(users . "." . created_by_user . ".username"); ) else ( username = lang_admin.profiles.unknown_user; ); ); ) else ( # Invalid profile. This is most likely a version 8.0, 8.1 or 7.x profile version = get_invalid_profile_version(the_profile); username = ""; created_by_user = ""; database_name = ""; default_date_filter = ""; # is_view_reports = false; # is_view_config = false; # is_rename = false; ); # profiles_dat .= "{"; # profiles_dat .= add_json("isValidProfile", is_valid_profile, "bool"); # profiles_dat .= add_json("version", version, "string"); # profiles_dat .= add_json("name", profile_name, "string"); # profiles_dat .= add_json("label", profile_label, "string"); # profiles_dat .= add_json("databaseType", database_type, "string"); # profiles_dat .= add_json("databaseName", database_name, "string"); # profiles_dat .= add_json("username", username, "string"); # profiles_dat .= add_json("df", default_date_filter, "string"); # profiles_dat .= add_json("isViewReports", is_view_reports, "bool"); # profiles_dat .= add_json("isViewConfig", is_view_config, "bool"); # profiles_dat .= add_json("isRename", is_rename, "bool"); # profiles_dat .= add_json("isDelete", is_delete, "bool"); # profiles_dat = close_json(profiles_dat) . ","; # Changing object to array because profilesDb becomes saved on client. # IE6 and IE7 have a size limit. string profile_item_dat = "["; profile_item_dat .= '"' . profile_name . '",'; profile_item_dat .= '"' . encode_json(profile_label) . '",'; profile_item_dat .= database_type_to_number(database_type) . ','; profile_item_dat .= '"' . encode_json(database_name) . '",'; profile_item_dat .= '"' . encode_json(username) . '",'; profile_item_dat .= '"' . encode_json(default_date_filter) . '",'; # profile_item_dat .= is_view_reports . ','; # profile_item_dat .= is_view_config . ','; # profile_item_dat .= is_rename . ','; # profile_item_dat .= is_delete . ','; profile_item_dat .= '"' . encode_json(version) . '"'; profile_item_dat .= ']'; # Return profile_item_dat; )); # # # # get_profiles_dat() # # # subroutine(get_profiles_dat( string session_id, bool is_root_admin, string user_node_name, node the_profiles), ( # This returns profilesDb array # for the permitted profiles in the_profiles. # the_profiles contains only permitted profiles. # Sort profiles # KHP 05/Nov/2008, moved sorting to client side because the list must be re-sorted upon client side anyway # when a new profile is created. node item; node the_profile; string profile_name; string profile_item_dat; string profiles_dat = "["; foreach item the_profiles ( profile_name = node_name(item); if (is_root_admin) then ( # item already presents the actual profile node the_profile = item; ) else ( # Get the actual profile node the_profile = "profiles." . profile_name; ); profile_item_dat = get_profile_item_dat( user_node_name, profile_name, the_profile); profiles_dat .= profile_item_dat . ','; ); if (profiles_dat ne "[") then ( profiles_dat = replace_last(profiles_dat, ",", "]"); ) else ( profiles_dat .= "]"; ); # Return profiles_dat profiles_dat; )); # # # # get_profiles_list_data_after_profiles_changes() # # # subroutine(get_profiles_list_data_after_profiles_changes( string session_id, bool is_root_admin, string user_node_name, string client_profiles_list_checksum, string profiles_list_checksum_before_profile_modification, string profile_name, string operation), ( # This returns a JSON object with a new profiles_list_checksum after a profile # has been created, modified, renamed or deleted. # If the client_profiles_list_checksum is equal the profiles_list_checksum_before_profile_modification # then the client only requires the new profiles_list_checksum and a few profile item data (except upon deletion). # operation is: new_profile, delete_profile, rename_profile, save_profile bool requires_new_profiles_list = (client_profiles_list_checksum ne profiles_list_checksum_before_profile_modification); # Get new profiles_list_checksum (profile has already been modified, added or deleted) string new_profiles_list_checksum = get_profiles_list_checksum(session_id, is_root_admin, user_node_name); string dat ="{"; dat .= add_json("profilesListChecksum", new_profiles_list_checksum, "string"); dat .= add_json("isNewProfilesList", requires_new_profiles_list, "bool"); if (requires_new_profiles_list) then ( # The client profiles list is out of sync, so we resend all profiles node the_profiles; if (is_root_admin) then ( the_profiles = "profiles"; ) else ( # Handle RBAC permissions. # Create a separate with permitted profiles only the_profiles = get_permitted_profiles(session_id); ); int num_permitted_profiles = num_subnodes(the_profiles); int num_all_profiles = if (is_root_admin) then (num_permitted_profiles) else (num_subnodes("profiles")); # Includes also profiles for which the user has no access permission! string profiles_dat = get_profiles_dat(session_id, is_root_admin, user_node_name, the_profiles); dat .= add_json("profilesDb", profiles_dat, "obj"); dat .= add_json("numAllProfiles", num_all_profiles, "int"); dat .= add_json("numPermittedProfiles", num_permitted_profiles, "int"); ) else ( if (operation eq "delete_profile") then ( # We only need the profile_name dat .= add_json("profileName", profile_name, "string"); ) else ( # Get profile item data node the_profile = "profiles." . profile_name; # TODO - Test permissions for non-root-admins # bool is_view_reports = true; # bool is_view_config = true; # bool is_rename = true; # bool is_delete = true; string profile_item_dat = get_profile_item_dat( user_node_name, profile_name, the_profile); dat .= add_json("profileItem", profile_item_dat, "obj"); ); ); dat = close_json(dat); # Return dat; ));