[FIX] google_drive: do not reset refresh_token

When setting the authorization code, a refresh token is generated in
the background and stored in a system parameter.

However, when saving the general settings (res.config.settings)
without changing the authorization code, the refresh token is deleted.

The refresh token should only be deleted if the authorization was
removed.

This was not the case as the set_param is always called and a value is
only computed when the authorization code has changed. The current
value was never retrieved.

Set a ir.config_parameter only when it a value has changed.

closes odoo/odoo#35028

Signed-off-by: Jérome Maes (jem) <jem@openerp.com>
This commit is contained in:
David Dufresne
2019-08-01 14:11:54 +00:00
committed by Martin Trigaux
parent e08f706b11
commit 921fab992d
@@ -21,7 +21,9 @@ class ResConfigSettings(models.TransientModel):
authorization_code_before = params.get_param('google_drive_authorization_code')
super(ResConfigSettings, self).set_values()
authorization_code = self.google_drive_authorization_code
refresh_token = False
if authorization_code and authorization_code != authorization_code_before:
refresh_token = self.env['google.service'].generate_refresh_token('drive', authorization_code)
params.set_param('google_drive_refresh_token', refresh_token)
if authorization_code != authorization_code_before:
refresh_token = (
self.env['google.service'].generate_refresh_token('drive', authorization_code)
if authorization_code else False
)
params.set_param('google_drive_refresh_token', refresh_token)