Skip to content

Commit

Permalink
[FIX]google_drive, google_spreadsheet: go to configuration panel only…
Browse files Browse the repository at this point in the history
… for group settings, spreadsheet attached to model without res_id

bzr revid: [email protected]
  • Loading branch information
beledouxdenis committed Jul 24, 2013
1 parent d5539ec commit 54de409
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions addons/google_drive/google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ def get_google_drive_url(self, cr, uid, config_id, res_id, template_id, context=
def get_access_token(self, cr, uid, scope=None, context=None):
ir_config = self.pool['ir.config_parameter']
google_drive_refresh_token = ir_config.get_param(cr, SUPERUSER_ID, 'google_drive_refresh_token')
group_config = self.pool['ir.model.data'].get_object_reference(cr, uid, 'base', 'group_erp_manager')[1]
user = self.pool['res.users'].read(cr, uid, uid, "groups_id")
if not google_drive_refresh_token:
raise self.pool.get('res.config.settings').get_config_warning(cr, _("You haven't configured 'Authorization Code' generated from google, Please generate and configure it in %(menu:base_setup.menu_general_configuration)s."), context=context)
if group_config in user['groups_id']:
raise self.pool.get('res.config.settings').get_config_warning(cr, _("You haven't configured 'Authorization Code' generated from google, Please generate and configure it in %(menu:base_setup.menu_general_configuration)s."), context=context)
else:
raise osv.except_osv(_('Error!'), _("Google Drive is not yet configured. Please contact your administrator."))
google_drive_client_id = ir_config.get_param(cr, SUPERUSER_ID, 'google_drive_client_id')
google_drive_client_secret = ir_config.get_param(cr, SUPERUSER_ID, 'google_drive_client_secret')
#For Getting New Access Token With help of old Refresh Token
Expand All @@ -75,10 +80,11 @@ def get_access_token(self, cr, uid, scope=None, context=None):
try:
req = urllib2.Request('https://accounts.google.com/o/oauth2/token', data, headers)
content = urllib2.urlopen(req).read()
except urllib2.HTTPError as e:
print vars(e)
print e.read()
raise self.pool.get('res.config.settings').get_config_warning(cr, _("Something went wrong during the token generation. Please request again an authorization code in %(menu:base_setup.menu_general_configuration)s."), context=context)
except urllib2.HTTPError:
if group_config in user['groups_id']:
raise self.pool.get('res.config.settings').get_config_warning(cr, _("Something went wrong during the token generation. Please request again an authorization code in %(menu:base_setup.menu_general_configuration)s."), context=context)
else:
raise osv.except_osv(_('Error!'), _("Google Drive is not yet configured. Please contact your administrator."))
content = json.loads(content)
return content.get('access_token')

Expand Down
2 changes: 1 addition & 1 deletion addons/google_spreadsheet/google_spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def set_spreadsheet(self, cr, uid, model, domain, groupbys, view_id, context=Non
raise
config = self.browse(cr, uid, config_id, context=context)
title = 'Spreadsheet %s' % model
res = self.copy_doc(cr, uid, config.id, config.google_drive_resource_id, title, 'google.drive.config', context=context)
res = self.copy_doc(cr, uid, False, config.google_drive_resource_id, title, model, context=context)

mo = re.search("(key=|/d/)([A-Za-z0-9-_]+)", res['url'])
if mo:
Expand Down

0 comments on commit 54de409

Please sign in to comment.