{= # # # rename_profile.cfv # # include "templates.util.base_util"; include "templates.util.rbac.rbac_util"; include "templates.util.encoding"; include "templates.util.database"; include "templates.util.profiles.new_profile_util"; include "templates.util.profiles.get_profile_data_util"; include "templates.util.profiles.get_profiles_user_grants"; include "templates.util.rbac.create_user_grants"; include "templates.util.backup_util"; include "templates.admin_pages.profiles.rename_profile_util"; debug_message("\n\n#### rename_profile.cfv START \n\n"); string session_id = volatile.session_id; string page_token = v.fp.page_token; string source_profile_name = v.fp.source_profile_name; # Make sure the user has permission to rename this profile bool is_rename_permission = get_is_rename_profile_permission(source_profile_name); if (is_rename_permission and get_is_valid_page_token(session_id, "profiles", page_token)) then ( debug_message("\n" . node_as_string("v.fp") . "\n"); string new_profile_name = v.fp.new_profile_name; string new_profile_label = v.fp.new_profile_label; string new_database_name = v.fp.new_database_name; bool is_root_admin = get_is_root_admin(); string user_node_name = node_name(volatile.authenticated_user_node_path); node profiles = "profiles"; bool source_profile_exists = (profiles?{source_profile_name}); string error_message = ""; if (source_profile_exists) then ( # # # # Rename the profile # # # node source_profile = profiles{source_profile_name}; if (new_profile_name eq source_profile_name) then ( # # # Rename profile label only # # # We only rename the label of the profile, no further action is required # because the node name does not change. This are usually changes # in character case, i.e. when renaming "profile 1" to "PROFILE 1", so # the node name is still profile_1. # @source_profile{"label"} = new_profile_label; save_node(source_profile); ) else ( # # Make sure that nobody else created a profile which has the new_profile_name # if (!profiles?{"new_profile_name"}) then ( # # Make sure that no database is building or updating # node db_info = get_database_info(source_profile_name, false); bool database_is_building = get_database_is_building(source_profile_name, db_info); if (!database_is_building) then ( string database_server_type = @(source_profile . ".database.options.server.type"); bool is_real_time_processing = get_is_real_time_processing(profile_name); bool database_is_ready_for_reporting = get_database_is_ready_for_reporting(db_info); bool initial_build_done = get_initial_build_done(db_info, is_real_time_processing); # # Clone source profile to new profile name # clone_node(source_profile, profiles{new_profile_name}); # # Set new_profile_label # @profiles{new_profile_name}{"label"} = new_profile_label; # # Set new database_name # if (new_database_name ne "") then ( @profiles{new_profile_name}{"database"}{"options"}{"server"}{"database_name"} = new_database_name; ); # # Handle the profile database # rename_profile_database(source_profile_name, new_profile_name); # # Update relevant create_profile_wizard_info data # string info_path = profiles . "." . new_profile_name . ".create_profile_wizard_info"; if (?(info_path)) then ( # KHP 05/May/2011 - don't delete create_profile_wizard_info, it may be required by -a rp, # instead update relevant create_profile_wizard_info data. # delete_node(profiles . "." . new_profile_name . ".create_profile_wizard_info"); info_path . ".profile_name" = new_profile_label; info_path . ".created_by_user" = user_node_name; ); # # Save the renamed profile # save_node(profiles{new_profile_name}); # # Delete the source profile # delete_node(source_profile); # # Handle profile dependencies # handle_rename_profile_dependencies(source_profile_name, new_profile_name); # # Handle profile backup # handle_rename_profile_in_profile_backup(source_profile_name, new_profile_name); # # Handle RBAC # if (!is_root_admin) then ( string licensing_tier = get_licensing_tier(); if (licensing_tier ne "lite") then ( add_new_profile_to_user(licensing_tier, user_node_name, new_profile_name); create_user_grants(session_id); ); ); ) else ( # The database is building or updating, show error message error_message = lang_admin.profiles.rename_not_possible_due_active_database; ); # Clean up delete_node(db_info); ) else ( # A profile with new_profile_name already exists, show an error. error_message = lang_admin.profiles.rename_not_possible_due_existing_profile; ); ); ) else ( error_message = lang_admin.profiles.rename_not_possible_due_missing_profile; ); # # # Get fresh profiles data, also in case of an error! # # # string profiles_dat = get_profiles_dat(session_id, is_root_admin, user_node_name); # int number_of_all_profiles = num_subnodes(profiles); # Includes also profiles for which the user has no access permission! # Get profile_changes_dat # We always get fresh data because this is a rare uses case. string profile_changes_dat = get_profiles_list_data_after_profiles_changes( session_id, is_root_admin, user_node_name, "a", # client_profiles_list_checksum, not relevant though it must be different than profiles_list_checksum_before_profile_modification "b", # profiles_list_checksum_before_profile_modification, profile_name, "rename_profile"); # # Get up to date user grants for non root admin users # string profiles_user_grants_dat = "{}"; if (!is_root_admin) then ( # Get up to date user_grants node user_grants = "sessions_cache." . session_id . ".session_info.user_grants"; profiles_user_grants_dat = get_profiles_user_grants(user_grants); ); # # # Send response # # string dat = "{"; dat .= add_json("errorMessage", error_message, "string"); # dat .= add_json("profilesDb", profiles_dat, "obj"); # dat .= add_json("numberOfAllProfiles", number_of_all_profiles, "int"); dat .= add_json("profileChanges", profile_changes_dat, "obj"); dat .= add_json("userGrants", profiles_user_grants_dat, "obj"); dat = close_json(dat); 'renameProfile.renameAndSaveProfileFinalResponse(' . dat . ')'; ) else ( # No permission to view this resource (URL) display_no_permission_html(); ); debug_message("#### rename_profile.cfv END \n\n"); =}