[FIX]google_drive: using res.users has_group method to know if the user is admin, instead of reading groups_id of the user (and, also, fixed the read call with a string instead of an array for the fields to read)

bzr revid: dle@openerp.com-20131127142049-v9sr5ldc9g4cct98
This commit is contained in:
Denis Ledoux 2013-11-27 15:20:49 +01:00
parent 0ecdb5dec7
commit 274b9c9503
1 changed files with 3 additions and 4 deletions

View File

@ -60,10 +60,9 @@ class config(osv.Model):
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")
user_is_admin = self.pool['res.users'].has_group(cr, uid, 'base.group_erp_manager')
if not google_drive_refresh_token:
if group_config in user['groups_id']:
if user_is_admin:
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."))
@ -81,7 +80,7 @@ class config(osv.Model):
req = urllib2.Request('https://accounts.google.com/o/oauth2/token', data, headers)
content = urllib2.urlopen(req).read()
except urllib2.HTTPError:
if group_config in user['groups_id']:
if user_is_admin:
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."))