-
-
Notifications
You must be signed in to change notification settings - Fork 523
[16.0] [ADD] cross_connect_client #735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c833e56
[ADD] cross_connect_client
paradoxxxzero b7daf4b
[IMP] cross_connect_client: Handle redirect_url in controller
paradoxxxzero ac3bfe6
cross_connect_client: only pass redirect_url if set
sebastienbeau 39c1072
cross_connect_client: by default open in a new windows as we change o…
sebastienbeau 52bd7ff
[IMP] cross_connect_client: Require and send mail
paradoxxxzero 0ac7ee6
[IMP] Remove default value for the name of the server
florian-dacosta 255fd86
[IMP] Avoid deleting the cross connect server groups when unactiving it
florian-dacosta 7e18e52
Merge pull request #3 from akretion/16.0-add-cross_connect_client-fdc…
paradoxxxzero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 florian.mounier@akretion.com | ||
|
|
||
| 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 hidden or 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 hidden or 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 <florian.mounier@akretion.com> | ||
| # 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 hidden or 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 hidden or 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 <florian.mounier@akretion.com> | ||
| # 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(request.params.get("redirect_url")) | ||
| return request.redirect(url, local=False) | ||
This file contains hidden or 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 hidden or 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,179 @@ | ||
| # Copyright 2024 Akretion (http://www.akretion.com). | ||
| # @author Florian Mounier <florian.mounier@akretion.com> | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
|
||
| 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, | ||
| help="This name will be used for the new created app", | ||
| ) | ||
| 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("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 = 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": "new", | ||
| } | ||
| ) | ||
|
|
||
| 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, redirect_url=None): | ||
| 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")) | ||
|
|
||
| if not self.env.user.email: | ||
| raise UserError(_("User email is required")) | ||
|
|
||
| data = { | ||
| "id": self.env.user.id, | ||
| "name": self.env.user.name, | ||
| "login": self.env.user.login, | ||
| "email": self.env.user.email, | ||
| "lang": self.env.user.lang, | ||
| "groups": [group.cross_connect_server_group_id for group in groups], | ||
| } | ||
| if redirect_url: | ||
| data["redirect_url"] = redirect_url | ||
|
|
||
| response = self._request("POST", "/access", data=data) | ||
| 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 | ||
| ).write({"cross_connect_server_id": False}) | ||
|
|
||
| # Create or Update existing groups | ||
| for remote_group in remote_groups: | ||
| existing_group = self.env["res.groups"].search( | ||
| [("cross_connect_server_group_id", "=", remote_group["id"])] | ||
| ) | ||
| if existing_group and not existing_group.cross_connect_server_id: | ||
| existing_group.write({"cross_connect_server_id": self.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.write({"cross_connect_server_id": False}) | ||
|
|
||
| @property | ||
| def _server_env_fields(self): | ||
| return {"api_key": {}} | ||
|
|
||
| def unlink(self): | ||
| for rec in self: | ||
| # deleting the groups will delete the menu and related action. | ||
| rec.group_ids.unlink() | ||
| return super().unlink() | ||
This file contains hidden or 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 <florian.mounier@akretion.com> | ||
| # 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 hidden or 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 <florian.mounier@akretion.com> |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should override the
unlinkmethod to delete the groups and menu before deleting the cross connect server.(Even without changing the
action_disablemethod, I guess thecross.connect.servercould be deleted while enabled)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can’t we cascade these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better indeed.