commit
817ce06356
|
|
@ -0,0 +1,102 @@
|
||||||
|
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
|
||||||
|
:target: https://www.gnu.org/licenses/agpl
|
||||||
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
|
======================
|
||||||
|
Auth Oauth Environment
|
||||||
|
======================
|
||||||
|
|
||||||
|
This module extends the functionality of server environment to support OAuth
|
||||||
|
providers, and allows you to enable providers and set client_id key according
|
||||||
|
to environment. (Refer to module server_environment for more informations)
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
To install this module, you need to have the server_environment module
|
||||||
|
installed and properly configured.
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
To configure this module, you need to add a section
|
||||||
|
``[auth_oauth.provider_simple_name]`` to you server_environment_files
|
||||||
|
configurations, where 'provider_simple_name' match the simplified name field on
|
||||||
|
auth.oauth.provider.
|
||||||
|
|
||||||
|
'provider_simple_name' is the first part (until first space character) in
|
||||||
|
lower case of provider name. Using existing providers, it could be either
|
||||||
|
``google``, ``odoo.com``, or ``facebook``.
|
||||||
|
|
||||||
|
For example, if you want to activate Google and Odoo.com, your
|
||||||
|
server_environment_files should look like this ::
|
||||||
|
|
||||||
|
[auth_oauth.google]
|
||||||
|
enabled=True
|
||||||
|
client_id=123456789101-abcdefghijklmnopqrstuvwxyz000000
|
||||||
|
|
||||||
|
[auth_oauth.odoo.com]
|
||||||
|
enabled=True
|
||||||
|
|
||||||
|
|
||||||
|
Any provider not being enabled through server_environment_files will be set as
|
||||||
|
disabled automatically.
|
||||||
|
|
||||||
|
If you want to define a new custom provider, you should pay attention to the
|
||||||
|
name to use in the server_environment_files. If you create a provider with
|
||||||
|
'Dummy auth provider' as its name, then the section should be named
|
||||||
|
``[auth_oauth.dummy]``.
|
||||||
|
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
Once configured, Odoo will read from server_environment_files the following
|
||||||
|
fields of auth.oauth.provider :
|
||||||
|
|
||||||
|
* Allowed (``enabled``)
|
||||||
|
* Client ID (``client_id``)
|
||||||
|
|
||||||
|
|
||||||
|
Known issues / Roadmap
|
||||||
|
======================
|
||||||
|
|
||||||
|
* Due to the specific nature of this module, it cannot be tested on OCA runbot.
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `GitHub Issues
|
||||||
|
<https://github.com/OCA/server-env/issues>`_. In case of trouble, please
|
||||||
|
check there if your issue has already been reported. If you spotted it first,
|
||||||
|
help us smash it by providing detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Images
|
||||||
|
------
|
||||||
|
|
||||||
|
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Akim Juillerat <akim.juillerat@camptocamp.com>
|
||||||
|
|
||||||
|
Do not contact contributors directly about support or help with technical issues.
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/logo.png
|
||||||
|
:alt: Odoo Community Association
|
||||||
|
:target: https://odoo-community.org
|
||||||
|
|
||||||
|
This module is maintained by the OCA.
|
||||||
|
|
||||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
|
mission is to support the collaborative development of Odoo features and
|
||||||
|
promote its widespread use.
|
||||||
|
|
||||||
|
To contribute to this module, please visit https://odoo-community.org.
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
from . import models
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Copyright 2017 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
{
|
||||||
|
'name': 'Auth oauth configuration with server_environment',
|
||||||
|
'version': '11.0.1.0.0',
|
||||||
|
'category': 'Tools',
|
||||||
|
'summary': 'Configure mail servers with server_environment_files',
|
||||||
|
'author': "Camptocamp SA, Odoo Community Association (OCA)",
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'website': 'http://odoo-community.org',
|
||||||
|
'depends': [
|
||||||
|
'auth_oauth',
|
||||||
|
'server_environment',
|
||||||
|
],
|
||||||
|
'data': [
|
||||||
|
'views/auth_oauth_provider.xml'
|
||||||
|
],
|
||||||
|
'auto_install': False,
|
||||||
|
'installable': True,
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
from . import auth_oauth_provider
|
||||||
|
from . import res_config_settings
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
# Copyright 2017 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
import json
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
from odoo import fields, models, api, _
|
||||||
|
from odoo.addons.server_environment import serv_config
|
||||||
|
|
||||||
|
|
||||||
|
class AuthOAuthProvider(models.Model):
|
||||||
|
|
||||||
|
_inherit = 'auth.oauth.provider'
|
||||||
|
|
||||||
|
managed_by_env = fields.Boolean(compute='_compute_server_env')
|
||||||
|
provider_simple_name = fields.Char(compute='_compute_simple_name')
|
||||||
|
client_id = fields.Char(string='Client ID', compute='_compute_server_env')
|
||||||
|
enabled = fields.Boolean(string='Allowed', compute='_compute_server_env',
|
||||||
|
search='_search_enabled')
|
||||||
|
|
||||||
|
def _compute_server_env(self):
|
||||||
|
for provider in self:
|
||||||
|
provider_section_name = provider._get_provider_section_name()
|
||||||
|
vals = {}
|
||||||
|
|
||||||
|
if serv_config.has_section(provider_section_name):
|
||||||
|
|
||||||
|
vals.update({'managed_by_env': True})
|
||||||
|
vals.update(serv_config.items(provider_section_name))
|
||||||
|
else:
|
||||||
|
vals.update({'managed_by_env': False, 'enabled': False})
|
||||||
|
provider.update(vals)
|
||||||
|
|
||||||
|
def _search_enabled(self, operator, value):
|
||||||
|
enabled_provider_ids = []
|
||||||
|
for provider in self.search([]):
|
||||||
|
provider_section_name = provider._get_provider_section_name()
|
||||||
|
if serv_config.has_option(provider_section_name, 'enabled') \
|
||||||
|
and serv_config.get(provider_section_name, 'enabled'):
|
||||||
|
enabled_provider_ids.append(provider.id)
|
||||||
|
return [('id', 'in', enabled_provider_ids)]
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def _compute_simple_name(self):
|
||||||
|
for provider in self:
|
||||||
|
provider.provider_simple_name = provider.name.split(' ')[0].lower()
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def _get_provider_section_name(self):
|
||||||
|
self.ensure_one()
|
||||||
|
return '.'.join(['auth_oauth', self.provider_simple_name])
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
|
||||||
|
submenu=False):
|
||||||
|
res = super(AuthOAuthProvider, self).fields_view_get(
|
||||||
|
view_id=view_id, view_type=view_type, toolbar=toolbar,
|
||||||
|
submenu=submenu)
|
||||||
|
readonly_fields = ['enabled', 'client_id']
|
||||||
|
doc = etree.XML(res['arch'])
|
||||||
|
for ro_field in readonly_fields:
|
||||||
|
for node in doc.xpath("//field[@name='%s']" % ro_field):
|
||||||
|
node.set('readonly', '1')
|
||||||
|
modifiers = json.loads(node.get("modifiers"))
|
||||||
|
modifiers['readonly'] = True
|
||||||
|
node.set("modifiers", json.dumps(modifiers))
|
||||||
|
|
||||||
|
node.set('help', _('This field is managed through server '
|
||||||
|
'environment'))
|
||||||
|
res['arch'] = etree.tostring(doc, encoding='unicode')
|
||||||
|
return res
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
# Copyright 2017 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
import json
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
|
from odoo import models, api, _
|
||||||
|
|
||||||
|
|
||||||
|
class ResConfigSettings(models.TransientModel):
|
||||||
|
|
||||||
|
_inherit = 'res.config.settings'
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
|
||||||
|
submenu=False):
|
||||||
|
res = super(ResConfigSettings, self).fields_view_get(
|
||||||
|
view_id=view_id, view_type=view_type, toolbar=toolbar,
|
||||||
|
submenu=submenu)
|
||||||
|
|
||||||
|
google_provider = self.env.ref('auth_oauth.provider_google',
|
||||||
|
raise_if_not_found=False)
|
||||||
|
|
||||||
|
if google_provider and google_provider.managed_by_env:
|
||||||
|
readonly_fields = ['module_auth_oauth',
|
||||||
|
'auth_oauth_google_enabled',
|
||||||
|
'auth_oauth_google_client_id']
|
||||||
|
doc = etree.XML(res['arch'])
|
||||||
|
for ro_field in readonly_fields:
|
||||||
|
for node in doc.xpath("//field[@name='%s']" % ro_field):
|
||||||
|
node.set('readonly', '1')
|
||||||
|
modifiers = json.loads(node.get("modifiers"))
|
||||||
|
modifiers['readonly'] = True
|
||||||
|
node.set("modifiers", json.dumps(modifiers))
|
||||||
|
|
||||||
|
node.set('help', _('This field is managed through server '
|
||||||
|
'environment'))
|
||||||
|
res['arch'] = etree.tostring(doc, encoding='unicode')
|
||||||
|
return res
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_oauth_provider_form" model="ir.ui.view">
|
||||||
|
<field name="name">auth.oauth.provider.form.inherit</field>
|
||||||
|
<field name="model">auth.oauth.provider</field>
|
||||||
|
<field name="inherit_id" ref="auth_oauth.view_oauth_provider_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="name" position="before">
|
||||||
|
<field name="managed_by_env" invisible="1" />
|
||||||
|
</field>
|
||||||
|
<field name="name" position="attributes">
|
||||||
|
<attribute name="attrs">{'readonly': [('managed_by_env', '=', True)]}</attribute>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Loading…
Reference in New Issue