prevent readonly user from saving deployment sites
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index 5aeb784..5c52578 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -65,7 +65,6 @@
request.readonly = True
return super(ReadOnlyAwareAdmin, self).change_view(request, object_id, extra_context=extra_context)
-
def __user_is_readonly(self, request):
return request.user.isReadOnlyUser()
@@ -499,13 +498,17 @@
return deployment
+class DeploymentAdminROForm(DeploymentAdminForm):
+ def save(self, commit=True):
+ raise PermissionDenied
+
class SiteAssocInline(PlStackTabularInline):
model = Site.deployments.through
extra = 0
suit_classes = 'suit-tab suit-tab-sites'
class DeploymentAdmin(PlanetStackBaseAdmin):
- form = DeploymentAdminForm
+ #form = DeploymentAdminForm
model = Deployment
fieldList = ['name','sites']
fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-sites']})]
@@ -516,6 +519,13 @@
suit_form_tabs =(('sites','Deployment Details'),('nodes','Nodes'),('deploymentprivileges','Privileges'),('tags','Tags'))
+ def get_form(self, request, obj=None, **kwargs):
+ if request.user.isReadOnlyUser():
+ kwargs["form"] = DeploymentAdminROForm
+ else:
+ kwargs["form"] = DeploymentAdminForm
+ return super(DeploymentAdmin,self).get_form(request, obj, **kwargs)
+
class ServiceAttrAsTabROInline(ReadOnlyTabularInline):
model = ServiceAttribute
fields = ['name','value']