Merge lp:~fabien-morin/unifield-server/fm-us-2695 into lp:unifield-server

Proposed by jftempo
Status: Rejected
Rejected by: jftempo
Proposed branch: lp:~fabien-morin/unifield-server/fm-us-2695
Merge into: lp:unifield-server
Diff against target: 201 lines (+100/-6)
7 files modified
bin/addons/base/i18n/fr.po (+7/-0)
bin/addons/msf_profile/i18n/fr_MF.po (+7/-0)
bin/addons/msf_sync_data_server/__openerp__.py (+2/-0)
bin/addons/msf_sync_data_server/security/group.xml (+9/-0)
bin/addons/sync_client/sync_client.py (+61/-5)
bin/osv/orm.py (+6/-1)
doc/openerp-server.conf (+8/-0)
To merge this branch: bzr merge lp:~fabien-morin/unifield-server/fm-us-2695
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+322338@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jeff Allen (jr.allen) wrote :

Sorry, lots of comments.

Revision history for this message
Jeff Allen (jr.allen) :
Revision history for this message
Jeff Allen (jr.allen) :
Revision history for this message
Fabien MORIN (fabien-morin) wrote :
Download full text (9.8 KiB)

On Tuesday 11 April 2017 14:31:06 you wrote:
> Sorry, lots of comments.
>
> Diff comments:
> > === modified file 'bin/updater.py'
> > --- bin/updater.py 2017-01-17 13:07:11 +0000
> > +++ bin/updater.py 2017-04-11 07:12:45 +0000
> > @@ -445,42 +445,91 @@
> >
> > def reconnect_sync_server():
> > """Reconnect the connection manager to the SYNC_SERVER if password
> > file
> > exists
> >
> > + If password file is not found but sync_user_login and
> > sync_user_password are + found in the config file, set them into the
> > connection manager, this way + there is no need to enter them
> > manually.
> >
> > """
> > import tools
> >
> > + import pooler
> >
> > credential_filepath = os.path.join(tools.config['root_path'],
> > 'unifield-socket.py')>
> > - if os.path.isfile(credential_filepath):
> > - import base64
> > - import pooler
> > - f = open(credential_filepath, 'r')
> > - lines = f.readlines()
> > - f.close()
> > - if lines:
> > - try:
> > + sync_user_login = tools.config.get('sync_user_login')
>
> if sync_user_login == 'admin': throw an error. We only want them to be using
> this feature with the per-instance user/pass.

Throwing an error is may be a bit violent. May be it is better to ignore it an
log an error message than preventing the instance from starting ?

> > + sync_user_password = tools.config.get('sync_user_password')
> > + dbname_list = []
> > + password_from_file = None
> > + cr = None
> > +
> > + try:
> > + if os.path.isfile(credential_filepath):
> > + import base64
> > + with open(credential_filepath, 'r') as f:
> > + lines = f.readlines()
> >
> > + if lines:
> > dbname = base64.decodestring(lines[0])
> >
> > - password = base64.decodestring(lines[1])
> > - logger.info('dbname = %s' % dbname)
> > - db, pool = pooler.get_db_and_pool(dbname)
> > - db, pool = pooler.restart_pool(dbname) # do not remove
> > this line, it is required to restart pool not to have - #
> > strange behaviour with the connection on web interface -
> > - # do not execute this code on server side
> > - if not pool.get("sync.server.entity"):
> > - cr = db.cursor()
> > - # delete the credential file
> > - os.remove(credential_filepath)
> > - # reconnect to SYNC_SERVER
> > - connection_module =
> > pool.get("sync.client.sync_server_connection") -
> > connection_module.connect(cr, 1, password=password) -
> > - # in caes of automatic patching, relaunch the sync
> > - # (as the sync that launch the silent upgrade was
> > aborted to do the upgrade first) - if
> > connection_module.is_automatic_patching_allowed(cr, 1): -
> > pool.get('sync.client.entity').sync_withbackup(cr, 1) -
> > cr.close()
> > - except Exception as e:
> > - ...

