Fixed import/export servers issue reported during testing.

This commit is contained in:
Akshay Joshi 2022-01-10 16:16:10 +05:30
parent e43a87da09
commit 7fe1d89891
3 changed files with 17 additions and 13 deletions

View File

@ -451,7 +451,9 @@ def dump_database_servers(output_file, selected_servers,
object_dict["Servers"] = server_dict
# retrieve storage directory path
storage_manager_path = get_storage_directory()
storage_manager_path = None
if not from_setup:
storage_manager_path = get_storage_directory(user)
# generate full path of file
file_path = unquote(output_file)
@ -470,7 +472,7 @@ def dump_database_servers(output_file, selected_servers,
# write to file
file_content = json.dumps(object_dict, indent=4)
error_str = gettext("Error: {0}")
error_str = "Error: {0}"
try:
with open(file_path, 'w') as output_file:
output_file.write(file_content)
@ -481,8 +483,8 @@ def dump_database_servers(output_file, selected_servers,
err_msg = error_str.format(e.strerror)
return _handle_error(err_msg, from_setup)
msg = "Configuration for %s servers dumped to %s." % \
(servers_dumped, output_file)
msg = "Configuration for %s servers dumped to %s" % \
(servers_dumped, output_file.name)
print(msg)
return True, msg
@ -557,8 +559,15 @@ def load_database_servers(input_file, selected_servers,
load_user=current_user, from_setup=False):
"""Load server groups and servers.
"""
user = _does_user_exist(load_user, from_setup)
if user is None:
return False, USER_NOT_FOUND % load_user
# retrieve storage directory path
storage_manager_path = get_storage_directory()
storage_manager_path = None
if not from_setup:
storage_manager_path = get_storage_directory(user)
# generate full path of file
file_path = unquote(input_file)
if storage_manager_path:
@ -580,10 +589,6 @@ def load_database_servers(input_file, selected_servers,
f.close()
user = _does_user_exist(load_user, from_setup)
if user is None:
return False, USER_NOT_FOUND % load_user
user_id = user.id
# Counters
groups_added = 0

View File

@ -16,7 +16,7 @@ from flask_security import current_user
from werkzeug.exceptions import InternalServerError
def get_storage_directory():
def get_storage_directory(user=current_user):
import config
if config.SERVER_MODE is not True:
return None
@ -44,7 +44,7 @@ def get_storage_directory():
return ret_un
username = _preprocess_username(current_user.username.split('@')[0])
username = _preprocess_username(user.username.split('@')[0])
# Figure out the old-style storage directory name
old_storage_dir = os.path.join(
@ -53,7 +53,7 @@ def get_storage_directory():
username
)
username = _preprocess_username(current_user.username)
username = _preprocess_username(user.username)
# Figure out the new style storage directory name
storage_dir = os.path.join(

View File

@ -11,7 +11,6 @@
and settings database."""
import argparse
import json
import os
import sys
import builtins