save users supported in tenant view
diff --git a/planetstack/core/xoslib/dashboards/xosTenant.html b/planetstack/core/xoslib/dashboards/xosTenant.html
index 01b354c..4ccf10c 100644
--- a/planetstack/core/xoslib/dashboards/xosTenant.html
+++ b/planetstack/core/xoslib/dashboards/xosTenant.html
@@ -41,8 +41,8 @@
</script>
<script type="text/template" id="tenant-edit-users">
- <%= xosPickerTemplate({pickedItems: model.attributes.users,
- unpickedItems: array_diff(xos.tenant().current_user_site_users, model.attributes.users),
+ <%= xosPickerTemplate({pickedItems: model.usersBuffer,
+ unpickedItems: array_diff(xos.tenant().current_user_site_users, model.usersBuffer),
id: "users",
fieldName: "users",
detailView: detailView,
diff --git a/planetstack/core/xoslib/objects/sliceplus.py b/planetstack/core/xoslib/objects/sliceplus.py
index bbab060..73017ee 100644
--- a/planetstack/core/xoslib/objects/sliceplus.py
+++ b/planetstack/core/xoslib/objects/sliceplus.py
@@ -1,4 +1,4 @@
-from core.models import Slice, SlicePrivilege, Sliver, Site, Node
+from core.models import Slice, SlicePrivilege, SliceRole, Sliver, Site, Node, User
from plus import PlusObjectMixin
from operator import itemgetter, attrgetter
@@ -80,7 +80,7 @@
qs = SlicePlus.objects.filter(id__in=slice_ids)
return qs
- def get_site_node_allocation(self, siteList):
+ def get_node_allocation(self, siteList):
siteIDList = [site.id for site in siteList]
nodeList = []
for node in Node.objects.all():
@@ -97,12 +97,20 @@
if self._update_site_allocation:
self.save_site_allocation(noAct=True)
+
+ if self._update_users:
+ self.save_users(noAct=True)
+
+ if self._update_site_allocation:
self.save_site_allocation()
+ if self._update_users:
+ self.save_users()
+
def save_site_allocation(self, noAct = False):
new_site_allocation = self._update_site_allocation
- all_slice_slivers = self.slivers.all() # Sliver.objects.filter(slice=self)
+ all_slice_slivers = self.slivers.all()
for site_name in new_site_allocation.keys():
desired_allocation = new_site_allocation[site_name]
@@ -122,7 +130,7 @@
# add more slivers
if (len(slivers) < desired_allocation):
site = Site.objects.get(name = site_name)
- nodes = self.get_site_node_allocation([site])
+ nodes = self.get_node_allocation([site])
if (not nodes):
raise ValueError("no nodes in site %s" % site_name)
@@ -147,4 +155,35 @@
node.sliverCount = node.sliverCount + 1
+ def save_users(self, noAct = False):
+ new_users = self._update_users
+
+ default_role = SliceRole.objects.get(role="default")
+
+ slice_privs = self.sliceprivileges.all()
+ slice_user_ids = [priv.user.id for priv in slice_privs]
+
+ for user_id in new_users:
+ if (user_id not in slice_user_ids):
+ print "XXX", user_id
+ priv = SlicePrivilege(slice=self, user=User.objects.get(id=user_id), role=default_role)
+ if (not noAct):
+ priv.save()
+
+ print "added user id", user_id
+
+ for priv in slice_privs:
+ if (priv.role.id != default_role.id):
+ # only mess with 'default' users; don't kill an admin
+ continue
+
+ if (priv.user.id not in new_users):
+ if (not noAct):
+ priv.delete()
+
+ print "deleted user id", user_id
+
+
+
+
diff --git a/planetstack/core/xoslib/static/js/xosTenant.js b/planetstack/core/xoslib/static/js/xosTenant.js
index 4c70f70..48ac835 100644
--- a/planetstack/core/xoslib/static/js/xosTenant.js
+++ b/planetstack/core/xoslib/static/js/xosTenant.js
@@ -30,7 +30,7 @@
putToSlice: function(slice) {
slice.attributes.site_allocation = {};
for (index in this.models) {
- model = this.models[index];
+ var model = this.models[index];
slice.attributes.site_allocation[ model.attributes.name ] = model.attributes.allocated;
}
},
@@ -75,6 +75,7 @@
saveClicked: function(e) {
model = this.options.linkedView.model;
model.tenantSiteCollection.putToSlice(model);
+ model.attributes.users = model.usersBuffer;
this.options.linkedView.submitContinueClicked.call(this.options.linkedView, e);
},
});
@@ -181,7 +182,7 @@
modal: true,
width: 640,
buttons : {
- "Save" : function() {
+ "Create Slice" : function() {
var addDialog = this;
console.log("SAVE!!!");
detailView.synchronous = true;
@@ -206,11 +207,11 @@
modal: true,
width: 640,
buttons : {
- "Save" : function() {
+ "Ok" : function() {
var editDialog = this;
user_ids = all_options($("#tenant-edit-users-dialog").find(".select-picker-to"));
user_ids = user_ids.map( function(x) { return parseInt(x,10); } );
- model.attributes.users = user_ids;
+ model.usersBuffer = user_ids;
$(editDialog).dialog("close");
},
"Cancel" : function() {
@@ -248,6 +249,7 @@
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.tenantSiteCollection = tenantSites;
XOSTenantApp.tenantSites = tenantSites;