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 default_get(self, cr, uid, fields, context=None):
38 res = super(base_config_settings, self).default_get(cr, uid, fields, context=context)
39 res.update(self.get_oauth_providers(cr, uid, fields, context=context))
42 def get_oauth_providers(self, cr, uid, fields, context=None):
43 google_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_google')[1]
44 facebook_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_facebook')[1]
45 rg = self.pool.get('auth.oauth.provider').read(cr, uid, [google_id], ['enabled','client_id'], context=context)
46 rf = self.pool.get('auth.oauth.provider').read(cr, uid, [facebook_id], ['enabled','client_id'], context=context)
48 'auth_oauth_google_enabled': rg[0]['enabled'],
49 'auth_oauth_google_client_id': rg[0]['client_id'],
50 'auth_oauth_facebook_enabled': rf[0]['enabled'],
51 'auth_oauth_facebook_client_id': rf[0]['client_id'],
54 def set_oauth_providers(self, cr, uid, ids, context=None):
55 google_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_google')[1]
56 facebook_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'auth_oauth', 'provider_facebook')[1]
57 config = self.browse(cr, uid, ids[0], context=context)
59 'enabled':config.auth_oauth_google_enabled,
60 'client_id':config.auth_oauth_google_client_id,
63 'enabled':config.auth_oauth_facebook_enabled,
64 'client_id':config.auth_oauth_facebook_client_id,
66 self.pool.get('auth.oauth.provider').write(cr, uid, [google_id], rg)
67 self.pool.get('auth.oauth.provider').write(cr, uid, [facebook_id], rf)