Admin and User Metadata for transactional ressources and users (#5897)#6118
Admin and User Metadata for transactional ressources and users (#5897)#6118tvdeyen merged 8 commits intosolidusio:mainfrom
Conversation
6a23bc0 to
dc6114a
Compare
tvdeyen
left a comment
There was a problem hiding this comment.
Thanks. I like the feature. The only request I have is the coordination of commits in this PR. Tests should be included with the commit that makes the introduction/change. You could also add the tests first, make them pending and then implement commit by commit, removing the pending flag, but this is your decision.
|
@shahmayur001 it was discussed with Thomas to squash everything at the end. |
To be fully transparent I offered to squash merge this if @shahmayur001 is not able to rewrite the git history to our standards. |
403fa02 to
7131bae
Compare
e2d8324 to
192c365
Compare
This migration adds customer_metadata and admin_metadata to various tables
… and length
Introduced validations and configurable limits for metadata attributes
(`customer_metadata` and `admin_metadata`) to ensure consistency and prevent
overly large or complex structures.
**Implementation:**
- Set default values for `customer_metadata` and `admin_metadata` to empty hashes (`{}`) for proper initialization.
- Implemented validation to limit the number of keys, and the length of keys and values in metadata.
- Added configuration checks to ensure metadata does not exceed the limits defined in `Spree::Config`.
- Introduced preferences: `meta_data_max_keys`, `meta_data_max_key_length`, and `meta_data_max_value_length` to control metadata size:
- `meta_data_max_keys`: Max keys allowed (default: 6).
- `meta_data_max_key_length`: Max key length (default: 16).
- `meta_data_max_value_length`: Max value length (default: 256).
- Created a shared concern to handle metadata validation logic.
- Added tests to ensure default values and validation logic work correctly.
- Created a shared example that can be used in other specs to ensure consistent testing of metadata validation across various parts of the system.
Call the metadata concern to various models to validate and add admin and customer metadata
192c365 to
3286a68
Compare
b8ca440 to
b08d5ee
Compare
…tadata handling Update the API configuration to permit the `customer_metadata` attribute across various models, such as orders, payments, shipments, and return authorizations. This change allows better handling of customer metadata within API requests, ensuring consistent storage and validation of metadata attributes. Additionally, it updates the `preference` configurations for models to include `customer_metadata`. **Implementation:** - Added `customer_metadata` to the permitted attributes for several API resources. - Updated various `preference` settings, including `order_attributes`, `payment_attributes`, `shipment_attributes`, etc., to include `customer_metadata`. - Ensured that `customer_metadata` is correctly permitted in the API parameters for each relevant model, allowing admins and users to store custom metadata. - This change improves the flexibility of metadata management within the API, enabling dynamic handling and easier customizations.
User cannot update customer_metadata after the status of order is complete
Introduce the `admin_metadata` attribute to support dynamic metadata handling for admins. It enables configuration of metadata via API preferences, and ensures that metadata fields are properly permitted for admin users through new helper methods. **Implementation:** - Added `admin_metadata` to resources for admins. - Integrated `metadata_permit_parameters` and `metadata_api_parameters preference` in API configuration. - Implemented `permitted_<resource>_attributes` and `<method_name>_attributes` methods for dynamic metadata permissions. - Added `extract_metadata` in `line_items_controller` to handle metadata fields.
This configuration adds the ability to enable or disable metadata restrictions as needed. Following configurations are possible: - `meta_data_validation_enabled` : Enables or disables restrictions globally.
b08d5ee to
b954491
Compare
|
@tvdeyen this should be all, all comments are resolved, the failed tests are either related to
And are outside of the impact zone of this PR. |
|
@kennyadsl @tvdeyen Thank you so much for your guidance and support in helping us become more familiar with the Solidus community. As you know, we are completely new contributors, and we’ve likely made quite a few mistakes but we truly appreciate your patience. We’re actively learning from your feedback, taking notes, and doing our best to avoid repeating the same mistakes in the future. Your patience and insights are truly appreciated! |
tvdeyen
left a comment
There was a problem hiding this comment.
Thank you for your patience and the adjusting of your commits. This is very much appreciated
Closes #5897
Concerns #5951
Breaking Changes
This feature breaks sqlite versions predating to December 2023, verify your requirements before migrating.
Introduction
Overview
This PR introduces the concept of metadata fields to solidus. The purpose of metadata fields is to allow customers and admins alike to provide additional information to transactions to either extend the informations contained or allow to insert additional data to correlate transactions with third party systems.
Examples for data can be:
Possible Applications on a very high level are:
The current scope of meta data are following ressources:
How is the additional information stored?
for each of the above resources two columns have been created:
The resources store the information as jsonb.
What is the access model?
Cancancan has been used to allow users to write data with the current scope just extended by the additional fields:
Testing
Extensive test cases have been added.
Detailed Overview
Types of Meta Data and usage suggestions
Overview
Meta data can be broken down in three large topics visible in the table below:
Administrative Metadata
Transactional resources are either by nature integrated with 3rd party systems (eg Payments, Billing in Italy with eInvoicing) or by operational requirement (ERP, CRMs like Salesforce,...). Meta data as an extension on admin site for all transactional resources to connect the transactional resources to any of such systems. Given that more and more countries will switch to a form of eInvoicing in the coming years meta data allows to fetch or store additional information in those transactions.
Customer Meta Data
Customer meta data allows users to customize a cart with either administrative (PO numbers,...) or customisation information (eg an URL to a picture to customize a shirt, text strings for incisions or in our case IMEIs to relate to a subscription) allowing to significantly extend the features without changing the underlying model. Fields should be accessible on front-end and backend.
Schema
Meta Data should net a reliable outcome:
"key1" : "value1" should be as applicable as "key2" : "value2", without restriction other than the quantity of storable key value pairs and limitations of the dimension of the value given that json as a format does not pose limits we should do that server side.
Future models to reserve or block certain key names might be possible.
Scopes & Arrays
Nature of the Values
The system is agnostic to the value contained. A decision has been made to store the data in additional columns in a jsonb which by now is relatively widely supported. Some preexisting installations might have to upgrade DBs, older sqlite versions dating before Jan 2024 are therefor not supported and need to be updated.
"key1" : "value1" should lead to the same behaviour as "key2" : "value2" without requiring modification inside the code. Reasonable provisions should be taken inside the code base to edit the quantities and content size of key value pairs and appropriate errors should be returned where rate or size limits are exceeded.
Administrative Meta Data
Allow appropriate roles to customize resources with private fields not end-user accessible.
R/W = Read and Write Access
Customer Meta Data
Allowing users to customize an incomplete order (or I'd say a cart) and call the information after a completed order. Admins should in an ideal case be allowed to edit those information after purchase, but I feel that can wait if technical limitations are currently in place.