Skip to content

Commit dd7e861

Browse files
committed
[MIG] auth_oauth_environment: Migration to 17.0
1 parent 583c9fa commit dd7e861

15 files changed

Lines changed: 650 additions & 180 deletions

auth_oauth_environment/README.rst

Lines changed: 80 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
1-
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
2-
:target: https://www.gnu.org/licenses/agpl
3-
:alt: License: AGPL-3
4-
5-
======================
6-
Auth Oauth Environment
7-
======================
8-
9-
This module extends the functionality of server environment to support OAuth
10-
providers, and allows you to enable providers and set client_id key according
11-
to environment. (Refer to module server_environment for more informations)
1+
================================================
2+
Auth oauth configuration with server_environment
3+
================================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:b787e16c08c7d8d3b53118cafeba8c96756be4e4b2a8405d57a351b746ea021e
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github
20+
:target: https://github.com/OCA/server-env/tree/17.0/auth_oauth_environment
21+
:alt: OCA/server-env
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/server-env-17-0/server-env-17-0-auth_oauth_environment
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-env&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module extends the functionality of server environment to support
32+
OAuth providers, and allows you to enable providers and set client_id
33+
key according to environment. (Refer to module server_environment for
34+
more informations)
35+
36+
**Table of contents**
37+
38+
.. contents::
39+
:local:
1240

1341
Installation
1442
============
@@ -20,83 +48,82 @@ Configuration
2048
=============
2149

2250
To configure this module, you need to add a section
23-
``[auth_oauth.provider_simple_name]`` to you server_environment_files
24-
configurations, where 'provider_simple_name' match the simplified name field on
51+
``[auth_oauth.provider_name]`` to you server_environment_files
52+
configurations, where 'provider_name' match the tech_name field on
2553
auth.oauth.provider.
2654

27-
'provider_simple_name' is the first part (until first space character) in
28-
lower case of provider name. Using existing providers, it could be either
29-
``google``, ``odoo.com``, or ``facebook``.
55+
'provider_name' is the first part (until first space character) in lower
56+
case of provider name. Using existing providers, it could be either
57+
``provider_google``, ``provider_openerp``, or ``provider_facebook``.
3058

3159
For example, if you want to activate Google and Odoo.com, your
32-
server_environment_files should look like this ::
60+
server_environment_files should look like this:
3361

34-
[auth_oauth.google]
35-
enabled=True
36-
client_id=123456789101-abcdefghijklmnopqrstuvwxyz000000
62+
::
3763

38-
[auth_oauth.odoo.com]
39-
enabled=True
64+
[auth_oauth.provider_google]
65+
client_id=123456789101-abcdefghijklmnopqrstuvwxyz000000
66+
enabled=True
4067

68+
[auth_oauth.provider_openerp]
69+
enabled=True
4170

42-
Any provider not being enabled through server_environment_files will be set as
43-
disabled automatically.
44-
45-
If you want to define a new custom provider, you should pay attention to the
46-
name to use in the server_environment_files. If you create a provider with
47-
'Dummy auth provider' as its name, then the section should be named
48-
``[auth_oauth.dummy]``.
71+
Any provider not being enabled through server_environment_files will be
72+
set as disabled automatically.
4973

74+
If you want to define a new custom provider, you should pay attention to
75+
the tech name to use in the server_environment_files. If you create a
76+
provider with 'provider_dummy' as its tech_name, then the section should
77+
be named ``[auth_oauth.provider_dummy]``.
5078

5179
Usage
5280
=====
5381

54-
Once configured, Odoo will read from server_environment_files the following
55-
fields of auth.oauth.provider :
56-
57-
* Allowed (``enabled``)
58-
* Client ID (``client_id``)
82+
Once configured, Odoo will read from server_environment_files the
83+
following fields of auth.oauth.provider :
5984

60-
61-
Known issues / Roadmap
62-
======================
63-
64-
* Due to the specific nature of this module, it cannot be tested on OCA runbot.
85+
- Allowed (``enabled``)
86+
- Client ID (``client_id``)
6587

6688
Bug Tracker
6789
===========
6890

