Skip to content

Commit

Permalink
Merge pull request #1118 from getredash/feature/params_ui
Browse files Browse the repository at this point in the history
Fix: remove alerts for archived queries
  • Loading branch information
arikfr authored Jun 14, 2016
2 parents 4fabaae + da4db94 commit 3ce27b9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion rd_ui/app/views/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h4 class="modal-title">Query Archive</h4>
</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>
Expand Down
3 changes: 3 additions & 0 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@ def archive(self):
for w in vis.widgets:
w.delete_instance()

for alert in self.alerts:
alert.delete_instance(recursive=True)

self.save()

@classmethod
Expand Down
11 changes: 8 additions & 3 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ def create_alert(self, **kwargs):
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
Expand Down Expand Up @@ -274,6 +282,3 @@ def create_api_key(self, **kwargs):

def create_destination(self, **kwargs):
return destination_factory.create(**kwargs)

def create_alert_subscription(self, **kwargs):
return alert_subscription_factory.create(**kwargs)
10 changes: 10 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,16 @@ def test_removes_scheduling(self):

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': []}]
Expand Down

0 comments on commit 3ce27b9

Please sign in to comment.