Skip to content

Commit 98f70b6

Browse files
committed
[IMP] shopinvader_api_signin_jwt: Call promote directly at signin
1 parent 0c7a3f1 commit 98f70b6

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

shopinvader_api_signin_jwt/README.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Shopinvader Api Signin JWT
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:59c45a1d4cbece13c06acf5a0b621bf113fd94ed74b05de2143494c755320354
10+
!! source digest: sha256:7337f1eba6afcff7201a9185515fa52033fa3c544861e8b59aa71ed2545d6a7b
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -25,6 +25,11 @@ Shopinvader Api Signin JWT
2525
This addon adds a web API to signin into the application and create a partner
2626
if the email in the jwt payload is unknown.
2727

28+
This addon supports the "anonymous partner" feature, which allows to create
29+
carts for user that are not loggedin.
30+
When you login from an anonymous partner, your cart is transfered to your real
31+
partner, and your anonymous partner is deleted.
32+
2833
**Table of contents**
2934

3035
.. contents::
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
This addon adds a web API to signin into the application and create a partner
22
if the email in the jwt payload is unknown.
3+
4+
This addon supports the "anonymous partner" feature, which allows to create
5+
carts for user that are not loggedin.
6+
When you login from an anonymous partner, your cart is transfered to your real
7+
partner, and your anonymous partner is deleted.

shopinvader_api_signin_jwt/routers/signin.py

+3
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ def signin(
3434
Authenticate the partner based on a JWT token or a session cookie.
3535
Set the session cookie if allowed.
3636
Return HTTP code 201 if res.partner created (case of the first signin).
37+
Promote anonymous partner and delete it if any.
3738
"""
3839
if not partner:
3940
partner = env[
4041
"shopinvader_api_signin_jwt.signin_router.helper"
4142
]._create_partner_from_payload(payload)
4243
response.status_code = status.HTTP_201_CREATED
4344

45+
env["res.partner"]._promote_anonymous_partner(partner, request.cookies, response)
46+
4447

4548
@signin_router.post("/signout")
4649
def signout(

shopinvader_api_signin_jwt/static/description/index.html

+8-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010
/*
1111
:Author: David Goodger ([email protected])
12-
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
12+
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
1313
:Copyright: This stylesheet has been placed in the public domain.
1414
1515
Default cascading style sheet for the HTML output of Docutils.
16-
Despite the name, some widely supported CSS2 features are used.
1716
1817
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1918
customize this style sheet.
@@ -276,7 +275,7 @@
276275
margin-left: 2em ;
277276
margin-right: 2em }
278277

279-
pre.code .ln { color: gray; } /* line numbers */
278+
pre.code .ln { color: grey; } /* line numbers */
280279
pre.code, code { background-color: #eeeeee }
281280
pre.code .comment, code .comment { color: #5C6576 }
282281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -302,7 +301,7 @@
302301
span.pre {
303302
white-space: pre }
304303

305-
span.problematic, pre.problematic {
304+
span.problematic {
306305
color: red }
307306

308307
span.section-subtitle {
@@ -368,11 +367,15 @@ <h1 class="title">Shopinvader Api Signin JWT</h1>
368367
!! This file is generated by oca-gen-addon-readme !!
369368
!! changes will be overwritten. !!
370369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
371-
!! source digest: sha256:59c45a1d4cbece13c06acf5a0b621bf113fd94ed74b05de2143494c755320354
370+
!! source digest: sha256:d2a37ed8f608aa991e96f29205867b36c47bf9ec58fd392ec4ee8d6f386da0f2
372371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
373372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/shopinvader/odoo-shopinvader/tree/16.0/shopinvader_api_signin_jwt"><img alt="shopinvader/odoo-shopinvader" src="https://img.shields.io/badge/github-shopinvader%2Fodoo--shopinvader-lightgray.png?logo=github" /></a></p>
374373
<p>This addon adds a web API to signin into the application and create a partner
375374
if the email in the jwt payload is unknown.</p>
375+
<p>This addon supports the “anonymous partner” feature, which allows to create
376+
carts for user that are not loggedin.
377+
When you login from an anonymous partner, your cart is transfered to your real
378+
partner, and your anonymous partner is deleted.</p>
376379
<p><strong>Table of contents</strong></p>
377380
<div class="contents local topic" id="contents">
378381
<ul class="simple">

shopinvader_api_signin_jwt/tests/test_signin.py

+33
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from odoo.addons.fastapi.tests.common import FastAPITransactionCase
99
from odoo.addons.fastapi_auth_jwt.dependencies import auth_jwt_default_validator_name
10+
from odoo.addons.shopinvader_anonymous_partner.models.res_partner import COOKIE_NAME
1011

1112
from ..routers import signin_router
1213

@@ -79,6 +80,38 @@ def test_signin(self):
7980
res = client.post("/signin", headers={"Authorization": token})
8081
self.assertEqual(res.status_code, 200)
8182

83+
def test_signin_anonymous_cart(self):
84+
anonymous_partner = self.env["res.partner"].create(
85+
{"name": "Test anonymous", "anonymous_token": "1234", "active": False}
86+
)
87+
product = self.env["product.product"].create(
88+
{"name": "product", "uom_id": self.env.ref("uom.product_uom_unit").id}
89+
)
90+
anonymous_cart = self.env["sale.order"].create(
91+
{
92+
"partner_id": anonymous_partner.id,
93+
"order_line": [
94+
(0, 0, {"product_id": product.id, "product_uom_qty": 1}),
95+
],
96+
"typology": "cart",
97+
}
98+
)
99+
100+
token = self._get_token()
101+
with self._create_test_client() as client:
102+
res = client.post(
103+
"/signin",
104+
headers={"Authorization": token},
105+
cookies={COOKIE_NAME: "1234"},
106+
)
107+
self.assertFalse(res.cookies.get(COOKIE_NAME))
108+
self.assertFalse(anonymous_partner.exists())
109+
self.assertFalse(anonymous_cart.exists())
110+
partner = self.env["res.partner"].search([("email", "=", "[email protected]")])
111+
cart = self.env["sale.order"].search([("partner_id", "=", partner.id)])
112+
self.assertEqual(len(cart.order_line), 1)
113+
self.assertEqual(cart.order_line[0].product_id, product)
114+
82115
def test_signout(self):
83116
self.validator.write({"cookie_enabled": True, "cookie_name": "test_cookie"})
84117
token = self._get_token()

0 commit comments

Comments
 (0)