69-
Bugs are tracked on `GitHub Issues
70-
<https://github.com/OCA/server-env/issues>`_. In case of trouble, please
71-
check there if your issue has already been reported. If you spotted it first,
72-
help us smash it by providing detailed and welcomed feedback.
91+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-env/issues>`_.
92+
In case of trouble, please check there if your issue has already been reported.
93+
If you spotted it first, help us to smash it by providing a detailed and welcomed
94+
`feedback <https://github.com/OCA/server-env/issues/new?body=module:%20auth_oauth_environment%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
95+
96+
Do not contact contributors directly about support or help with technical issues.
7397

7498
Credits
7599
=======
76100

77-
Images
78-
------
101+
Authors
102+
-------
79103

80-
* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.
104+
* Camptocamp SA
81105

82106
Contributors
83107
------------
84108

85-
* Akim Juillerat <akim.juillerat@camptocamp.com>
109+
- `Camptocamp <https://www.camptocamp.com>`__
86110

87-
Do not contact contributors directly about support or help with technical issues.
111+
- Akim Juillerat akim.juillerat@camptocamp.com
112+
- Vincent Van Rossem vincent.vanrossem@camptocamp.com>
88113

89-
Maintainer
90-
----------
114+
Maintainers
115+
-----------
116+
117+
This module is maintained by the OCA.
91118

92119
.. image:: https://odoo-community.org/logo.png
93120
:alt: Odoo Community Association
94121
:target: https://odoo-community.org
95122

96-
This module is maintained by the OCA.
97-
98123
OCA, or the Odoo Community Association, is a nonprofit organization whose
99124
mission is to support the collaborative development of Odoo features and
100125
promote its widespread use.
101126

102-
To contribute to this module, please visit https://odoo-community.org.
127+
This module is part of the `OCA/server-env <https://github.com/OCA/server-env/tree/17.0/auth_oauth_environment>`_ project on GitHub.
128+
129+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

auth_oauth_environment/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33
{
44
"name": "Auth oauth configuration with server_environment",
5-
"version": "11.0.1.0.0",
5+
"version": "17.0.1.0.0",
66
"category": "Tools",
77
"summary": "Configure mail servers with server_environment_files",
88
"author": "Camptocamp SA, Odoo Community Association (OCA)",
@@ -12,7 +12,7 @@
1212
"auth_oauth",
1313
"server_environment",
1414
],
15-
"data": ["views/auth_oauth_provider.xml"],
15+
"data": ["data/auth_oauth_provider.xml"],
1616
"auto_install": False,
1717
"installable": True,
1818
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo noupdate="1">
3+
<record id="auth_oauth.provider_openerp" model="auth.oauth.provider">
4+
<field name="tech_name">provider_openerp</field>
5+
</record>
6+
<record id="auth_oauth.provider_facebook" model="auth.oauth.provider">
7+
<field name="tech_name">provider_facebook</field>
8+
</record>
9+
<record id="auth_oauth.provider_google" model="auth.oauth.provider">
10+
<field name="tech_name">provider_google</field>
11+
</record>
12+
</odoo>
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
from . import auth_oauth_provider
2-
from . import res_config_settings
Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,36 @@
11
# Copyright 2017 Camptocamp SA
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
import json
5-
6-
from lxml import etree
74

85
from odoo import _, api, fields, models
9-
10-
from odoo.addons.server_environment import serv_config
6+
from odoo.exceptions import UserError
117

128

139
class AuthOAuthProvider(models.Model):
14-
_inherit = "auth.oauth.provider"
15-
16-
managed_by_env = fields.Boolean(compute="_compute_server_env")
17-
provider_simple_name = fields.Char(compute="_compute_simple_name")
18-
client_id = fields.Char(string="Client ID", compute="_compute_server_env")
19-
enabled = fields.Boolean(
20-
string="Allowed", compute="_compute_server_env", search="_search_enabled"
21-
)
10+
_name = "auth.oauth.provider"
11+
_inherit = ["auth.oauth.provider", "server.env.techname.mixin", "server.env.mixin"]
2212

23-
def _compute_server_env(self):
24-
for provider in self:
25-
provider_section_name = provider._get_provider_section_name()
26-
vals = {}
13+
enabled = fields.Boolean(search="_search_enabled")
2714

