Skip to content

Commit

Permalink
[ADD] shopinvader_auth_jwt_transfer_cart
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Sep 25, 2023
1 parent b749f3c commit 3c72341
Show file tree
Hide file tree
Showing 11 changed files with 575 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/shopinvader_auth_jwt_transfer_cart/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
77 changes: 77 additions & 0 deletions shopinvader_auth_jwt_transfer_cart/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/shopinvader/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 <https://github.com/OCA/shopinvader/issues/new?body=module:%20shopinvader_auth_jwt_transfer_cart%0Aversion:%2014.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
~~~~~~~~~~~~

* `Akretion <https://www.akretion.com>`_:

* 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 <https://github.com/OCA/shopinvader/tree/14.0/shopinvader_auth_jwt_transfer_cart>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions shopinvader_auth_jwt_transfer_cart/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import services
9 changes: 9 additions & 0 deletions shopinvader_auth_jwt_transfer_cart/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
}
3 changes: 3 additions & 0 deletions shopinvader_auth_jwt_transfer_cart/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Akretion <https://www.akretion.com>`_:

* Florian Mounier
1 change: 1 addition & 0 deletions shopinvader_auth_jwt_transfer_cart/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions shopinvader_auth_jwt_transfer_cart/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Activation is automatic.
1 change: 1 addition & 0 deletions shopinvader_auth_jwt_transfer_cart/services/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import cart
48 changes: 48 additions & 0 deletions shopinvader_auth_jwt_transfer_cart/services/cart.py
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit 3c72341

Please sign in to comment.