Read more...

4286. By Fabien MORIN

US-2695 [IMP] make possible for connect() to accept a login in addition to
password.
[IMP] close connection on each pass of the for loop to avoid connection leak
[FIX] misspelling
[IMP] delete the credentials file used for automatic patching only when
operations are done (finally).
[IMP] comments

4287. By Fabien MORIN

US-2695 [IMP] revert changes to bin/updater.py after ticket description changes

4288. By Fabien MORIN

US-2695 [IMP] change the way it works after ticket desciption change:
Now it's a synchronization time that the config file is read to try to connect
with this credentials.

4289. By Fabien MORIN

US-2695 [IMP] update the comment accordingly

4290. By Fabien MORIN

US-2695 [ADD] translation
[IMP] comments and variable names more clear

4291. By Fabien MORIN

US-2695 [MERGE] with latest trunk

Revision history for this message
jftempo (jfb-tempo-consulting) :
4292. By Fabien MORIN

US-2695 [IMP] the group Instance Sync is only for sync_server, move it into
msf_sync_data_server module
[IMP] do not duplicate AdminLoginException error message, make it part of the
exception to have it only one time.

4293. By Fabien MORIN

US-2835 [IMP] add a more verbose message in case the object_id is not found

4294. By Fabien MORIN

US-2835 [FIX] no need to do any checks on orm_memory as we are already in the
orm_memory class

4295. By Fabien MORIN

US-2695 [ADD] translation for error message

Unmerged revisions

4295. By Fabien MORIN

US-2695 [ADD] translation for error message

4294. By Fabien MORIN

US-2835 [FIX] no need to do any checks on orm_memory as we are already in the
orm_memory class

4293. By Fabien MORIN

US-2835 [IMP] add a more verbose message in case the object_id is not found

4292. By Fabien MORIN

US-2695 [IMP] the group Instance Sync is only for sync_server, move it into
msf_sync_data_server module
[IMP] do not duplicate AdminLoginException error message, make it part of the
exception to have it only one time.

4291. By Fabien MORIN