28-
if serv_config.has_section(provider_section_name):
29-
vals.update({"managed_by_env": True})
30-
vals.update(serv_config.items(provider_section_name))
31-
else:
32-
vals.update({"managed_by_env": False, "enabled": False})
33-
provider.update(vals)
34-
35-
def _search_enabled(self, operator, value):
36-
enabled_provider_ids = []
37-
for provider in self.search([]):
38-
provider_section_name = provider._get_provider_section_name()
39-
if serv_config.has_option(
40-
provider_section_name, "enabled"
41-
) and serv_config.get(provider_section_name, "enabled"):
42-
enabled_provider_ids.append(provider.id)
43-
return [("id", "in", enabled_provider_ids)]
44-
45-
@api.multi
46-
def _compute_simple_name(self):
47-
for provider in self:
48-
provider.provider_simple_name = provider.name.split(" ")[0].lower()
49-
50-
@api.multi
51-
def _get_provider_section_name(self):
52-
self.ensure_one()
53-
return ".".join(["auth_oauth", self.provider_simple_name])
15+
@property
16+
def _server_env_fields(self):
17+
base_fields = super()._server_env_fields
18+
oauth_fields = {
19+
"client_id": {},
20+
"enabled": {},
21+
}
22+
oauth_fields.update(base_fields)
23+
return oauth_fields
5424

5525
@api.model
56-
def fields_view_get(
57-
self, view_id=None, view_type="form", toolbar=False, submenu=False
58-
):
59-
res = super().fields_view_get(
60-
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
61-
)
62-
readonly_fields = ["enabled", "client_id"]
63-
doc = etree.XML(res["arch"])
64-
for ro_field in readonly_fields:
65-
for node in doc.xpath("//field[@name='%s']" % ro_field):
66-
node.set("readonly", "1")
67-
modifiers = json.loads(node.get("modifiers"))
68-
modifiers["readonly"] = True
69-
node.set("modifiers", json.dumps(modifiers))
26+
def _server_env_global_section_name(self):
27+
return "auth_oauth"
7028

71-
node.set(
72-
"help", _("This field is managed through server " "environment")
73-
)
74-
res["arch"] = etree.tostring(doc, encoding="unicode")
75-
return res
29+
@api.model
30+
def _search_enabled(self, operator, value):
31+
if operator not in ["=", "!="] or not isinstance(value, bool):
32+
raise UserError(_("Operation not supported"))
33+
if operator != "=":
34+
value = not value
35+
enabled = self.search([]).filtered(lambda p: p.enabled)
36+
return [("id", "in" if value else "not in", enabled.ids)]

auth_oauth_environment/models/res_config_settings.py

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
To configure this module, you need to add a section
2+
``[auth_oauth.provider_name]`` to you server_environment_files
3+
configurations, where 'provider_name' match the tech_name field on
4+
auth.oauth.provider.
5+
6+
'provider_name' is the first part (until first space character) in
7+
lower case of provider name. Using existing providers, it could be either
8+
``provider_google``, ``provider_openerp``, or ``provider_facebook``.
9+
10+
For example, if you want to activate Google and Odoo.com, your
11+
server_environment_files should look like this:
12+
```
13+
[auth_oauth.provider_google]
14+
client_id=123456789101-abcdefghijklmnopqrstuvwxyz000000
15+
enabled=True
16+
17+
[auth_oauth.provider_openerp]
18+
enabled=True
19+
```
20+
21+
Any provider not being enabled through server_environment_files will be set as
22+
disabled automatically.
23+
24+
If you want to define a new custom provider, you should pay attention to the
25+
tech name to use in the server_environment_files. If you create a provider with
26+
'provider_dummy' as its tech_name, then the section should be named
27+
``[auth_oauth.provider_dummy]``.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- [Camptocamp](https://www.camptocamp.com)
2+
- Akim Juillerat <akim.juillerat@camptocamp.com>
3+
- Vincent Van Rossem <vincent.vanrossem@camptocamp.com>>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This module extends the functionality of server environment to support OAuth
2+
providers, and allows you to enable providers and set client_id key according
3+
to environment. (Refer to module server_environment for more informations)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
To install this module, you need to have the server_environment module
2+
installed and properly configured.

0 commit comments

Comments
 (0)