-
-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
035093d
commit c3e5a28
Showing
19 changed files
with
1,237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
==================== | ||
Cross Connect Client | ||
==================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:f10ceaed1b91df49c3a9b4e8acdef3d412d7ce50105f6f1ca752630fc1559d8e | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github | ||
:target: https://github.com/OCA/server-auth/tree/16.0/cross_connect_client | ||
:alt: OCA/server-auth | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/server-auth-16-0/server-auth-16-0-cross_connect_client | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows this odoo instance users to connect directly on | ||
another odoo instance where the module ``cross_connect_server`` is | ||
installed. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
First of all after installing the module, you need to configure the | ||
server connection. | ||
|
||
In order to do that, you need to go to the menu | ||
``Settings > Technical > Cross Connect > Cross Connect Servers`` and | ||
create a new server to connect to. | ||
|
||
Fill the fields with the server's information : | ||
|
||
- Url: The api root path (e.g. ``https://my-remote-odoo.com/api``) | ||
- Api Key: The api-key from the ``cross_connect_server`` configuration | ||
|
||
Then click on the ``Sync Cross Connection`` button to check if the | ||
connection is working and to sync the remote server's groups. | ||
|
||
After that, you will have to affect the remote groups to the local users | ||
in order for them to be able to connect to the remote server. | ||
|
||
Once an user has a remote group, a new top level menu will appear in the | ||
menu bar with the Cross Connect Server's name. Clicking on it will | ||
redirect the user to the remote server logged in as the user. | ||
|
||
You can change each menu icon (for use with ``web_responsive`` for | ||
instance) by setting the ``Web Icon Data`` in the server configuration. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-auth/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/server-auth/issues/new?body=module:%20cross_connect_client%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* Akretion | ||
|
||
Contributors | ||
------------ | ||
|
||
- Florian Mounier [email protected] | ||
|
||
Maintainers | ||
----------- | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
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. | ||
|
||
.. |maintainer-paradoxxxzero| image:: https://github.com/paradoxxxzero.png?size=40px | ||
:target: https://github.com/paradoxxxzero | ||
:alt: paradoxxxzero | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-paradoxxxzero| | ||
|
||
This module is part of the `OCA/server-auth <https://github.com/OCA/server-auth/tree/16.0/cross_connect_client>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import controllers | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Cross Connect Client", | ||
"version": "16.0.1.0.0", | ||
"author": "Akretion, Odoo Community Association (OCA)", | ||
"summary": "Cross Connect Client allows to connect to a " | ||
"Cross Connect Server enabled odoo instance.", | ||
"category": "Tools", | ||
"depends": ["server_environment"], | ||
"website": "https://github.com/OCA/server-auth", | ||
"data": [ | ||
"security/ir_model_access.xml", | ||
"views/cross_connect_server_views.xml", | ||
], | ||
"maintainers": ["paradoxxxzero"], | ||
"demo": [], | ||
"installable": True, | ||
"license": "AGPL-3", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import cross_connect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import _ | ||
from odoo.exceptions import UserError | ||
from odoo.http import Controller, request, route | ||
|
||
|
||
class CrossConnectController(Controller): | ||
@route( | ||
["/cross_connect_server/<int:server_id>"], | ||
methods=["GET"], | ||
type="http", | ||
auth="public", | ||
) | ||
def cross_connect( | ||
self, | ||
server_id, | ||
**params, | ||
): | ||
server = request.env["cross.connect.server"].sudo().browse(server_id) | ||
if not server: | ||
raise UserError(_("Server not found")) | ||
|
||
url = server._get_cross_connect_url() | ||
return request.redirect(url, local=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import cross_connect_server | ||
from . import res_groups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from urllib.parse import urlparse | ||
|
||
import requests | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class CrossConnectServer(models.Model): | ||
_name = "cross.connect.server" | ||
_description = "Cross Connect Server" | ||
_inherit = "server.env.mixin" | ||
|
||
name = fields.Char( | ||
required=True, compute="_compute_name", readonly=False, store=True | ||
) | ||
server_url = fields.Char(required=True) | ||
api_key = fields.Char( | ||
required=True, | ||
) | ||
group_ids = fields.One2many( | ||
"res.groups", | ||
inverse_name="cross_connect_server_id", | ||
string="Cross Connect Server Groups", | ||
readonly=True, | ||
) | ||
menu_id = fields.Many2one( | ||
"ir.ui.menu", | ||
string="Menu", | ||
help="Menu to display the Cross Connect Server in the menu", | ||
compute="_compute_menu_id", | ||
store=True, | ||
) | ||
web_icon_data = fields.Binary( | ||
compute="_compute_web_icon_data", inverse="_inverse_web_icon_data" | ||
) | ||
|
||
@api.depends("server_url") | ||
def _compute_name(self): | ||
for record in self: | ||
if not record.name or record.name == "/": | ||
try: | ||
record.name = urlparse(record.server_url).hostname | ||
except Exception: | ||
record.name = "/" | ||
|
||
@api.depends("name", "group_ids") | ||
def _compute_menu_id(self): | ||
for record in self: | ||
if not record.group_ids: | ||
if record.menu_id: | ||
if record.menu_id.action: | ||
record.menu_id.action.unlink() | ||
record.menu_id.unlink() | ||
record.menu_id = False | ||
continue | ||
|
||
menu_groups = self.env.ref("base.group_system") | record.group_ids | ||
|
||
if not record.menu_id: | ||
action = self.env["ir.actions.act_url"].create( | ||
{ | ||
"name": record.name, | ||
"url": f"/cross_connect_server/{record.id}", | ||
"target": "self", | ||
} | ||
) | ||
|
||
record.menu_id = self.env["ir.ui.menu"].create( | ||
{ | ||
"name": record.name, | ||
"action": f"ir.actions.act_url,{action.id}", # noqa | ||
"web_icon": "cross_connect_client,static/description/web_icon_data.png", | ||
"groups_id": [(6, 0, menu_groups.ids)], | ||
"sequence": 100, | ||
} | ||
) | ||
else: | ||
record.menu_id.name = record.name | ||
record.menu_id.groups_id = [(6, 0, menu_groups.ids)] | ||
|
||
@api.depends("menu_id") | ||
def _compute_web_icon_data(self): | ||
for record in self: | ||
record.web_icon_data = record.menu_id.web_icon_data | ||
|
||
def _inverse_web_icon_data(self): | ||
for record in self: | ||
record.menu_id.web_icon_data = record.web_icon_data | ||
|
||
def _absolute_url_for(self, path): | ||
return f"{self.server_url.rstrip('/')}/cross_connect/{path.lstrip('/')}" | ||
|
||
def _request(self, method, url, headers=None, data=None): | ||
headers = headers or {} | ||
headers["api-key"] = self.api_key | ||
response = requests.request( | ||
method, | ||
self._absolute_url_for(url), | ||
headers=headers, | ||
json=data, | ||
timeout=10, | ||
) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
def _get_cross_connect_url(self): | ||
self.ensure_one() | ||
groups = self.env.user.groups_id & self.group_ids | ||
if not groups: | ||
raise UserError(_("You are not allowed to access this server")) | ||
|
||
response = self._request( | ||
"POST", | ||
"/access", | ||
data={ | ||
"id": self.env.user.id, | ||
"name": self.env.user.name, | ||
"login": self.env.user.login, | ||
"lang": self.env.user.lang, | ||
"groups": [group.cross_connect_server_group_id for group in groups], | ||
}, | ||
) | ||
client_id = response.get("client_id") | ||
token = response.get("token") | ||
if not token: | ||
raise UserError(_("Missing token")) | ||
|
||
return self._absolute_url_for(f"login/{client_id}/{token}") | ||
|
||
def _sync_groups(self): | ||
self.ensure_one() | ||
response = self._request("GET", "/sync") | ||
remote_groups = response.get("groups", []) | ||
# Removing groups that are not on the remote server | ||
remote_groups_ids = {remote_group["id"] for remote_group in remote_groups} | ||
self.group_ids.filtered( | ||
lambda group: group.cross_connect_server_group_id not in remote_groups_ids | ||
).unlink() | ||
|
||
# Create or Update existing groups | ||
for remote_group in remote_groups: | ||
existing_group = self.group_ids.filtered( | ||
lambda group: group.cross_connect_server_group_id == remote_group["id"] | ||
) | ||
if existing_group: | ||
existing_group.sudo().write( | ||
{ | ||
"name": f"{self.name}: {remote_group['name']}", | ||
"comment": remote_group["comment"], | ||
} | ||
) | ||
else: | ||
self.env["res.groups"].sudo().create( | ||
{ | ||
"cross_connect_server_id": self.id, | ||
"cross_connect_server_group_id": remote_group["id"], | ||
"name": f"{self.name}: {remote_group['name']}", | ||
"comment": remote_group["comment"], | ||
} | ||
) | ||
|
||
def action_sync(self): | ||
for record in self: | ||
record._sync_groups() | ||
|
||
def action_disable(self): | ||
for record in self: | ||
record.group_ids.unlink() | ||
|
||
@property | ||
def _server_env_fields(self): | ||
return {"api_key": {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2024 Akretion (http://www.akretion.com). | ||
# @author Florian Mounier <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResGroups(models.Model): | ||
_inherit = "res.groups" | ||
|
||
cross_connect_server_id = fields.Many2one( | ||
"cross.connect.server", string="Originating Cross Connect Server" | ||
) | ||
cross_connect_server_group_id = fields.Integer( | ||
string="Originating Cross Connect Server Group ID" | ||
) | ||
|
||
_sql_constraints = [ | ||
( | ||
"cross_connect_server_group_id_cross_connect_server_id_unique", | ||
"unique (cross_connect_server_group_id, cross_connect_server_id)", | ||
"Cross Connect Server Group ID must be unique per Cross Connect Server", | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Florian Mounier <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This module allows this odoo instance users to connect directly on another odoo instance | ||
where the module `cross_connect_server` is installed. |
Oops, something went wrong.