1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2012-Today OpenERP SA (<http://www.openerp.com>)
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>
20 ##############################################################################
22 from openerp.osv import osv, fields
25 _logger = logging.getLogger(__name__)
27 class base_config_settings(osv.TransientModel):
28 _inherit = 'base.config.settings'
31 'auth_oauth_google_enabled' : fields.boolean('Allow users to sign in with Google'),
32 'auth_oauth_google_client_id' : fields.char('Client ID'),
33 'auth_oauth_facebook_enabled' : fields.boolean('Allow users to sign in with Facebook'),
34 'auth_oauth_facebook_client_id' : fields.char('Client ID'),
37 def get_oauth_providers(self, cr, uid, fields, context=None):
38 google_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_google')[1]
39 facebook_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_facebook')[1]
40 rg = self.pool.get('auth.oauth.provider').read(cr, uid, [google_id], ['enabled','client_id'], context=context)
41 rf = self.pool.get('auth.oauth.provider').read(cr, uid, [facebook_id], ['enabled','client_id'], context=context)
43 'auth_oauth_google_enabled': rg[0]['enabled'],
44 'auth_oauth_google_client_id': rg[0]['client_id'],
45 'auth_oauth_facebook_enabled': rf[0]['enabled'],
46 'auth_oauth_facebook_client_id': rf[0]['client_id'],
49 def set_oauth_providers(self, cr, uid, ids, context=None):
50 google_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_google')[1]
51 facebook_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_facebook')[1]
52 config = self.browse(cr, uid, ids[0], context=context)
54 'enabled':config.auth_oauth_google_enabled,
55 'client_id':config.auth_oauth_google_client_id,
58 'enabled':config.auth_oauth_facebook_enabled,
59 'client_id':config.auth_oauth_facebook_client_id,
61 self.pool.get('auth.oauth.provider').write(cr, uid, [google_id], rg)
62 self.pool.get('auth.oauth.provider').write(cr, uid, [facebook_id], rf)