Commit 679ba5fc authored by Łukasz Nowak's avatar Łukasz Nowak

- formatting and typos


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@34271 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4373e555
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from ZPublisher.HTTPRequest import FileUpload from ZPublisher.HTTPRequest import FileUpload
from Globals import DTMLFile from Globals import DTMLFile
from Products.ERP5Type.Accessor.Constant import PropertyGetter as ConstantGetter from Products.ERP5Type.Accessor.Constant import PropertyGetter as \
ConstantGetter
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Wizard import _dtmldir from Products.ERP5Wizard import _dtmldir
...@@ -46,7 +47,8 @@ from urlparse import urlparse, urlunparse ...@@ -46,7 +47,8 @@ from urlparse import urlparse, urlunparse
from base64 import encodestring, decodestring from base64 import encodestring, decodestring
from urllib import quote, unquote from urllib import quote, unquote
from DateTime import DateTime from DateTime import DateTime
from Products.PluggableAuthService.interfaces.plugins import IAuthenticationPlugin from Products.PluggableAuthService.interfaces.plugins import \
IAuthenticationPlugin
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
# global (RAM) cookie storage # global (RAM) cookie storage
...@@ -77,7 +79,8 @@ def _isUserAcknowledged(cookiejar): ...@@ -77,7 +79,8 @@ def _isUserAcknowledged(cookiejar):
return 1 return 1
return 0 return 0
def _getAcCookieFromServer(url, opener, cookiejar, username, password, header_dict = {}): def _getAcCookieFromServer(url, opener, cookiejar, username, password,
header_dict = {}):
""" get __ac cookie from server """ """ get __ac cookie from server """
data = urllib.urlencode({'__ac_name': username, data = urllib.urlencode({'__ac_name': username,
'__ac_password': password}) '__ac_password': password})
...@@ -107,7 +110,8 @@ class GeneratorCall(UserDict): ...@@ -107,7 +110,8 @@ class GeneratorCall(UserDict):
for item in self.convert_data[binary_key]: for item in self.convert_data[binary_key]:
self[binary_key].append(self._decodeData(item[16:-18])) self[binary_key].append(self._decodeData(item[16:-18]))
else: else:
self[binary_key] = self._decodeData(self.convert_data[binary_key][16:-18]) self[binary_key] = self._decodeData(self.convert_data[binary_key]
[16:-18])
## load string keys ## load string keys
for string_key in self._string_keys: for string_key in self._string_keys:
self[string_key] = self.convert_data[string_key] self[string_key] = self.convert_data[string_key]
...@@ -127,7 +131,8 @@ class GeneratorCall(UserDict): ...@@ -127,7 +131,8 @@ class GeneratorCall(UserDict):
self.convert_data[binary_key] = None self.convert_data[binary_key] = None
for string_key in self._string_keys: for string_key in self._string_keys:
self.convert_data[string_key] = self[string_key] self.convert_data[string_key] = self[string_key]
return xmlrpclib.dumps((self.convert_data,), 'GeneratorAnswer', allow_none=1) return xmlrpclib.dumps((self.convert_data,), 'GeneratorAnswer',
allow_none=1)
def _decodeData(self, data): def _decodeData(self, data):
""" Decode data. """ """ Decode data. """
...@@ -136,7 +141,7 @@ class GeneratorCall(UserDict): ...@@ -136,7 +141,7 @@ class GeneratorCall(UserDict):
return binary_decoder.data return binary_decoder.data
def _encodeData(self, data): def _encodeData(self, data):
""" Encode data to transmitable text. """ """ Encode data to transmittable text. """
fp = StringIO() fp = StringIO()
try: try:
# data might be ERP5Type.Message.Message instance. # data might be ERP5Type.Message.Message instance.
...@@ -159,7 +164,8 @@ def _generateErrorXML(error_message): ...@@ -159,7 +164,8 @@ def _generateErrorXML(error_message):
## server to local preferences id translation table ## server to local preferences id translation table
_server_to_preference_ids_map = {'client_id': 'preferred_express_client_uid', _server_to_preference_ids_map = {'client_id': 'preferred_express_client_uid',
'current_bc_index': 'preferred_express_erp5_uid', 'current_bc_index':
'preferred_express_erp5_uid',
'password': 'preferred_express_password', 'password': 'preferred_express_password',
'user_id': 'preferred_express_user_id',} 'user_id': 'preferred_express_user_id',}
...@@ -187,7 +193,8 @@ class WizardTool(BaseTool): ...@@ -187,7 +193,8 @@ class WizardTool(BaseTool):
global referer global referer
path[:-1] = [] path[:-1] = []
if referer is None: if referer is None:
referer = '%s/portal_wizard/proxy/%s/view' %(self.getPortalObject().absolute_url(), \ referer = '%s/portal_wizard/proxy/%s/view' % (
self.getPortalObject().absolute_url(),
'/'.join(subpath[:3])) '/'.join(subpath[:3]))
def _getProxyURL(self, subpath='', query=''): def _getProxyURL(self, subpath='', query=''):
...@@ -238,12 +245,14 @@ class WizardTool(BaseTool): ...@@ -238,12 +245,14 @@ class WizardTool(BaseTool):
def _getSubsribedUserAndPassword(self): def _getSubsribedUserAndPassword(self):
"""Retrieve the username and password for the subscription from """Retrieve the username and password for the subscription from
the system.""" the system."""
user = CachingMethod(self.getExpressConfigurationPreference, \ user = CachingMethod(self.getExpressConfigurationPreference,
'WizardTool_preferred_express_user_id', \ 'WizardTool_preferred_express_user_id',
cache_factory='erp5_content_long')('preferred_express_user_id', '') cache_factory='erp5_content_long')(
pw = CachingMethod(self.getExpressConfigurationPreference, \ 'preferred_express_user_id', '')
'WizardTool_preferred_express_password', \ pw = CachingMethod(self.getExpressConfigurationPreference,
cache_factory='erp5_content_long')('preferred_express_password', '') 'WizardTool_preferred_express_password',
cache_factory='erp5_content_long')(
'preferred_express_password', '')
return (user, pw) return (user, pw)
# This is a custom opener director for not handling redirections # This is a custom opener director for not handling redirections
...@@ -286,7 +295,8 @@ class WizardTool(BaseTool): ...@@ -286,7 +295,8 @@ class WizardTool(BaseTool):
content_type_value = None content_type_value = None
content_type_dict = None content_type_dict = None
if content_type: if content_type:
content_type_value, content_type_dict = cgi.parse_header(content_type) content_type_value, content_type_dict = cgi.parse_header(
content_type)
if content_type_value == 'multipart/form-data': if content_type_value == 'multipart/form-data':
fp = StringIO(user_input) fp = StringIO(user_input)
user_input_dict = cgi.parse_multipart(fp, content_type_dict) user_input_dict = cgi.parse_multipart(fp, content_type_dict)
...@@ -321,9 +331,11 @@ class WizardTool(BaseTool): ...@@ -321,9 +331,11 @@ class WizardTool(BaseTool):
cookiejar, cookiejar,
user_and_password[0], user_and_password[0],
user_and_password[1]) user_and_password[1])
# if server doesn't support cookie authentication try basic authentication # if server doesn't support cookie authentication try basic
# authentication
if not _isUserAcknowledged(cookiejar): if not _isUserAcknowledged(cookiejar):
auth = 'Basic %s' % base64.standard_b64encode('%s:%s' % user_and_password) auth = 'Basic %s' % base64.standard_b64encode('%s:%s' %
user_and_password)
header_dict['Authorization'] = auth header_dict['Authorization'] = auth
# save last credentials we passed to server # save last credentials we passed to server
last_loggedin_user_and_password = user_and_password last_loggedin_user_and_password = user_and_password
...@@ -334,10 +346,11 @@ class WizardTool(BaseTool): ...@@ -334,10 +346,11 @@ class WizardTool(BaseTool):
if not header_dict.has_key('Cookie'): if not header_dict.has_key('Cookie'):
header_dict['Cookie'] = '' header_dict['Cookie'] = ''
for cookie in cookiejar: for cookie in cookiejar:
# unconditionally send all cookies (no matter if expired or not) as URL is always the same # unconditionally send all cookies (no matter if expired or not) as URL
# is always the same
header_dict['Cookie'] += '%s=%s;' %(cookie.name, cookie.value) header_dict['Cookie'] += '%s=%s;' %(cookie.name, cookie.value)
# include cookies from local browser (like show/hide tabs) which are set directly # include cookies from local browser (like show/hide tabs) which are set
# by client JavaScript code (i.e. not sent from server) # directly by client JavaScript code (i.e. not sent from server)
for cookie_name, cookie_value in self.REQUEST.cookies.items(): for cookie_name, cookie_value in self.REQUEST.cookies.items():
header_dict['Cookie'] += '%s=%s;' %(cookie_name, cookie_value) header_dict['Cookie'] += '%s=%s;' %(cookie_name, cookie_value)
...@@ -355,12 +368,14 @@ class WizardTool(BaseTool): ...@@ -355,12 +368,14 @@ class WizardTool(BaseTool):
location = metadata.getheader('location') location = metadata.getheader('location')
if location is not None: if location is not None:
parsed_url = list(urlparse(location)) parsed_url = list(urlparse(location))
local_site_url_prefix = urllib.quote('%s/portal_wizard/proxy' \ local_site_url_prefix = urllib.quote(
%self.getPortalObject().absolute_url()) '%s/portal_wizard/proxy' % self.getPortalObject().absolute_url())
remote_url_parsed = urlparse(self.getServerUrl()) remote_url_parsed = urlparse(self.getServerUrl())
remote_site_url_prefix = '%s://%s/kb' %(remote_url_parsed[0], remote_url_parsed[1]) remote_site_url_prefix = '%s://%s/kb' %(remote_url_parsed[0],
remote_url_parsed[1])
# fix arguments for returned location URL # fix arguments for returned location URL
parsed_url[4] = parsed_url[4].replace(local_site_url_prefix, remote_site_url_prefix) parsed_url[4] = parsed_url[4].replace(local_site_url_prefix,
remote_site_url_prefix)
response['location'] = urlunparse(parsed_url) response['location'] = urlunparse(parsed_url)
response.setStatus(f.code, f.msg) response.setStatus(f.code, f.msg)
...@@ -383,30 +398,33 @@ class WizardTool(BaseTool): ...@@ -383,30 +398,33 @@ class WizardTool(BaseTool):
Return remote portal_witch tool interface. Return remote portal_witch tool interface.
""" """
handle = self.getPortalObject().portal_web_services.connect( handle = self.getPortalObject().portal_web_services.connect(
url = url, \ url = url,
user_name = user_name, \ user_name = user_name,
password = password, \ password = password,
transport = 'xml-rpc') transport = 'xml-rpc')
return handle.portal_witch return handle.portal_witch
def callRemoteProxyMethod(self, distant_method, server_url=None, \ def callRemoteProxyMethod(self, distant_method, server_url=None,
use_cache=1, ignore_exceptions=1, **kw): use_cache=1, ignore_exceptions=1, **kw):
""" Call proxy method on server. """ """ Call proxy method on server. """
configurator_user_preferred_language = self.getConfiguratorUserPreferredLanguage() configurator_user_preferred_language = self\
.getConfiguratorUserPreferredLanguage()
def wrapper(distant_method, **kw): def wrapper(distant_method, **kw):
return self._callRemoteMethod(distant_method, \ return self._callRemoteMethod(
use_proxy=1, \ distant_method,
use_proxy=1,
ignore_exceptions=ignore_exceptions, **kw)['data'] ignore_exceptions=ignore_exceptions, **kw)['data']
if use_cache: if use_cache:
wrapper = CachingMethod(wrapper, wrapper = CachingMethod(wrapper,
id = 'callRemoteProxyMethod_%s_%s' id = 'callRemoteProxyMethod_%s_%s'
%(distant_method, configurator_user_preferred_language), %(distant_method,
configurator_user_preferred_language),
cache_factory = 'erp5_ui_medium') cache_factory = 'erp5_ui_medium')
rc = wrapper(distant_method, **kw) rc = wrapper(distant_method, **kw)
return rc return rc
def _callRemoteMethod(self, distant_method, server_url=None, \ def _callRemoteMethod(self, distant_method, server_url=None, use_proxy=0,
use_proxy=0, ignore_exceptions=1, **kw): ignore_exceptions=1, **kw):
""" Call remote method on server and get result. """ """ Call remote method on server and get result. """
result_call = GeneratorCall() result_call = GeneratorCall()
user_name = None user_name = None
...@@ -437,7 +455,8 @@ class WizardTool(BaseTool): ...@@ -437,7 +455,8 @@ class WizardTool(BaseTool):
html = method(parameter_dict) html = method(parameter_dict)
except socket.error, message: except socket.error, message:
html = _generateErrorXML("""Cannot contact the server: %s. html = _generateErrorXML("""Cannot contact the server: %s.
Please check your network settings.""" %server_url) Please check your network settings.""" %
server_url)
zLOG.LOG('Wizard Tool socket error', zLOG.ERROR, message) zLOG.LOG('Wizard Tool socket error', zLOG.ERROR, message)
result_call.update({"command": "show", result_call.update({"command": "show",
"data": html, "data": html,
...@@ -445,7 +464,8 @@ class WizardTool(BaseTool): ...@@ -445,7 +464,8 @@ class WizardTool(BaseTool):
"previous": None}) "previous": None})
except xmlrpclib.ProtocolError, message: except xmlrpclib.ProtocolError, message:
html = _generateErrorXML("""The server %s refused to reply. html = _generateErrorXML("""The server %s refused to reply.
Please contact erp5-dev@erp5.org""" %server_url) Please contact erp5-dev@erp5.org""" %
server_url)
zLOG.LOG('Wizard Tool xmlrpc protocol error', zLOG.ERROR, message) zLOG.LOG('Wizard Tool xmlrpc protocol error', zLOG.ERROR, message)
result_call.update({"command": "show", result_call.update({"command": "show",
"data": html, "data": html,
...@@ -463,7 +483,7 @@ class WizardTool(BaseTool): ...@@ -463,7 +483,7 @@ class WizardTool(BaseTool):
command = result_call["command"] command = result_call["command"]
html = result_call["data"] html = result_call["data"]
if message is not None and not ignore_exceptions: if message is not None and not ignore_exceptions:
# raise last cought exception # raise last caught exception
raise raise
return result_call return result_call
...@@ -473,7 +493,8 @@ class WizardTool(BaseTool): ...@@ -473,7 +493,8 @@ class WizardTool(BaseTool):
for item, value in kw.items(): for item, value in kw.items():
if item in _server_to_preference_ids_map.keys(): if item in _server_to_preference_ids_map.keys():
## save persistently (as preference) ## save persistently (as preference)
self.setExpressConfigurationPreference(_server_to_preference_ids_map[item], self.setExpressConfigurationPreference(
_server_to_preference_ids_map[item],
value) value)
def getConfiguratorUserPreferredLanguage(self): def getConfiguratorUserPreferredLanguage(self):
...@@ -482,11 +503,14 @@ class WizardTool(BaseTool): ...@@ -482,11 +503,14 @@ class WizardTool(BaseTool):
configurator_user_preferred_language = None configurator_user_preferred_language = None
if REQUEST is not None: if REQUEST is not None:
# language value will be in cookie or REQUEST itself. # language value will be in cookie or REQUEST itself.
configurator_user_preferred_language = REQUEST.get(LANGUAGE_COOKIE_NAME, None) configurator_user_preferred_language = REQUEST.get(LANGUAGE_COOKIE_NAME,
None)
if configurator_user_preferred_language is None: if configurator_user_preferred_language is None:
# Find a preferred language from HTTP_ACCEPT_LANGUAGE # Find a preferred language from HTTP_ACCEPT_LANGUAGE
available_language_list = [i[1] for i in self.WizardTool_getConfigurationLanguageList()] available_language_list = [i[1] for i in self\
configurator_user_preferred_language = getAvailableLanguageFromHttpAcceptLanguage( .WizardTool_getConfigurationLanguageList()]
configurator_user_preferred_language = \
getAvailableLanguageFromHttpAcceptLanguage(
REQUEST.get('HTTP_ACCEPT_LANGUAGE', 'en'), REQUEST.get('HTTP_ACCEPT_LANGUAGE', 'en'),
available_language_list) available_language_list)
if configurator_user_preferred_language is None: if configurator_user_preferred_language is None:
...@@ -500,8 +524,9 @@ class WizardTool(BaseTool): ...@@ -500,8 +524,9 @@ class WizardTool(BaseTool):
parameter_dict[key] = self.getExpressConfigurationPreference(value, None) parameter_dict[key] = self.getExpressConfigurationPreference(value, None)
## add local ERP5 instance url ## add local ERP5 instance url
parameter_dict['erp5_url'] = self.getPortalObject().absolute_url() parameter_dict['erp5_url'] = self.getPortalObject().absolute_url()
# add user preffered language # add user preferred language
parameter_dict['user_preferred_language'] = self.getConfiguratorUserPreferredLanguage() parameter_dict['user_preferred_language'] = self.\
getConfiguratorUserPreferredLanguage()
# new way - reuse, if exist erp5_site_global_id # new way - reuse, if exist erp5_site_global_id
erp5_site_global_id = getattr(self.getPortalObject(), erp5_site_global_id = getattr(self.getPortalObject(),
...@@ -524,13 +549,16 @@ class WizardTool(BaseTool): ...@@ -524,13 +549,16 @@ class WizardTool(BaseTool):
def _importBT5FileData(self, bt5_filename, bt5_filedata): def _importBT5FileData(self, bt5_filename, bt5_filedata):
""" Import bt5 file content. """ """ Import bt5 file content. """
bt5_io = StringIO(bt5_filedata) bt5_io = StringIO(bt5_filedata)
portal_templates = getToolByName(self.getPortalObject(), 'portal_templates') portal_templates = getToolByName(self.getPortalObject(),
'portal_templates')
try: try:
business_template = portal_templates.importFile(import_file=bt5_io, batch_mode=1) business_template = portal_templates.importFile(import_file=bt5_io,
batch_mode=1)
except: except:
## importing of generated bt5 failed ## importing of generated bt5 failed
business_template = None business_template = None
LOG("Wizard", ERROR, "[FAIL] Import of Nexedi Configurator bt5 file(%s)" %bt5_filename) LOG("Wizard", ERROR, "[FAIL] Import of Nexedi Configurator bt5 file(%s)"
% bt5_filename)
raise raise
bt5_io.close() bt5_io.close()
#install bt5 #install bt5
...@@ -548,7 +576,8 @@ class WizardTool(BaseTool): ...@@ -548,7 +576,8 @@ class WizardTool(BaseTool):
global installation_status global installation_status
if use_super_manager: if use_super_manager:
# set current security manager to owner of site # set current security manager to owner of site
original_security_manager = _setSuperSecurityManager(self.getPortalObject()) original_security_manager = _setSuperSecurityManager(
self.getPortalObject())
portal = self.getPortalObject() portal = self.getPortalObject()
bt5_files = server_response.get("filedata", []) bt5_files = server_response.get("filedata", [])
...@@ -562,7 +591,8 @@ class WizardTool(BaseTool): ...@@ -562,7 +591,8 @@ class WizardTool(BaseTool):
LOG("Wizard", INFO, LOG("Wizard", INFO,
"Starting installation for %s" %' '.join(bt5_filenames)) "Starting installation for %s" %' '.join(bt5_filenames))
installation_status['bt5']['all'] = len(bt5_files) installation_status['bt5']['all'] = len(bt5_files)
#execute_after_setup_script = install_standard_bt5 = install_customer_bt5 = False # dev mode # execute_after_setup_script = install_standard_bt5 =
# install_customer_bt5 = False # dev mode
for bt5_id in bt5_filenames: for bt5_id in bt5_filenames:
if bt5_id.startswith('http://') or bt5_id.startswith('file://') : if bt5_id.startswith('http://') or bt5_id.startswith('file://') :
## direct download of bt5 files available ## direct download of bt5 files available
...@@ -583,8 +613,10 @@ class WizardTool(BaseTool): ...@@ -583,8 +613,10 @@ class WizardTool(BaseTool):
(bt5_id, len(bt5_filedata))) (bt5_id, len(bt5_filedata)))
## .. ## ..
counter += 1 counter += 1
## can we execute after setup script that will finish installation on client side? ## can we execute after setup script that will finish installation on
bt5_after_setup_script_id = server_response["server_buffer"].get("after_setup_script_id", None) ## client side?
bt5_after_setup_script_id = server_response["server_buffer"].get(
"after_setup_script_id", None)
if bt5_after_setup_script_id is None and \ if bt5_after_setup_script_id is None and \
self.getExpressConfigurationPreference( self.getExpressConfigurationPreference(
'preferred_express_configuration_status', False): 'preferred_express_configuration_status', False):
...@@ -593,13 +625,16 @@ class WizardTool(BaseTool): ...@@ -593,13 +625,16 @@ class WizardTool(BaseTool):
'preferred_express_after_setup_script_id', None) 'preferred_express_after_setup_script_id', None)
if execute_after_setup_script and bt5_after_setup_script_id is not None: if execute_after_setup_script and bt5_after_setup_script_id is not None:
## Execute script provided (if) in customer specific business template. ## Execute script provided (if) in customer specific business template.
bt5_customer_template_id = server_response["server_buffer"]['filenames'][-1] bt5_customer_template_id = server_response["server_buffer"]['filenames'
][-1]
bt5_customer_template_id = bt5_customer_template_id.replace('.bt5', '') bt5_customer_template_id = bt5_customer_template_id.replace('.bt5', '')
after_script = getattr(self, bt5_after_setup_script_id, None) after_script = getattr(self, bt5_after_setup_script_id, None)
if after_script is not None: if after_script is not None:
after_script_result = after_script(customer_template_id = bt5_customer_template_id) after_script_result = after_script(
LOG("Wizard", INFO,"[OK] execution of afer setup script %s (for bt5 %s)\n%s" customer_template_id = bt5_customer_template_id)
%(after_script.getId(), bt5_customer_template_id, after_script_result)) LOG("Wizard", INFO,"[OK] execution of after setup script %s (for bt5 "
"%s)%s" %(after_script.getId(), bt5_customer_template_id,
after_script_result))
## mark this ERP5 instance as configured ## mark this ERP5 instance as configured
self.setExpressConfigurationPreference( self.setExpressConfigurationPreference(
'preferred_express_configuration_status', 1) 'preferred_express_configuration_status', 1)
...@@ -620,7 +655,8 @@ class WizardTool(BaseTool): ...@@ -620,7 +655,8 @@ class WizardTool(BaseTool):
def remoteLogin(self, REQUEST): def remoteLogin(self, REQUEST):
""" Login client and show next form. """ """ Login client and show next form. """
client_id = None client_id = None
user_id = REQUEST.get('field_my_ac_name', None) or self.getExpressConfigurationPreference('preferred_express_user_id') user_id = REQUEST.get('field_my_ac_name', None) or self\
.getExpressConfigurationPreference('preferred_express_user_id')
REQUEST.form['field_my_ac_name'] = user_id REQUEST.form['field_my_ac_name'] = user_id
password = REQUEST.get('field_my_ac_password', '') password = REQUEST.get('field_my_ac_password', '')
came_from_method = REQUEST.get('field_my_came_from_method', '') came_from_method = REQUEST.get('field_my_came_from_method', '')
...@@ -637,10 +673,12 @@ class WizardTool(BaseTool): ...@@ -637,10 +673,12 @@ class WizardTool(BaseTool):
client_id=client_id) client_id=client_id)
return self.WizardTool_dialogForm(form_html=response["data"]) return self.WizardTool_dialogForm(form_html=response["data"])
elif command == "next": elif command == "next":
self._setServerInfo(user_id=user_id, \ self._setServerInfo(user_id=user_id,
#password=password, \ #password=password,
client_id=response['server_buffer'].get('client_id', None), \ client_id=response['server_buffer'].get('client_id',
current_bc_index=response['server_buffer'].get('current_bc_index', None)) None),
current_bc_index=response['server_buffer'].get(
'current_bc_index', None))
# set encoded __ac_express cookie at client's browser # set encoded __ac_express cookie at client's browser
__ac_express = quote(encodestring(password)) __ac_express = quote(encodestring(password))
expires = (DateTime() + 1).toZone('GMT').rfc822() expires = (DateTime() + 1).toZone('GMT').rfc822()
...@@ -651,18 +689,20 @@ class WizardTool(BaseTool): ...@@ -651,18 +689,20 @@ class WizardTool(BaseTool):
return self.next(REQUEST=REQUEST) return self.next(REQUEST=REQUEST)
elif command == "login": elif command == "login":
## invalid user/password ## invalid user/password
self.REQUEST.RESPONSE.redirect( \ self.REQUEST.RESPONSE.redirect(
'portal_wizard/%s?field_my_ac_name=%s&portal_status_message=%s' \ 'portal_wizard/%s?field_my_ac_name=%s&portal_status_message=%s'
%(came_from_method, user_id, response['server_buffer']['message'])) %(came_from_method, user_id, response['server_buffer']['message']))
return return
def login(self, REQUEST): def login(self, REQUEST):
""" Login client and show next form. """ """ Login client and show next form. """
user_id = self.getExpressConfigurationPreference('preferred_express_user_id') user_id = self.getExpressConfigurationPreference(
'preferred_express_user_id')
password = REQUEST.get('field_my_ac_password', '') password = REQUEST.get('field_my_ac_password', '')
if self._isCorrectConfigurationKey(user_id, password): if self._isCorrectConfigurationKey(user_id, password):
# set user preferred configuration language # set user preferred configuration language
user_preferred_language = REQUEST.get('field_my_user_preferred_language', None) user_preferred_language = REQUEST.get(
'field_my_user_preferred_language', None)
if user_preferred_language: if user_preferred_language:
# Set language value to request so that next page after login # Set language value to request so that next page after login
# can get the value. Because cookie value is available from # can get the value. Because cookie value is available from
...@@ -683,15 +723,17 @@ class WizardTool(BaseTool): ...@@ -683,15 +723,17 @@ class WizardTool(BaseTool):
else: else:
# incorrect user_id / password # incorrect user_id / password
REQUEST.set('portal_status_message', REQUEST.set('portal_status_message',
self.callRemoteProxyMethod('WizardTool_viewIncorrectConfigurationKeyMessageRenderer')) self.callRemoteProxyMethod('WizardTool_viewIncorrectConfigu'
'rationKeyMessageRenderer'))
return self.view() return self.view()
def _isCorrectConfigurationKey(self, user_id, password): def _isCorrectConfigurationKey(self, user_id, password):
""" Is configuration key correct """ """ Is configuration key correct """
uf = self.getPortalObject().acl_users uf = self.getPortalObject().acl_users
for plugin_name, plugin in uf._getOb('plugins').listPlugins(IAuthenticationPlugin): for plugin_name, plugin in uf._getOb('plugins').listPlugins(
if plugin.authenticateCredentials({'login':user_id, IAuthenticationPlugin):
'password': password}) is not None: if plugin.authenticateCredentials(
{'login':user_id, 'password': password}) is not None:
return 1 return 1
return 0 return 0
...@@ -699,7 +741,8 @@ class WizardTool(BaseTool): ...@@ -699,7 +741,8 @@ class WizardTool(BaseTool):
""" Can user access locally portal_wizard """ """ Can user access locally portal_wizard """
password = self.REQUEST.get('__ac_express', None) password = self.REQUEST.get('__ac_express', None)
if password is not None: if password is not None:
user_id = self.getExpressConfigurationPreference('preferred_express_user_id') user_id = self.getExpressConfigurationPreference(
'preferred_express_user_id')
password = decodestring(unquote(password)) password = decodestring(unquote(password))
return self._isCorrectConfigurationKey(user_id, password) return self._isCorrectConfigurationKey(user_id, password)
return 0 return 0
...@@ -709,7 +752,8 @@ class WizardTool(BaseTool): ...@@ -709,7 +752,8 @@ class WizardTool(BaseTool):
""" Validate settings and return a new form to the user. """ """ Validate settings and return a new form to the user. """
# check if user is allowed to access service # check if user is allowed to access service
if not self._isUserAllowedAccess(): if not self._isUserAllowedAccess():
REQUEST.set('portal_status_message', self.Base_translateString('Incorrect Configuration Key')) REQUEST.set('portal_status_message', self.Base_translateString(
'Incorrect Configuration Key'))
return self.view() return self.view()
response = self._callRemoteMethod("next") response = self._callRemoteMethod("next")
if isinstance(response['server_buffer'], dict): if isinstance(response['server_buffer'], dict):
...@@ -735,7 +779,8 @@ class WizardTool(BaseTool): ...@@ -735,7 +779,8 @@ class WizardTool(BaseTool):
""" Display the previous form. """ """ Display the previous form. """
# check if user is allowed to access service # check if user is allowed to access service
if not self._isUserAllowedAccess(): if not self._isUserAllowedAccess():
REQUEST.set('portal_status_message', self.Base_translateString('Incorrect Configuration Key')) REQUEST.set('portal_status_message', self.Base_translateString(
'Incorrect Configuration Key'))
return self.view() return self.view()
response = self._callRemoteMethod('previous') response = self._callRemoteMethod('previous')
command = response["command"] command = response["command"]
...@@ -757,22 +802,29 @@ class WizardTool(BaseTool): ...@@ -757,22 +802,29 @@ class WizardTool(BaseTool):
activities should not exists. activities should not exists.
""" """
global installation_status global installation_status
portal_activities = getToolByName(self.getPortalObject(), 'portal_activities') portal_activities = getToolByName(self.getPortalObject(),
is_bt5_installation_over = (portal_activities.countMessageWithTag('initialERP5Setup')==0) 'portal_activities')
if 0 == len(portal_activities.getMessageList()) and is_bt5_installation_over: is_bt5_installation_over = (portal_activities.countMessageWithTag(
'initialERP5Setup')==0)
if 0 == len(portal_activities.getMessageList()) and \
is_bt5_installation_over:
html = self.WizardTool_viewSuccessfulConfigurationMessageRenderer() html = self.WizardTool_viewSuccessfulConfigurationMessageRenderer()
else: else:
if is_bt5_installation_over: if is_bt5_installation_over:
# only if bt5s are installed start tracking number of activities # only if bt5s are installed start tracking number of activities
activity_list = portal_activities.getMessageList() activity_list = portal_activities.getMessageList()
installation_status['activity_list'].append(len(activity_list)) installation_status['activity_list'].append(len(activity_list))
html = self.WizardTool_viewRunningInstallationMessage(installation_status = installation_status) html = self.WizardTool_viewRunningInstallationMessage(
installation_status = installation_status)
# set encoding as this is usually called from asynchronous JavaScript call # set encoding as this is usually called from asynchronous JavaScript call
self.REQUEST.RESPONSE.setHeader('Content-Type', 'text/html; charset=utf-8'); self.REQUEST.RESPONSE.setHeader('Content-Type',
'text/html; charset=utf-8')
return html return html
security.declarePublic(Permissions.AccessContentsInformation, 'getInstallationStatusReportFromServer') security.declarePublic(Permissions.AccessContentsInformation,
def getInstallationStatusReportFromServer(self, active_process_id=None, REQUEST=None): 'getInstallationStatusReportFromServer')
def getInstallationStatusReportFromServer(self, active_process_id=None,
REQUEST=None):
""" Query remote server (usually only once for some installation status report """ """ Query remote server (usually only once for some installation status report """
response = self._callRemoteMethod("getInstallationStatusReport") response = self._callRemoteMethod("getInstallationStatusReport")
html = response["data"] html = response["data"]
...@@ -780,9 +832,9 @@ class WizardTool(BaseTool): ...@@ -780,9 +832,9 @@ class WizardTool(BaseTool):
security.declareProtected(Permissions.ModifyPortalContent, 'startInstallation') security.declareProtected(Permissions.ModifyPortalContent, 'startInstallation')
def startInstallation(self, REQUEST): def startInstallation(self, REQUEST):
""" Start installation process as an activity which will query generation server and """ Start installation process as an activity which will query generation
download/install bt5 template files and meanwhile offer user a nice GUI to observe server and download/install bt5 template files and meanwhile offer
what's happening. """ user a nice GUI to observe what's happening. """
global installation_status global installation_status
# init installation status # init installation status
installation_status['bt5']['all'] = 0 installation_status['bt5']['all'] = 0
...@@ -790,11 +842,14 @@ class WizardTool(BaseTool): ...@@ -790,11 +842,14 @@ class WizardTool(BaseTool):
installation_status['activity_list'] = [] installation_status['activity_list'] = []
active_process = self.portal_activities.newActiveProcess() active_process = self.portal_activities.newActiveProcess()
REQUEST.set('active_process_id', active_process.getId()) REQUEST.set('active_process_id', active_process.getId())
request_restore_dict = {'__ac_express': self.REQUEST.get('__ac_express', None),} request_restore_dict = {'__ac_express': self.REQUEST.get('__ac_express',
self.activate(active_process=active_process, tag = 'initialERP5Setup').initialERP5Setup(request_restore_dict) None),}
self.activate(active_process=active_process, tag = 'initialERP5Setup'
).initialERP5Setup(request_restore_dict)
return self.Wizard_viewInstallationStatus(REQUEST) return self.Wizard_viewInstallationStatus(REQUEST)
security.declareProtected(Permissions.ModifyPortalContent, 'initialERP5Setup') security.declareProtected(Permissions.ModifyPortalContent,
'initialERP5Setup')
def initialERP5Setup(self, request_restore_dict={}): def initialERP5Setup(self, request_restore_dict={}):
""" Get from remote generation server customized bt5 template files """ Get from remote generation server customized bt5 template files
and then install them. """ and then install them. """
...@@ -803,29 +858,36 @@ class WizardTool(BaseTool): ...@@ -803,29 +858,36 @@ class WizardTool(BaseTool):
for key, value in request_restore_dict.items(): for key, value in request_restore_dict.items():
self.REQUEST.set(key, value) self.REQUEST.set(key, value)
self.REQUEST.form['wizard_request_type'] = 'initial_setup' self.REQUEST.form['wizard_request_type'] = 'initial_setup'
# calculate server_url, because after bt5 installation reindexing is started # calculate server_url, because after bt5 installation reindexing is
# which will make it impossible to get preferences items # started which will make it impossible to get preferences items
server_url = self.getServerUrl() + self.getServerRoot() server_url = self.getServerUrl() + self.getServerRoot()
server_response = self._callRemoteMethod('getBT5FilesForBusinessConfiguration', server_url) server_response = self._callRemoteMethod(
## save erp5_uid which will make it possible to distingush different business conf for client 'getBT5FilesForBusinessConfiguration', server_url)
## save erp5_uid which will make it possible to distinguish different
## Business Configuration for client
if server_response.get('server_buffer', None) is not None: if server_response.get('server_buffer', None) is not None:
current_bc_index = server_response['server_buffer'].get('current_bc_index', None) current_bc_index = server_response['server_buffer'].get(
'current_bc_index', None)
if current_bc_index is not None: if current_bc_index is not None:
self._setServerInfo(current_bc_index = current_bc_index) self._setServerInfo(current_bc_index = current_bc_index)
self.installBT5FilesFromServer(server_response, True) self.installBT5FilesFromServer(server_response, True)
server_response = self._callRemoteMethod('finalizeInstallation', server_url) server_response = self._callRemoteMethod('finalizeInstallation',
server_url)
LOG("Wizard", INFO, LOG("Wizard", INFO,
"Successfuly installed generated business configuration from %s" %self.getServerUrl()) "Successfully installed generated business configuration from %s" %
self.getServerUrl())
security.declareProtected(Permissions.ModifyPortalContent, 'repair') security.declareProtected(Permissions.ModifyPortalContent, 'repair')
def repair(self): def repair(self):
""" Repair broken ERP5 instance. This will install all business templates """ Repair broken ERP5 instance. This will install all business templates
for ERP5 instance as specified in its business configuration. """ for ERP5 instance as specified in its business configuration. """
self.REQUEST.form['wizard_request_type'] = 'repair' self.REQUEST.form['wizard_request_type'] = 'repair'
server_response = self._callRemoteMethod('getBT5FilesForBusinessConfiguration') server_response = self._callRemoteMethod(
'getBT5FilesForBusinessConfiguration')
if server_response['command'] == "install": if server_response['command'] == "install":
active_process = self.portal_activities.newActiveProcess() active_process = self.portal_activities.newActiveProcess()
self.activate(active_process=active_process).installBT5FilesFromServer(server_response, True) self.activate(active_process=active_process).installBT5FilesFromServer(
server_response, True)
html = server_response['data'] html = server_response['data']
LOG("Wizard", INFO, LOG("Wizard", INFO,
"Start repair process for ERP5 instance from %s" %self.getServerUrl()) "Start repair process for ERP5 instance from %s" %self.getServerUrl())
...@@ -835,10 +897,12 @@ class WizardTool(BaseTool): ...@@ -835,10 +897,12 @@ class WizardTool(BaseTool):
def update(self): def update(self):
""" Update ERP5's instance standard business templates. """ """ Update ERP5's instance standard business templates. """
self.REQUEST.form['wizard_request_type'] = 'update' self.REQUEST.form['wizard_request_type'] = 'update'
server_response = self._callRemoteMethod('getBT5FilesForBusinessConfiguration') server_response = self._callRemoteMethod(
'getBT5FilesForBusinessConfiguration')
if server_response['command'] == "install": if server_response['command'] == "install":
active_process = self.portal_activities.newActiveProcess() active_process = self.portal_activities.newActiveProcess()
self.activate(active_process=active_process).installBT5FilesFromServer(server_response, self.activate(active_process=active_process).installBT5FilesFromServer(
server_response,
execute_after_setup_script = False) execute_after_setup_script = False)
html = server_response['data'] html = server_response['data']
LOG("Wizard", INFO, LOG("Wizard", INFO,
...@@ -847,17 +911,20 @@ class WizardTool(BaseTool): ...@@ -847,17 +911,20 @@ class WizardTool(BaseTool):
security.declareProtected(Permissions.View, 'getServerUrl') security.declareProtected(Permissions.View, 'getServerUrl')
def getServerUrl(self): def getServerUrl(self):
return CachingMethod(self.getExpressConfigurationPreference, \ return CachingMethod(self.getExpressConfigurationPreference,
'WizardTool_preferred_witch_tool_server_url', \ 'WizardTool_preferred_witch_tool_server_url',
cache_factory='erp5_content_long')('preferred_witch_tool_server_url', '') cache_factory='erp5_content_long')(
'preferred_witch_tool_server_url', '')
security.declareProtected(Permissions.View, 'getServerRoot') security.declareProtected(Permissions.View, 'getServerRoot')
def getServerRoot(self): def getServerRoot(self):
return CachingMethod(self.getExpressConfigurationPreference, \ return CachingMethod(self.getExpressConfigurationPreference,
'WizardTool_preferred_witch_tool_server_root', \ 'WizardTool_preferred_witch_tool_server_root',
cache_factory='erp5_content_long')('preferred_witch_tool_server_root', '') cache_factory='erp5_content_long')(
'preferred_witch_tool_server_root', '')
security.declareProtected(Permissions.View, 'getExpressConfigurationPreference') security.declareProtected(Permissions.View,
'getExpressConfigurationPreference')
def getExpressConfigurationPreference(self, preference_id, default = None): def getExpressConfigurationPreference(self, preference_id, default = None):
""" Get Express configuration preference """ """ Get Express configuration preference """
original_security_manager = _setSuperSecurityManager(self.getPortalObject()) original_security_manager = _setSuperSecurityManager(self.getPortalObject())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment