[FIX] google_drive: Generate Google Authorization Code URL

When checking `Attach Google documents to any record`
in the general settings, if you are not redirected
to a module, but, instead, the current page is refreshed
(the wizard is reloaded instead of creating a new
configuration wizard),
the default value for `google_drive_uri` was not correctly
loaded, the `client_id` in the URL
remained `False` because the wizard was not being
re-created, but reloaded,
and therefore `default_get` hasn't been re-called,
and the `client_id` changed
(it was added to the system parameters after
the installation of the module)

Therefore, the link did not include the correct
`client_id`, and it leaded to the inabibility
to use the URL:
401. That’s an error.
The OAuth client was not found.

Replacing the simple char fields by a function
field, with the correct store trigger,
force the URL value to be reloaded
when the system parameter is inserted.

opw-673274
This commit is contained in:
Denis Ledoux 2016-03-30 16:01:48 +02:00
parent 1d5db33638
commit 6e07ae5a5c
1 changed files with 17 additions and 1 deletions

View File

@ -241,9 +241,25 @@ class config(osv.Model):
class base_config_settings(osv.TransientModel):
_inherit = "base.config.settings"
def _get_drive_uri(self, cr, uid, ids, field_name, arg, context=None):
return {
wizard_id: self.default_get(cr, uid, ['google_drive_uri']).get('google_drive_uri')
for wizard_id in ids
}
def _get_wizard_ids(self, cr, uid, ids, context=None):
result = []
if any(rec.key in ['google_drive_client_id', 'google_redirect_uri'] for rec in self.browse(cr, uid, ids, context=context)):
result.extend(self.pool['base.config.settings'].search(cr, uid, [], context=context))
return result
_columns = {
'google_drive_authorization_code': fields.char('Authorization Code'),
'google_drive_uri': fields.char('URI', readonly=True, help="The URL to generate the authorization code from Google"),
'google_drive_uri': fields.function(_get_drive_uri, string='URI', help="The URL to generate the authorization code from Google", type="char", store={
'ir.config_parameter': (_get_wizard_ids, None, 20),
}), # TODO: 1. in master, remove the store, there is no reason for this field to be stored. It's just a dynamic link.
# TODO: 2. when converted to the new API, the code to get the default value can be moved to the compute method directly, and the default value can be removed
# the only reason the default value is defined is because function fields are not computed in draft mode in the old API.
}
_defaults = {
'google_drive_uri': lambda s, cr, uid, c: s.pool['google.service']._get_google_token_uri(cr, uid, 'drive', scope=s.pool['google.drive.config'].get_google_scope(), context=c),