[IMP] core: don't save config when setting admin password

When setting the password in the database manager the config is saved
automatically in a odoorc file.

This can be problematic, especially when testing locally, with
specific options.
Going in the database manager and creating a new database or changing
admin pasword will save all those options.

This commit proposes to only save the admin_passwd when modified.

Part-of: odoo/odoo#82874
This commit is contained in:
Xavier-Do
2022-01-24 11:09:55 +00:00
committed by Raphael Collet
parent 63c4a9b951
commit 292645573b
2 changed files with 9 additions and 4 deletions
+1 -1
View File
@@ -347,7 +347,7 @@ def exp_rename(old_name, new_name):
@check_db_management_enabled
def exp_change_admin_password(new_password):
odoo.tools.config.set_admin_password(new_password)
odoo.tools.config.save()
odoo.tools.config.save(['admin_passwd'])
return True
@check_db_management_enabled
+8 -3
View File
@@ -633,11 +633,17 @@ class configmanager(object):
except ConfigParser.NoSectionError:
pass
def save(self):
def save(self, keys=None):
p = ConfigParser.RawConfigParser()
loglevelnames = dict(zip(self._LOGLEVELS.values(), self._LOGLEVELS))
p.add_section('options')
rc_exists = os.path.exists(self.rcfile)
if rc_exists and keys:
p.read([self.rcfile])
if not p.has_section('options'):
p.add_section('options')
for opt in sorted(self.options):
if keys is not None and opt not in keys:
continue
if opt in ('version', 'language', 'translate_out', 'translate_in', 'overwrite_existing_translations', 'init', 'update'):
continue
if opt in self.blacklist_for_save:
@@ -656,7 +662,6 @@ class configmanager(object):
# try to create the directories and write the file
try:
rc_exists = os.path.exists(self.rcfile)
if not rc_exists and not os.path.exists(os.path.dirname(self.rcfile)):
os.makedirs(os.path.dirname(self.rcfile))
try: