update SitePrivilegeAdmin and SliceMembershipAdmin
diff --git a/plstackapi/core/admin.py b/plstackapi/core/admin.py
index acf4c7d..e722b32 100644
--- a/plstackapi/core/admin.py
+++ b/plstackapi/core/admin.py
@@ -38,6 +38,18 @@
model = Site
extra = 0
+class SliceInline(admin.TabularInline):
+ model = Slice
+ extra = 0
+
+class UserInline(admin.TabularInline):
+ model = PLUser
+ extra = 0
+
+class RoleInline(admin.TabularInline):
+ model = Role
+ extra = 0
+
class NodeInline(admin.TabularInline):
model = Node
extra = 0
@@ -101,6 +113,12 @@
inlines = [NodeInline,]
search_fields = ['name']
+class SitePrivilegeAdmin(OSModelAdmin):
+ fieldsets = [
+ (None, {'fields': ['user', 'site', 'role']})
+ ]
+ list_display = ('user', 'site', 'role')
+
class KeyAdmin(OSModelAdmin):
fieldsets = [
('Key', {'fields': ['name', 'key', 'type', 'blacklisted', 'user']})
@@ -128,6 +146,13 @@
# users can only see slices at their site
return qs.filter(site=request.user.site)
+class SliceMembershipAdmin(OSModelAdmin):
+ fieldsets = [
+ (None, {'fields': ['user', 'slice', 'role']})
+ ]
+ list_display = ('user', 'slice', 'role')
+ inlines = [UserInline, SliceInline, RoleInline]
+
class SubnetAdmin(OSModelAdmin):
fields = ['cidr', 'ip_version', 'start', 'end', 'slice']
list_display = ('slice','cidr', 'start', 'end', 'ip_version')
@@ -261,9 +286,9 @@
admin.site.unregister(Group)
admin.site.register(Site, SiteAdmin)
-admin.site.register(SitePrivilege)
+admin.site.register(SitePrivilege, SitePrivilegeAdmin)
admin.site.register(Slice, SliceAdmin)
-admin.site.register(SliceMembership)
+admin.site.register(SliceMembership, SliceMembershipAdmin)
admin.site.register(Subnet, SubnetAdmin)
admin.site.register(Image, ImageAdmin)
admin.site.register(Node, NodeAdmin)
diff --git a/plstackapi/core/models/site.py b/plstackapi/core/models/site.py
index 67b3e52..ef7db95 100644
--- a/plstackapi/core/models/site.py
+++ b/plstackapi/core/models/site.py
@@ -50,4 +50,12 @@
def __unicode__(self): return u'%s %s %s' % (self.site, self.user, self.role)
+ def save(self, *args, **kwds):
+ self.driver.add_user_role(self.user.user_id, self.site.tenant_id, self.role.role_type)
+ super(SitePrivilege, self).save(*args, **kwds)
+
+ def delete(self, *args, **kwds):
+ self.driver.delete_user_role(self.user.user_id, self.site.tenant_id, self.role.role_type)
+ super(SitePrivilege, self).delete(*args, **kwds)
+
diff --git a/plstackapi/core/models/slice.py b/plstackapi/core/models/slice.py
index d174b2e..dda6553 100644
--- a/plstackapi/core/models/slice.py
+++ b/plstackapi/core/models/slice.py
@@ -56,3 +56,10 @@
def __unicode__(self): return u'%s %s %s' % (self.slice, self.user, self.role)
+ def save(self, *args, **kwds):
+ self.driver.add_user_role(self.user.user_id, self.slice.tenant_id, self.role.role_type)
+ super(SliceMembership, self).save(*args, **kwds)
+
+ def delete(self, *args, **kwds):
+ self.driver.delete_user_role(self.user.user_id, self.slice.tenant_id, self.role.role_type)
+ super(SliceMembership, self).delete(*args, **kwds)