US-2695 [MERGE] with latest trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/base/i18n/fr.po'
2--- bin/addons/base/i18n/fr.po 2016-12-15 16:14:13 +0000
3+++ bin/addons/base/i18n/fr.po 2017-04-26 15:01:47 +0000
4@@ -9695,3 +9695,10 @@
5 #: selection:base.language.install,lang:0
6 msgid "Russian / русский язык"
7 msgstr "Russie / русский язык"
8+
9+#. module: base
10+#: code:addons/orm.py:2348
11+#, python-format
12+msgid "Object id \'%s\' not found in \'%s\'. You may try to access a deleted temporary object (ie. wizard)"
13+msgstr "L'object d'id \'%s\' n'a pas été trouvé pour \'%s\'. Vous essayez probablement d'accéder à un objet temporaire qui n'existe plus (ex. un assistant)"
14+
15
16=== modified file 'bin/addons/msf_profile/i18n/fr_MF.po'
17--- bin/addons/msf_profile/i18n/fr_MF.po 2017-04-19 14:11:12 +0000
18+++ bin/addons/msf_profile/i18n/fr_MF.po 2017-04-26 15:01:47 +0000
19@@ -98226,6 +98226,13 @@
20 msgstr "L'article doit être uniquement utilisé dans un programme correctement construit, à besoin d'une description plus détaillée."
21
22 #. module: sync_client
23+#: code:addons/sync_client/sync_client.py:92
24+#: code:addons/sync_client/sync_client.py:249
25+#, python-format
26+msgid "Not connected to server. You cannot use 'admin' in the config file for automatic connection, please use a user dedicated to the synchronization or manually connect before launching a sync."
27+msgstr "Non connecté au serveur. Vous ne pouvez pas utiliser 'admin' dans le fichier de configuration pour une connexion automatique, veuillez utiliser un utilisateur dédié à la synchronisation ou vous connecter manuellement avant de lancer une synchronisation."
28+
29+#. module: sync_client
30 #: view:sync.client.update_received:0
31 msgid "Updates Received"
32 msgstr "Mises à jour Reçues"
33
34=== modified file 'bin/addons/msf_sync_data_server/__openerp__.py'
35--- bin/addons/msf_sync_data_server/__openerp__.py 2016-05-26 08:28:49 +0000
36+++ bin/addons/msf_sync_data_server/__openerp__.py 2017-04-26 15:01:47 +0000
37@@ -33,6 +33,8 @@
38 'data/sync.server.group_type.csv',
39 'data/sync_server.sync_rule.csv',
40 'data/sync_server.message_rule.csv',
41+ 'security/group.xml',
42+ 'security/ir.model.access.csv',
43 ],
44 'demo_xml': [
45 ],
46
47=== added directory 'bin/addons/msf_sync_data_server/security'
48=== added file 'bin/addons/msf_sync_data_server/security/group.xml'
49--- bin/addons/msf_sync_data_server/security/group.xml 1970-01-01 00:00:00 +0000
50+++ bin/addons/msf_sync_data_server/security/group.xml 2017-04-26 15:01:47 +0000
51@@ -0,0 +1,9 @@
52+<?xml version="1.0" encoding="utf-8"?>
53+<openerp>
54+ <data>
55+ <record id="instance_sync_user" model="res.groups">
56+ <field name="name">Instance Sync</field>
57+ </record>
58+ </data>
59+</openerp>
60+
61
62=== modified file 'bin/addons/sync_client/sync_client.py'
63--- bin/addons/sync_client/sync_client.py 2017-02-28 13:41:45 +0000
64+++ bin/addons/sync_client/sync_client.py 2017-04-26 15:01:47 +0000
65@@ -62,6 +62,18 @@
66 pass
67
68
69+class AdminLoginException(Exception):
70+ def __init__(self):
71+ self.value = "Not connected to server. "\
72+ "You cannot use 'admin' in the config file for "\
73+ "automatic connection, please use a user dedicated "\
74+ "to the synchronization or manually connect before "\
75+ "launching a sync."
76+
77+ def __str__(self):
78+ return repr(self.value)
79+
80+
81 class BackgroundProcess(Thread):
82
83 def __init__(self, cr, uid, method, context=None):
84@@ -80,6 +92,13 @@
85 # Check if we are not already syncing
86 entity.is_syncing(raise_on_syncing=True)
87 # Check if connection is up
88+ connection_obj = pool.get('sync.client.sync_server_connection')
89+ try:
90+ connection_obj.get_connection_from_config_file(cr, uid, context=context)
91+ except AdminLoginException as e:
92+ connected = False
93+ raise osv.except_osv(_("Error!"),
94+ _(e.value))
95 if not pool.get('sync.client.sync_server_connection').is_connected:
96 connected = False
97 raise osv.except_osv(_("Error!"), _("Not connected: please try to log on in the Connection Manager"))
98@@ -222,11 +241,18 @@
99
100 if need_connection:
101 # Check if connection is up
102- if not self.pool.get('sync.client.sync_server_connection').is_connected:
103+ connection_obj = self.pool.get('sync.client.sync_server_connection')
104+ if not connection_obj.is_connected:
105 if fn.__name__ == 'sync_manual_withbackup':
106 self.pool.get('backup.config').exp_dump_for_state(cr, uid, 'beforemanualsync', context=context)
107-
108- raise osv.except_osv(_("Error!"), _("Not connected: please try to log on in the Connection Manager"))
109+ # try to coonect from the file
110+ try:
111+ if not connection_obj.get_connection_from_config_file(cr,
112+ uid, context=context):
113+ raise osv.except_osv(_("Error!"), _("Not connected: please try to log on in the Connection Manager"))
114+ except AdminLoginException as e:
115+ raise osv.except_osv(_("Error!"),
116+ _(e.value))
117 # Check for update (if connection is up)
118 if hasattr(self, 'upgrade'):
119 # TODO: replace the return value of upgrade to a status and raise an error on required update
120@@ -1346,7 +1372,35 @@
121 raise osv.except_osv('Connection Error','Unknown protocol: %s' % con.protocol)
122 return connector
123
124- def connect(self, cr, uid, ids=None, password=None, context=None):
125+ def get_connection_from_config_file(self, cr, uid, ids=None, context=None):
126+ '''
127+ get credentials from config file if any and try to connect to the sync
128+ server with them. Return True if it has been connected using this
129+ credentials, False otherwise
130+ '''
131+ logger = logging.getLogger('sync.client')
132+ if not self.is_connected:
133+ login = tools.config.get('sync_user_login')
134+ if login == 'admin':
135+ raise AdminLoginException
136+ password = tools.config.get('sync_user_password')
137+ if login and password:
138+ # write this credentials in the connection manager to be
139+ # consistent with the credentials used for the current
140+ # connection and what is in the connection manager
141+ connection_ids = self.search(cr, 1, [])
142+ if connection_ids:
143+ logger.info('Automatic set up of sync connection credentials')
144+ data_to_write = {
145+ 'login': login,
146+ 'password': password,
147+ }
148+ self.write(cr, 1, connection_ids, data_to_write)
149+ cr.commit()
150+ return self.connect(cr, 1, password=password, login=login)
151+ return False
152+
153+ def connect(self, cr, uid, ids=None, password=None, login=None, context=None):
154 """
155 connect the instance to the SYNC_SERVER instance for synchronization
156 """
157@@ -1366,7 +1420,9 @@
158 con.password = password
159 else:
160 self._password = con.login
161- cnx = rpc.Connection(connector, con.database, con.login, self._password)
162+ if login is None:
163+ login=con.login
164+ cnx = rpc.Connection(connector, con.database, login, self._password)
165 con._cache = {}
166 if cnx.user_id:
167 self._uid = cnx.user_id
168
169=== modified file 'bin/osv/orm.py'
170--- bin/osv/orm.py 2017-04-20 09:59:19 +0000
171+++ bin/osv/orm.py 2017-04-26 15:01:47 +0000
172@@ -2342,7 +2342,12 @@
173 upd_todo.append(field)
174 for object_id in ids:
175 self._check_access(user, object_id, mode='write')
176- self.datas[object_id].update(vals2)
177+ try:
178+ self.datas[object_id].update(vals2)
179+ except KeyError:
180+ error_message = _('Object id \'%s\' not found in \'%s\'. You may try to access a deleted temporary object (ie. wizard)')
181+ error_message = error_message % (object_id, self._name)
182+ raise except_orm(_('Error'), error_message)
183 self.datas[object_id]['internal.date_access'] = time.time()
184 for field in upd_todo:
185 self._columns[field].set_memory(cr, self, object_id, field, vals[field], user, context)
186
187=== modified file 'doc/openerp-server.conf'
188--- doc/openerp-server.conf 2017-03-01 14:42:57 +0000
189+++ doc/openerp-server.conf 2017-04-26 15:01:47 +0000
190@@ -50,3 +50,11 @@
191 # for Weeks (0=Monday). See
192 # https://docs.python.org/2/library/logging.handlers.html#timedrotatingfilehandler
193 log_user_xmlrpc_when = D
194+
195+# Credentials to connect to the sync server. At synchronization time,
196+# If both are not False, the server will automatically try to connect
197+# with this credential and enter synchronization state "Connected"
198+# ONLY FOR USE WITH per-instance sync username/password ('admin' login is
199+# forbidden)
200+sync_user_login = False
201+sync_user_password = False

Subscribers

People subscribed via source and target branches