From 3c72341c5cdb7079e25d988de222b0cb38a34fce Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Tue, 25 Jan 2022 16:01:58 +0100 Subject: [PATCH] [ADD] shopinvader_auth_jwt_transfer_cart --- .../addons/shopinvader_auth_jwt_transfer_cart | 1 + .../setup.py | 6 + shopinvader_auth_jwt_transfer_cart/README.rst | 77 ++++ .../__init__.py | 1 + .../__manifest__.py | 9 + .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 1 + .../readme/USAGE.rst | 1 + .../services/__init__.py | 1 + .../services/cart.py | 48 ++ .../static/description/index.html | 427 ++++++++++++++++++ 11 files changed, 575 insertions(+) create mode 120000 setup/shopinvader_auth_jwt_transfer_cart/odoo/addons/shopinvader_auth_jwt_transfer_cart create mode 100644 setup/shopinvader_auth_jwt_transfer_cart/setup.py create mode 100644 shopinvader_auth_jwt_transfer_cart/README.rst create mode 100644 shopinvader_auth_jwt_transfer_cart/__init__.py create mode 100644 shopinvader_auth_jwt_transfer_cart/__manifest__.py create mode 100644 shopinvader_auth_jwt_transfer_cart/readme/CONTRIBUTORS.rst create mode 100644 shopinvader_auth_jwt_transfer_cart/readme/DESCRIPTION.rst create mode 100644 shopinvader_auth_jwt_transfer_cart/readme/USAGE.rst create mode 100644 shopinvader_auth_jwt_transfer_cart/services/__init__.py create mode 100644 shopinvader_auth_jwt_transfer_cart/services/cart.py create mode 100644 shopinvader_auth_jwt_transfer_cart/static/description/index.html diff --git a/setup/shopinvader_auth_jwt_transfer_cart/odoo/addons/shopinvader_auth_jwt_transfer_cart b/setup/shopinvader_auth_jwt_transfer_cart/odoo/addons/shopinvader_auth_jwt_transfer_cart new file mode 120000 index 0000000000..b2697d7724 --- /dev/null +++ b/setup/shopinvader_auth_jwt_transfer_cart/odoo/addons/shopinvader_auth_jwt_transfer_cart @@ -0,0 +1 @@ +../../../../shopinvader_auth_jwt_transfer_cart \ No newline at end of file diff --git a/setup/shopinvader_auth_jwt_transfer_cart/setup.py b/setup/shopinvader_auth_jwt_transfer_cart/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/shopinvader_auth_jwt_transfer_cart/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/shopinvader_auth_jwt_transfer_cart/README.rst b/shopinvader_auth_jwt_transfer_cart/README.rst new file mode 100644 index 0000000000..b063dd5adf --- /dev/null +++ b/shopinvader_auth_jwt_transfer_cart/README.rst @@ -0,0 +1,77 @@ +=========================================== +Shopinvader JWT Authentication Tranfer Cart +=========================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fshopinvader-lightgray.png?logo=github + :target: https://github.com/OCA/shopinvader/tree/14.0/shopinvader_auth_jwt_transfer_cart + :alt: OCA/shopinvader +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/shopinvader-14-0/shopinvader-14-0-shopinvader_auth_jwt_transfer_cart + :alt: Translate me on Weblate + +|badge1| |badge2| |badge3| |badge4| + +This module adds a new transfer route to cart service that takes a JWT token as POST parameter and transfer the cart from the logged in partner to the partner in the given jwt token. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Activation is automatic. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* `Akretion `_: + + * Florian Mounier + +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. + +This module is part of the `OCA/shopinvader `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/shopinvader_auth_jwt_transfer_cart/__init__.py b/shopinvader_auth_jwt_transfer_cart/__init__.py new file mode 100644 index 0000000000..99464a7510 --- /dev/null +++ b/shopinvader_auth_jwt_transfer_cart/__init__.py @@ -0,0 +1 @@ +from . import services diff --git a/shopinvader_auth_jwt_transfer_cart/__manifest__.py b/shopinvader_auth_jwt_transfer_cart/__manifest__.py new file mode 100644 index 0000000000..ce5ab7bf8f --- /dev/null +++ b/shopinvader_auth_jwt_transfer_cart/__manifest__.py @@ -0,0 +1,9 @@ +{ + "name": "Shopinvader JWT Authentication Tranfer Cart", + "version": "14.0.1.0.0", + "summary": "Add a cart route to transfer cart from a partner to another", + "website": "https://github.com/shopinvader/odoo-shopinvader", + "depends": ["shopinvader_auth_jwt"], + "author": "Akretion, Odoo Community Association (OCA)", + "license": "AGPL-3", +} diff --git a/shopinvader_auth_jwt_transfer_cart/readme/CONTRIBUTORS.rst b/shopinvader_auth_jwt_transfer_cart/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..a4d0ad9229 --- /dev/null +++ b/shopinvader_auth_jwt_transfer_cart/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Akretion `_: + + * Florian Mounier diff --git a/shopinvader_auth_jwt_transfer_cart/readme/DESCRIPTION.rst b/shopinvader_auth_jwt_transfer_cart/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..cb4f14c0cf --- /dev/null +++ b/shopinvader_auth_jwt_transfer_cart/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds a new transfer route to cart service that takes a JWT token as POST parameter and transfer the cart from the logged in partner to the partner in the given jwt token. diff --git a/shopinvader_auth_jwt_transfer_cart/readme/USAGE.rst b/shopinvader_auth_jwt_transfer_cart/readme/USAGE.rst new file mode 100644 index 0000000000..8a163b1afc --- /dev/null +++ b/shopinvader_auth_jwt_transfer_cart/readme/USAGE.rst @@ -0,0 +1 @@ +Activation is automatic. diff --git a/shopinvader_auth_jwt_transfer_cart/services/__init__.py b/shopinvader_auth_jwt_transfer_cart/services/__init__.py new file mode 100644 index 0000000000..d98a08bc7f --- /dev/null +++ b/shopinvader_auth_jwt_transfer_cart/services/__init__.py @@ -0,0 +1 @@ +from . import cart diff --git a/shopinvader_auth_jwt_transfer_cart/services/cart.py b/shopinvader_auth_jwt_transfer_cart/services/cart.py new file mode 100644 index 0000000000..c0c6ef5703 --- /dev/null +++ b/shopinvader_auth_jwt_transfer_cart/services/cart.py @@ -0,0 +1,48 @@ +from odoo import _ +from odoo.exceptions import AccessDenied + +from odoo.addons.component.core import Component + + +class CartService(Component): + _inherit = "shopinvader.cart.service" + + def _decode_token(self, token): + validator = self.env["auth.jwt.validator"]._get_validator_by_name( + validator_name="shopinvader" + ) + while validator: + try: + return validator._decode(token) + except Exception: + validator = validator.next_validator_id + + def _validator_transfer(self): + return { + "token": {"type": "string", "required": True}, + } + + def transfer(self, token=None): + cart = self._get() + auth_token = self._decode_token(token) + if not auth_token or not auth_token.get("email"): + raise AccessDenied(_("Invalid new auth token")) + + partner = self.env["shopinvader.partner"].search( + [("partner_email", "=", auth_token["email"])] + ) + + if len(partner) != 1: + raise AccessDenied(_("Invalid partner email in token")) + + # Change cart partner: + res_partner_id = partner.record_id.id + + cart.write_with_onchange( + { + "partner_id": res_partner_id, + "partner_shipping_id": res_partner_id, + "partner_invoice_id": res_partner_id, + } + ) + return self._to_json(cart) diff --git a/shopinvader_auth_jwt_transfer_cart/static/description/index.html b/shopinvader_auth_jwt_transfer_cart/static/description/index.html new file mode 100644 index 0000000000..9149c5fedc --- /dev/null +++ b/shopinvader_auth_jwt_transfer_cart/static/description/index.html @@ -0,0 +1,427 @@ + + + + + + +Shopinvader JWT Authentication Tranfer Cart + + + +
+

Shopinvader JWT Authentication Tranfer Cart

+ + +

Beta License: AGPL-3 OCA/shopinvader Translate me on Weblate

+

This module adds a new transfer route to cart service that takes a JWT token as POST parameter and transfer the cart from the logged in partner to the partner in the given jwt token.

+

Table of contents

+ +
+

Usage

+

Activation is automatic.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/shopinvader project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ +