Merge pull request #1118 from getredash/feature/params_ui

Fix: remove alerts for archived queries
This commit is contained in:
Arik Fraimovich
2016-06-14 11:15:50 +03:00
committed by GitHub
4 changed files with 22 additions and 4 deletions

View File

@@ -8,7 +8,7 @@
</div>
<div class="modal-body">
Are you sure you want to archive this query?
<br/> All dashboard widgets created with its visualizations will be deleted.
<br/> All alerts and dashboard widgets created with its visualizations will be deleted.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>

View File

@@ -641,6 +641,9 @@ class Query(ModelTimestampsMixin, BaseModel, BelongsToOrgMixin):
for w in vis.widgets:
w.delete_instance()
for alert in self.alerts:
alert.delete_instance(recursive=True)
self.save()
@classmethod

View File

@@ -185,6 +185,14 @@ class Factory(object):
args.update(**kwargs)
return alert_factory.create(**args)
def create_alert_subscription(self, **kwargs):
args = {
'user': self.user
}
args.update(**kwargs)
return alert_subscription_factory.create(**args)
def create_data_source(self, **kwargs):
args = {
'org': self.org
@@ -274,6 +282,3 @@ class Factory(object):
def create_destination(self, **kwargs):
return destination_factory.create(**kwargs)
def create_alert_subscription(self, **kwargs):
return alert_subscription_factory.create(**kwargs)

View File

@@ -276,6 +276,16 @@ class QueryArchiveTest(BaseTestCase):
self.assertEqual(None, query.schedule)
def test_deletes_alerts(self):
subscription = self.factory.create_alert_subscription()
query = subscription.alert.query
query.archive()
self.assertRaises(models.Alert.DoesNotExist, models.Alert.get_by_id, subscription.alert.id)
self.assertRaises(models.AlertSubscription.DoesNotExist, models.AlertSubscription.get_by_id, subscription.id)
class DataSourceTest(BaseTestCase):
def test_get_schema(self):
return_value = [{'name': 'table', 'columns': []}]