-
Notifications
You must be signed in to change notification settings - Fork 18
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
Implement admin page for gift cards #377
Conversation
4cf7347
to
e615341
Compare
api/src/firstrun.py
Outdated
amount=product.price, | ||
validation_code=12989519, | ||
email="[email protected]", | ||
status="activated", |
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.
What does the activated
status mean for a gift card? Has that been used?
I would think a gift card had the following states:
Valid
(when it has been bought and not yet used)Used
(when it has been used by a customer and cannot be used again)Cancelled
(if we have paid it back to the customer for whatever reason, and the customer should not be allowed to use it)
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.
Cancelling would be useful, we should add that
I think it would be nice if the admin page had a way to cancel the gift cards in case they are paid back. This can be implemented in a later PR (just create an issue for it, in that case). |
e615341
to
9a59c96
Compare
I opened a new issue about cancelling gift cards |
@coderabbitai review |
WalkthroughThe recent changes involve the introduction of gift card functionality within an e-commerce platform, both on the admin frontend and the API backend. New classes for handling gift cards were added to the admin models, and corresponding React components were created to display and manage gift cards. Backend changes include database schema updates, new API routes for gift cards, and modifications to existing entities and models to support gift card transactions. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on X ? TipsChat with CodeRabbit Bot (
|
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.
Review Status
Actionable comments generated: 5
Configuration used: CodeRabbit UI
Files selected for processing (12)
- admin/src/Models/GiftCard.js (1 hunks)
- admin/src/Models/GiftCardRow.js (1 hunks)
- admin/src/Sales/GiftCardList.js (1 hunks)
- admin/src/Sales/GiftCardShow.js (1 hunks)
- admin/src/Sales/OrderList.js (2 hunks)
- admin/src/Sales/Routes.jsx (2 hunks)
- admin/src/app.jsx (1 hunks)
- api/src/firstrun.py (3 hunks)
- api/src/migrations/0025_initial_gift_card.sql (2 hunks)
- api/src/shop/entities.py (3 hunks)
- api/src/shop/models.py (2 hunks)
- api/src/shop/views.py (2 hunks)
Files skipped from review due to trivial changes (1)
- admin/src/Sales/OrderList.js
Additional comments: 29
admin/src/Models/GiftCard.js (1)
- 6-8: The
del
method in theGiftCard
class correctly throws an error to prevent deletion of gift card data, which is a good practice for sensitive information. Ensure that this behavior is documented in the codebase and that any client code is aware that deletion is not supported for gift cards.admin/src/Models/GiftCardRow.js (3)
6-8: The
del
method inGiftCardRow
correctly throws an error to prevent deletion operations, which aligns with the need to retain sensitive gift card data for records or compliance.11-19: Ensure that the attributes defined in
GiftCardRow.model
match the backend schema and that the frontend correctly handles the default values, such asnull
foramount
andproduct_quantity
, and an empty string forname
.4-19: The
GiftCardRow
class appears to be a simple data model without much logic, which is acceptable if the business logic is handled elsewhere. Ensure that this design is consistent with the rest of the system's architecture.admin/src/Sales/GiftCardList.js (5)
1-8: The imports and component setup in
GiftCardList.js
appear to be correctly implemented and follow standard React conventions.10-20: The
Row
functional component is implemented correctly, with proper usage of theitem
prop to render gift card details.23-30: The initialization of
this.collection
with theGiftCard
model and URL endpoint in theGiftCardList
constructor appears to be correct. Verify that the URL/webshop/gift-card
correctly points to the gift card data endpoint.32-47: The
render
method inGiftCardList
is correctly implemented, with theCollectionTable
andSearchBox
components being used appropriately to render the UI.51-51: The export of the
GiftCardList
component is correct, allowing it to be used in other parts of the admin system.admin/src/Sales/GiftCardShow.js (2)
61-61: The currency value calculation seems to assume a fixed conversion rate of 100. If this is not the case, consider using a dynamic conversion rate or clarify the logic behind this fixed value.
39-44: Ensure that the display of email and validation code adheres to privacy and security best practices, and that only authorized users can access this sensitive information.
admin/src/Sales/Routes.jsx (2)
4-5: The imports for
GiftCardList
andGiftCardShow
are correctly added to the file.18-19: The routes for
GiftCardList
andGiftCardShow
are correctly set up and follow the existing routing pattern.admin/src/app.jsx (1)
- 80-83: The addition of the "Presentkort" navigation item is consistent with the PR objectives and integrates well with the existing navigation structure.
api/src/firstrun.py (3)
315-315: The change from a fixed
test_date
todatetime.now()
for thecreated_at
field of transactions will result in transactions having the current timestamp. Confirm that this change aligns with the intended behavior of the script, as it may affect tests or other operations that rely on thefirstrun.py
script.335-335: The
completed_at
field inTransactionAction
is now set todatetime.now()
, which could affect the reproducibility of test data. Ensure this change is consistent with the intended use of the script.414-436: The loop in
create_shop_gift_cards
creates gift cards with alternating "valid" and "used" statuses. Verify that the number of gift cards created and their properties meet the requirements for initial data setup. Additionally, consider adding comments to explain the logic behind the alternating statuses and the significance of the validation code values.api/src/migrations/0025_initial_gift_card.sql (3)
7-7: The
status
field in thewebshop_gift_card
table has been correctly updated to include the new enum values 'valid', 'used', 'expired', and 'cancelled', which is consistent with the PR objectives and AI-generated summaries.18-18: The addition of the
amount
field to thewebshop_product_gift_card_mapping
table is consistent with the PR objectives and AI-generated summaries, and the SQL syntax for its definition is correct.4-10: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [22-22]
The
ALTER TABLE
statement making themember_id
column in thewebshop_transactions
table nullable is not mentioned in the PR objectives or AI-generated summaries. It appears to be an important change to allow gift cards to be purchasable without being a member. Please verify that this change is intentional and correctly implemented.Verification successful
The change to make the
member_id
column nullable in thewebshop_transactions
table is confirmed by the migration file0025_initial_gift_card.sql
. The corresponding model inapi/src/shop/models.py
has been updated to reflect this change (nullable=True
), and the references inapi/src/shop/views.py
indicate that the application logic is prepared to handle nullablemember_id
. No additional constraints or triggers related to this change have been found. The change appears to be intentional and correctly implemented to support the purchase of gift cards without requiring membership.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the `member_id` column is now nullable and check if there are any constraints or triggers related to this column that might need to be updated. rg 'member_id' api/src/ --files-with-matchesLength of output: 2469
Script:
#!/bin/bash # Check the contents of the migration file for changes to the `member_id` column cat api/src/migrations/0025_initial_gift_card.sql # Look for references to the `member_id` column in the shop models and views rg 'member_id' api/src/shop/models.py rg 'member_id' api/src/shop/views.pyLength of output: 2126
api/src/shop/entities.py (4)
2-2: The import modification to include
DESC
is correct and aligns with the usage in the new entity declarations.58-62: The
gift_card_entity
declaration appears correct, with appropriatesearch_columns
specified. Ensure that all fields listed are indexed for performance optimization.65-69: The
gift_card_content_entity
declaration includes anexpand_fields
definition forproduct
. Verify that theProductGiftCardMapping.product
relationship is correctly set up and that theProduct.name
field is accessible as intended.58-70: Confirm that the new
GiftCard
andProductGiftCardMapping
entities are properly integrated into the system, including views, serializers, and any other components that may interact with them.api/src/shop/models.py (2)
185-202: The changes to the
GiftCard
class status enum values and the default status are consistent with the PR objectives and the AI-generated summary. Ensure that all parts of the codebase that interact with theGiftCard
status are updated to reflect these new enum values.221-229: The addition of the
amount
column to theProductGiftCardMapping
class aligns with the PR objectives. Ensure that this new column is properly handled in all parts of the code whereProductGiftCardMapping
instances are created or manipulated.api/src/shop/views.py (3)
32-33:
The addition ofgift_card_entity
andgift_card_content_entity
imports aligns with the PR's objective to introduce gift card management in the admin system.143-148:
The new service entity route for/gift-card
is correctly set up with appropriate permissions for the WEBSHOP role, which is consistent with the existing permission structure.150-155:
The related entity route for gift card products is correctly defined with anOrmSingeRelation
and the correct permission for the WEBSHOP role.
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- admin/src/Models/GiftCard.js (1 hunks)
- api/src/shop/models.py (2 hunks)
Files skipped from review as they are similar to previous changes (2)
- admin/src/Models/GiftCard.js
- api/src/shop/models.py
This PR adds an admin page for the gift cards with related entities etc. The view is similar to the one for transactions.
Summary by CodeRabbit
New Features
Enhancements
API & Database Updates
Bug Fixes