fix users list not subtracted properly when displaying picker
diff --git a/planetstack/core/xoslib/dashboards/xosTenant.html b/planetstack/core/xoslib/dashboards/xosTenant.html
index ca74d5c..1287e15 100644
--- a/planetstack/core/xoslib/dashboards/xosTenant.html
+++ b/planetstack/core/xoslib/dashboards/xosTenant.html
@@ -42,11 +42,13 @@
<script type="text/template" id="tenant-edit-users">
<%= xosPickerTemplate({pickedItems: model.usersBuffer,
- unpickedItems: array_diff(xos.tenant().current_user_site_users, model.usersBuffer),
+ unpickedItems: array_subtract(xos.tenant().current_user_site_users, model.usersBuffer),
id: "users",
fieldName: "users",
detailView: detailView,
- lookupFunc: function(x) { return array_pair_lookup(x, xos.tenant().current_user_site_user_names, xos.tenant().current_user_site_users); },
+ lookupFunc: function(x) { return array_pair_lookup(x,
+ $.merge($.merge([], xos.tenant().current_user_site_user_names), model.user_namesOrig),
+ $.merge($.merge([], xos.tenant().current_user_site_users), model.usersOrig)); },
} ) %>
</script>
diff --git a/planetstack/core/xoslib/objects/sliceplus.py b/planetstack/core/xoslib/objects/sliceplus.py
index 4fdc824..9a70e25 100644
--- a/planetstack/core/xoslib/objects/sliceplus.py
+++ b/planetstack/core/xoslib/objects/sliceplus.py
@@ -57,6 +57,10 @@
def user_names(self):
return [user["name"] for user in self.getSliceInfo()["users"].values()]
+ @user_names.setter
+ def user_names(self, value):
+ pass # it's read-only
+
@property
def users(self):
return [user["id"] for user in self.getSliceInfo()["users"].values()]
diff --git a/planetstack/core/xoslib/static/js/xosTenant.js b/planetstack/core/xoslib/static/js/xosTenant.js
index 929552c..96465d3 100644
--- a/planetstack/core/xoslib/static/js/xosTenant.js
+++ b/planetstack/core/xoslib/static/js/xosTenant.js
@@ -264,6 +264,8 @@
tenantSites = new XOSTenantSiteCollection();
tenantSites.getFromSlice(model);
model.usersBuffer = model.attributes.users; /* save a copy of 'users' that we can edit. This prevents another view (developer) from overwriting our copy with a fetch from the server */
+ model.usersOrig = model.attributes.users; /* save an immutable copy that we'll use for username lookups */
+ model.user_namesOrig = model.attributes.user_names;
model.tenantSiteCollection = tenantSites;
XOSTenantApp.tenantSites = tenantSites;
diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-util.js b/planetstack/core/xoslib/static/js/xoslib/xos-util.js
index 7a57d8a..59fb06e 100644
--- a/planetstack/core/xoslib/static/js/xoslib/xos-util.js
+++ b/planetstack/core/xoslib/static/js/xoslib/xos-util.js
@@ -93,6 +93,18 @@
return diff;
}
+function array_subtract(a1, a2)
+{
+ result=[]
+ for (index in a1) {
+ value = a1[index];
+ if (!$.inArray(value, a2) >= 0) {
+ result.push(value);
+ }
+ }
+ return result;
+}
+
function array_pair_lookup(x, names, values)
{
for (index in values) {