From 459721198cd3b00d36a144586ceb19dbe735087d Mon Sep 17 00:00:00 2001 From: Julien ANNE Date: Tue, 1 Mar 2022 10:38:47 +0100 Subject: [PATCH] Authorize uuid for existing object in sortable table --- .../spree/backend/components/sortable_table.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/app/assets/javascripts/spree/backend/components/sortable_table.js b/backend/app/assets/javascripts/spree/backend/components/sortable_table.js index 436a67a8e07..322dd6e6c51 100644 --- a/backend/app/assets/javascripts/spree/backend/components/sortable_table.js +++ b/backend/app/assets/javascripts/spree/backend/components/sortable_table.js @@ -1,6 +1,14 @@ //= require solidus_admin/Sortable /* eslint no-unused-vars: "off" */ +/* Check if string is valid UUID */ +function isAValidUUID(str) { + // https://stackoverflow.com/a/13653180/8170555 + const regexExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + + return regexExp.test(str); +} + Spree.SortableTable = { refresh: function() { var sortable_tables = document.querySelectorAll('table.sortable'); @@ -16,7 +24,7 @@ Spree.SortableTable = { var idAttr = el.id; if (idAttr) { var objId = idAttr.split('_').slice(-1); - if (!isNaN(objId)) { + if (!isNaN(objId) || isAValidUUID(objId)) { positions['positions['+objId+']'] = index + 1; } }