summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--horizon/horizon/tables/actions.py6
-rw-r--r--horizon/horizon/tables/base.py2
-rw-r--r--horizon/horizon/tests/table_tests.py17
3 files changed, 24 insertions, 1 deletions
diff --git a/horizon/horizon/tables/actions.py b/horizon/horizon/tables/actions.py
index 8b15b3865..38fccd62b 100644
--- a/horizon/horizon/tables/actions.py
+++ b/horizon/horizon/tables/actions.py
@@ -57,6 +57,12 @@ class BaseAction(object):
"""
return True
+ def _allowed(self, request, datum):
+ """ Default allowed checks for certain actions """
+ if isinstance(self, BatchAction) and not self.table.data:
+ return False
+ return self.allowed(request, datum)
+
def update(self, request, datum):
""" Allows per-action customization based on current conditions.
diff --git a/horizon/horizon/tables/base.py b/horizon/horizon/tables/base.py
index ba91f04fd..3e24a769d 100644
--- a/horizon/horizon/tables/base.py
+++ b/horizon/horizon/tables/base.py
@@ -665,7 +665,7 @@ class DataTable(object):
def _filter_action(self, action, request, datum=None):
try:
# Catch user errors in permission functions here
- return action.allowed(request, datum)
+ return action._allowed(request, datum)
except Exception:
LOG.exception("Error while checking action permissions.")
return None
diff --git a/horizon/horizon/tests/table_tests.py b/horizon/horizon/tests/table_tests.py
index 8784ffb5c..240ddb13b 100644
--- a/horizon/horizon/tests/table_tests.py
+++ b/horizon/horizon/tests/table_tests.py
@@ -475,6 +475,23 @@ class DataTableTests(test.TestCase):
self.assertEqual(list(req._messages)[0].message,
"Please select a row before taking that action.")
+ # At least one object in table
+ # BatchAction is available
+ req = self.factory.get('/my_url/')
+ self.table = MyTable(req, TEST_DATA_2)
+ self.assertQuerysetEqual(self.table.get_table_actions(),
+ ['<MyFilterAction: filter>',
+ '<MyAction: delete>',
+ '<MyBatchAction: batch>'])
+
+ # Zero objects in table
+ # BatchAction not available
+ req = self.factory.get('/my_url/')
+ self.table = MyTable(req, None)
+ self.assertQuerysetEqual(self.table.get_table_actions(),
+ ['<MyFilterAction: filter>',
+ '<MyAction: delete>'])
+
# Filtering
action_string = "my_table__filter__q"
req = self.factory.post('/my_url/', {action_string: '2'})