From c196b55d618d99faab65a3369b337b526661ce64 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 31 Jan 2017 12:00:54 +0100 Subject: [PATCH] [FIX] website_slides: use Drive access token It is not possible to import Google Drive slides which are not publicly shared. Google Drive requires an access authorization from the user, not a simple API key. The access token is generated in module `google_drive`, but the latter is not in the dependencies of `website_slides`. opw-703750 --- addons/website_slides/models/slides.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/website_slides/models/slides.py b/addons/website_slides/models/slides.py index 58b5a670d6f..bfe69ad65b4 100644 --- a/addons/website_slides/models/slides.py +++ b/addons/website_slides/models/slides.py @@ -572,8 +572,21 @@ class Slide(models.Model): return 'document' else: return 'presentation' - key = self.env['ir.config_parameter'].sudo().get_param('website_slides.google_app_key') - fetch_res = self._fetch_data('https://www.googleapis.com/drive/v2/files/%s' % document_id, {'projection': 'BASIC', 'key': key}, "json") + + # Google drive doesn't use a simple API key to access the data, but requires an access + # token. However, this token is generated in module google_drive, which is not in the + # dependencies of website_slides. We still keep the 'key' parameter just in case, but that + # is probably useless. + params = {} + params['projection'] = 'BASIC' + if 'google.drive.config' in self.env: + access_token = self.env['google.drive.config'].get_access_token() + if access_token: + params['access_token'] = access_token + if not params.get('access_token'): + params['key'] = self.env['ir.config_parameter'].sudo().get_param('website_slides.google_app_key') + + fetch_res = self._fetch_data('https://www.googleapis.com/drive/v2/files/%s' % document_id, params, "json") if fetch_res.get('error'): return fetch_res