-
Notifications
You must be signed in to change notification settings - Fork 104
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
[16.0][IMP] shopinvader signin jwt anonymous cart #1523
Merged
shopinvader-git-bot
merged 3 commits into
shopinvader:16.0
from
acsone:16.0-shopinvader_signin_anonymous_cart-qgr
Jun 4, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
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
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
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
This addon adds a web API to signin into the application and create a partner | ||
if the email in the jwt payload is unknown. | ||
If we had an anonymous partner, transfer his cart to the loggedin partner and delete it. |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
* Manage anonymous cart (see https://github.com/shopinvader/odoo-shopinvader/issues/1428) | ||
* Use ``fastapi_auth_jwt.auth_jwt_authenticated_odoo_env`` dependency for the env (see https://github.com/OCA/rest-framework/issues/406) |
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
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
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
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
from odoo.addons.fastapi.tests.common import FastAPITransactionCase | ||
from odoo.addons.fastapi_auth_jwt.dependencies import auth_jwt_default_validator_name | ||
from odoo.addons.shopinvader_anonymous_partner.models.res_partner import COOKIE_NAME | ||
|
||
from ..routers import signin_router | ||
|
||
|
@@ -79,6 +80,38 @@ def test_signin(self): | |
res = client.post("/signin", headers={"Authorization": token}) | ||
self.assertEqual(res.status_code, 200) | ||
|
||
def test_signin_anonymous_cart(self): | ||
anonymous_partner = self.env["res.partner"].create( | ||
{"name": "Test anonymous", "anonymous_token": "1234", "active": False} | ||
) | ||
product = self.env["product.product"].create( | ||
{"name": "product", "uom_id": self.env.ref("uom.product_uom_unit").id} | ||
) | ||
anonymous_cart = self.env["sale.order"].create( | ||
{ | ||
"partner_id": anonymous_partner.id, | ||
"order_line": [ | ||
(0, 0, {"product_id": product.id, "product_uom_qty": 1}), | ||
], | ||
"typology": "cart", | ||
} | ||
) | ||
|
||
token = self._get_token() | ||
with self._create_test_client() as client: | ||
res = client.post( | ||
"/signin", | ||
headers={"Authorization": token}, | ||
cookies={COOKIE_NAME: "1234"}, | ||
) | ||
self.assertFalse(res.cookies.get(COOKIE_NAME)) | ||
self.assertFalse(anonymous_partner.exists()) | ||
self.assertFalse(anonymous_cart.exists()) | ||
partner = self.env["res.partner"].search([("email", "=", "[email protected]")]) | ||
cart = self.env["sale.order"].search([("partner_id", "=", partner.id)]) | ||
self.assertEqual(len(cart.order_line), 1) | ||
self.assertEqual(cart.order_line[0].product_id, product) | ||
|
||
def test_signout(self): | ||
self.validator.write({"cookie_enabled": True, "cookie_name": "test_cookie"}) | ||
token = self._get_token() | ||
|
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
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 test_sale_cart |
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,37 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.addons.sale_cart.tests.test_sale_cart import TestSaleCart as TestSaleCartBase | ||
|
||
|
||
class TestSaleCart(TestSaleCartBase): | ||
def test_transfer_cart(self): | ||
product_2 = self.env["product.product"].create( | ||
{"name": "product", "uom_id": self.env.ref("uom.product_uom_unit").id} | ||
) | ||
partner_2 = self.env["res.partner"].create({"name": "partner 2"}) | ||
so_cart_2 = self.env["sale.order"].create( | ||
{ | ||
"partner_id": partner_2.id, | ||
"order_line": [ | ||
(0, 0, {"product_id": self.product.id, "product_uom_qty": 1}), | ||
(0, 0, {"product_id": product_2.id, "product_uom_qty": 1}), | ||
], | ||
"typology": "cart", | ||
} | ||
) | ||
merged_cart = so_cart_2._transfer_cart(self.partner.id) | ||
self.assertEqual(merged_cart.id, self.so_cart.id) | ||
self.assertEqual(len(merged_cart.order_line), 2) | ||
self.assertEqual( | ||
merged_cart.order_line.filtered( | ||
lambda l, product=self.product: l.product_id.id == product.id | ||
).product_uom_qty, | ||
2, | ||
) | ||
self.assertEqual( | ||
merged_cart.order_line.filtered( | ||
lambda l, product=product_2: l.product_id.id == product.id | ||
).product_uom_qty, | ||
1, | ||
) |
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.
@qgroulard who is supposed to call
_create_anonymous_partner__cookie
?Shouldn't it happen the 1st time you call a cart endpoint w/o authenticated customer?
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.
@simahawk this is done by the
auth_jwt_authenticated_or_anonymous_partner_autocreate
FastAPI depend. There is an example in #1364 where the cart routes are mounted with that authentication method.