Changed the message level for deleting some resources to info

Added functionality to the handle function in the BatchAction class
in action.py and allowed the easy changing between the alert types
and made deleting images, instances, and volumes give an info alert
rather than a success message and altered the testing parameters

Change-Id: I93251d6d12cf89a331b5c051bf4fe10a6e470f51
Closes-Bug: #1291681
This commit is contained in:
Simon Collins 2018-01-17 15:08:34 +13:00 committed by Adrian Turjak
parent 07070c437d
commit 2a3b04ce6c
5 changed files with 6 additions and 3 deletions

View File

@ -657,6 +657,7 @@ class BatchAction(Action):
"""
help_text = _("This action cannot be undone.")
default_message_level = "success"
def __init__(self, **kwargs):
super(BatchAction, self).__init__(**kwargs)
@ -798,8 +799,7 @@ class BatchAction(Action):
'Action %(action)s Failed for %(reason)s', {
'action': action_description, 'reason': ex})
# Begin with success message class, downgrade to info if problems.
success_message_level = messages.success
success_message_level = getattr(messages, self.default_message_level)
if action_not_allowed:
msg = _('You are not allowed to %(action)s: %(objs)s')
params = {"action":

View File

@ -85,6 +85,7 @@ class DeleteImage(tables.DeleteAction):
# NOTE: The bp/add-batchactions-help-text
# will add appropriate help text to some batch/delete actions.
help_text = _("Deleted images are not recoverable.")
default_message_level = "info"
@staticmethod
def action_present(count):

View File

@ -83,6 +83,7 @@ def is_deleting(instance):
class DeleteInstance(policy.PolicyTargetMixin, tables.DeleteAction):
policy_rules = (("compute", "os_compute_api:servers:delete"),)
help_text = _("Deleted instances are not recoverable.")
default_message_level = "info"
@staticmethod
def action_present(count):

View File

@ -4958,7 +4958,7 @@ class InstanceTests2(InstanceTestBase, InstanceTableTestMixin):
res = self.client.post(next_page_url, formData)
self.assertRedirectsNoFollow(res, next_page_url)
self.assertMessageCount(success=1)
self.assertMessageCount(info=1)
search_opts = {'marker': servers[page_size - 1].id, 'paginate': True}
self.mock_server_list.assert_called_once_with(

View File

@ -92,6 +92,7 @@ class LaunchVolumeNG(LaunchVolume):
class DeleteVolume(VolumePolicyTargetMixin, tables.DeleteAction):
help_text = _("Deleted volumes are not recoverable. "
"All data stored in the volume will be removed.")
default_message_level = "info"
@staticmethod
def action_present(count):