URL: https://github.com/freeipa/freeipa/pull/2297
Author: serg-cymbaluk
 Title: #2297: [Backport][ipa-4-7] Fix js error on reset view
Action: opened

PR body:
"""
This PR was opened automatically because PR #2269 was pushed to master and 
backport to ipa-4-7 is required.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/2297/head:pr2297
git checkout pr2297
From 9fb12776a21f769fb6eb3e188da77dbca8a04c22 Mon Sep 17 00:00:00 2001
From: Stanislav Levin <s...@altlinux.org>
Date: Wed, 22 Aug 2018 22:36:24 +0300
Subject: [PATCH 1/2] Fix "get_key_index" to fit caller's expectations

The clients of "get_key_index" expect index of key in matching case
otherwise -1. But instead of this function returns the "undefined"
value.

Fixes: https://pagure.io/freeipa/issue/7678
---
 install/ui/src/libs/jquery.ordered-map.js | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/install/ui/src/libs/jquery.ordered-map.js b/install/ui/src/libs/jquery.ordered-map.js
index b25dc3379f..4d3be294ba 100644
--- a/install/ui/src/libs/jquery.ordered-map.js
+++ b/install/ui/src/libs/jquery.ordered-map.js
@@ -125,7 +125,11 @@ jQuery.ordered_map = jQuery.fn.ordered_map = function(map) {
     };
 
     that.get_key_index = function(key) {
-        return that._key_indicies[key];
+        var index = that._key_indicies[key];
+        if (index !== undefined) {
+            return index;
+        }
+        return -1;
     };
 
     that.get_key_by_index = function(index) {

From 1ad9b50d02b0969f535bfa103a6ebcdac9f60152 Mon Sep 17 00:00:00 2001
From: Stanislav Levin <s...@altlinux.org>
Date: Wed, 22 Aug 2018 22:47:04 +0300
Subject: [PATCH 2/2] Reindex 'key_indicies' after item delete

The "keys.splice(i, 1)" removes one item at the specified position
from an array. Thus hashes which are stored at "that._key_indicies"
are no longer valid and should be reindexed.

Fixes: https://pagure.io/freeipa/issue/7678
---
 install/ui/src/libs/jquery.ordered-map.js | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/install/ui/src/libs/jquery.ordered-map.js b/install/ui/src/libs/jquery.ordered-map.js
index 4d3be294ba..9b8b477d7d 100644
--- a/install/ui/src/libs/jquery.ordered-map.js
+++ b/install/ui/src/libs/jquery.ordered-map.js
@@ -112,6 +112,11 @@ jQuery.ordered_map = jQuery.fn.ordered_map = function(map) {
         that.keys.splice(i, 1);
         that.values.splice(i, 1);
         delete that._key_indicies[key];
+
+        // reindex
+        for (var j=i; j<that.keys.length; j++) {
+            that._key_indicies[that.keys[j]]=j;
+        }
         that.length = that.keys.length;
         return value;
     };
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org

Reply via email to