Added columns to shared tool's restrictions dashboard
authorThierry Florac <thierry.florac@onf.fr>
Mon, 11 Sep 2017 14:50:14 +0200
changeset 136 5d1a29312100
parent 135 e85b629864ee
child 137 d17090a555a5
Added columns to shared tool's restrictions dashboard
src/pyams_content/shared/common/zmi/security.py
--- a/src/pyams_content/shared/common/zmi/security.py	Mon Sep 11 14:49:41 2017 +0200
+++ b/src/pyams_content/shared/common/zmi/security.py	Mon Sep 11 14:50:14 2017 +0200
@@ -104,6 +104,40 @@
     weight = 10
 
 
+@adapter_config(name='restricted', context=(ISharedTool, IAdminLayer, SharedToolManagersRestrictionsTable),
+                provides=IColumn)
+class SharedToolManagerRestrictionsEnabledColumn(I18nColumn, GetAttrColumn):
+    """Shared tool manager enabled restrictions column"""
+
+    _header = _("Restricted")
+    weight = 45
+    cssClasses = {'td': 'center'}
+
+    def getValue(self, obj):
+        restrictions = IManagerRestrictions(self.context).get_restrictions(obj)
+        if restrictions.restricted_contents:
+            return '<i class="fa fa-fw fa-check"></i>'
+        else:
+            return '--'
+
+
+@adapter_config(name='owners', context=(ISharedTool, IAdminLayer, SharedToolManagersRestrictionsTable),
+                provides=IColumn)
+class SharedToolManagerRestrictionsOwnersColumn(I18nColumn, GetAttrColumn):
+    """Shared tool manager owners restrictions column"""
+
+    _header = _("Owners")
+    weight = 50
+    cssClasses = {'td': 'center'}
+
+    def getValue(self, obj):
+        restrictions = IManagerRestrictions(self.context).get_restrictions(obj)
+        if restrictions.restricted_contents and restrictions.owners:
+            return '<i class="fa fa-fw fa-check"></i>'
+        else:
+            return '--'
+
+
 @pagelet_config(name='managers-restrictions.html', context=ISharedTool, layer=IPyAMSLayer,
                 permission=MANAGE_TOOL_PERMISSION)
 @implementer(IInnerPage)
@@ -195,3 +229,9 @@
              permission=MANAGE_TOOL_PERMISSION, renderer='json', xhr=True)
 class SharedToolManagerRestrictionsAJAXEditForm(AJAXEditForm, SharedToolManagerRestrictionsEditForm):
     """Shared tool manager restrictions edit form, JSON renderer"""
+
+    def get_ajax_output(self, changes):
+        if changes:
+            return {'status': 'reload'}
+        else:
+            return super(SharedToolManagerRestrictionsAJAXEditForm, self).get_ajax_output(changes)