Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: remove alerts for archived queries #1118

Merged
merged 2 commits into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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