{= # # # 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.rbac.create_user_grants"; 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 # delete_node("volatile.database_info"); get_database_info(source_profile_name, "volatile.database_info", false); node db_info = "volatile.database_info"; 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 database_is_ready_for_reporting = get_database_is_ready_for_reporting(db_info); bool initial_build_done = get_initial_build_done(db_info); # # 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 RBAC # if (!is_root_admin) then ( string licensing_features = get_licensing_features(); if (licensing_features ne "lite") then ( add_new_profile_to_user(licensing_features, 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; ); ) 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(is_root_admin, user_node_name); # # # Send response # # string dat = "{"; dat .= add_json("errorMessage", error_message, "string"); dat .= add_json("profilesDb", profiles_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"); =}