From 15506e3db395b079ccb355d5a6ded799d71ff634 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Tue, 5 Jan 2016 00:04:40 +0100 Subject: [PATCH] KEYCLOAK-2256 - Guarantee deterministic ordering for custom user attributes in admin console. We now iterate over custom-user attributes in a deterministic way such that new attributes don't lead to a complete reordering of the properties in the custom user attributes listings. Previously the order of custom attributes in the user attributes listings was not deterministic which lead to cases where keys that shared a common prefix where not placed at arbitrary positions. Introduced a custom angularjs flter "toOrderedMapSortedByKey" that helps to deterministically iterate over object properites. --- .../theme/base/admin/resources/js/app.js | 28 +++++++++++++++++++ .../resources/partials/user-attributes.html | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/forms/common-themes/src/main/resources/theme/base/admin/resources/js/app.js b/forms/common-themes/src/main/resources/theme/base/admin/resources/js/app.js index e5e1bb919b..65693881f9 100755 --- a/forms/common-themes/src/main/resources/theme/base/admin/resources/js/app.js +++ b/forms/common-themes/src/main/resources/theme/base/admin/resources/js/app.js @@ -2372,6 +2372,34 @@ module.filter('capitalize', function() { }; }); +/* + * Guarantees a deterministic property iteration order. + * See: http://www.2ality.com/2015/10/property-traversal-order-es6.html + */ +module.filter('toOrderedMapSortedByKey', function(){ + return function(input){ + + if(!input){ + return input; + } + + var keys = Object.keys(input); + + if(keys.length <= 1){ + return input; + } + + keys.sort(); + + var result = {}; + for (var i = 0; i < keys.length; i++) { + result[keys[i]] = input[keys[i]]; + } + + return result; + }; +}); + module.directive('kcSidebarResize', function ($window) { return function (scope, element) { function resize() { diff --git a/forms/common-themes/src/main/resources/theme/base/admin/resources/partials/user-attributes.html b/forms/common-themes/src/main/resources/theme/base/admin/resources/partials/user-attributes.html index df969fb1ca..31dde8a775 100755 --- a/forms/common-themes/src/main/resources/theme/base/admin/resources/partials/user-attributes.html +++ b/forms/common-themes/src/main/resources/theme/base/admin/resources/partials/user-attributes.html @@ -16,7 +16,7 @@ - + {{key}}