Remove allowed keys list for adding woocommerce_meta data (https://github.com/woocommerce/woocommerce-admin/pull/6889)

* introduce filter for wc meta preferences

* package changelog

* added PR number

* Remove allow list for woocommerce_meta keys

* Remove hooks dep

* Lint js fixes

* Update readme.txt

* Update readme.txt

* Fix test.

Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com>
This commit is contained in:
Christos Lilitsas 2021-04-29 01:18:29 +03:00 committed by GitHub
parent 060f52d938
commit 1edb849c67
4 changed files with 9 additions and 37 deletions

View File

@ -1,6 +1,7 @@
# Unreleased # Unreleased
- Fix parsing bad JSON string data in useUserPreferences hook. #6819 - Fix parsing bad JSON string data in useUserPreferences hook. #6819
- Removed allowed keys list for adding woocommerce_meta data. #6889
# 1.2.0 # 1.2.0

View File

@ -140,14 +140,11 @@ describe( 'useUserPreferences() hook', () => {
'function' 'function'
); );
const updateResult = await result.current.updateUserPreferences( { // Passing an array, not an object.
banana: 'is not a valid meta key', const updateResult = await result.current.updateUserPreferences( [] );
} );
expect( updateResult ).toMatchObject( { expect( updateResult ).toMatchObject( {
error: new Error( error: new Error( 'Invalid woocommerce_meta data for update.' ),
'No valid woocommerce_meta keys were provided for update.'
),
updatedUser: undefined, updatedUser: undefined,
} ); } );
} ); } );

View File

@ -1,7 +1,7 @@
/** /**
* External dependencies * External dependencies
*/ */
import { mapValues, pick } from 'lodash'; import { mapValues } from 'lodash';
import { useDispatch, useSelect } from '@wordpress/data'; import { useDispatch, useSelect } from '@wordpress/data';
/** /**
@ -48,39 +48,12 @@ async function updateUserPrefs(
) { ) {
// @todo Handle unresolved getCurrentUser() here. // @todo Handle unresolved getCurrentUser() here.
// Whitelist our meta fields. // Prep fields for update.
const userDataFields = [ const metaData = mapValues( userPrefs, JSON.stringify );
'categories_report_columns',
'coupons_report_columns',
'customers_report_columns',
'orders_report_columns',
'products_report_columns',
'revenue_report_columns',
'taxes_report_columns',
'variations_report_columns',
'dashboard_sections',
'dashboard_chart_type',
'dashboard_chart_interval',
'dashboard_leaderboard_rows',
'activity_panel_inbox_last_read',
'homepage_layout',
'homepage_stats',
'android_app_banner_dismissed',
'task_list_tracked_started_tasks',
'help_panel_highlight_shown',
];
// Prep valid fields for update.
const metaData = mapValues(
pick( userPrefs, userDataFields ),
JSON.stringify
);
if ( Object.keys( metaData ).length === 0 ) { if ( Object.keys( metaData ).length === 0 ) {
return { return {
error: new Error( error: new Error( 'Invalid woocommerce_meta data for update.' ),
'No valid woocommerce_meta keys were provided for update.'
),
updatedUser: undefined, updatedUser: undefined,
}; };
} }

View File

@ -87,6 +87,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
- Dev: Use rule processing for remote payment methods #6830 - Dev: Use rule processing for remote payment methods #6830
- Dev: Update E2E jest config, so it correctly creates screenshots on failure. #6858 - Dev: Update E2E jest config, so it correctly creates screenshots on failure. #6858
- Dev: Fixed storybook build script #6875 - Dev: Fixed storybook build script #6875
- Dev: Removed allowed keys list for adding woocommerce_meta data. #6889 🎉 @xristos3490
- Feature: Add recommended payment methods in payment settings. #6760 - Feature: Add recommended payment methods in payment settings. #6760
- Fix: Disable the continue btn on OBW when requested are being made #6838 - Fix: Disable the continue btn on OBW when requested are being made #6838
- Fix: Event tracking for merchant email notes #6616 - Fix: Event tracking for merchant email notes #6616