Skip to content

Commit dd89bd8

Browse files
author
Omer Lachish
authored
Add "deprecated" flag to query runners (and alert destinations) (getredash#3972)
* add a deprecated flag to query runners and show only non-deprecated query runners when adding a new data source * add a deprecated flag to alert destinations and show only non-deprecated alert destinations when adding a new alert destination * add a deprecated() decorator for a more succint way to deprecate * deprecate URL query runner and HipChat alert destination * use class properties instead of class methods for deprecation * I <3 newlines
1 parent b229519 commit dd89bd8

File tree

9 files changed

+41
-3
lines changed

9 files changed

+41
-3
lines changed

redash/destinations/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212

1313
class BaseDestination(object):
14+
deprecated = False
15+
1416
def __init__(self, configuration):
1517
self.configuration = configuration
1618

redash/destinations/hipchat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from redash.destinations import *
55
from redash.models import Alert
6-
from redash.utils import json_dumps
6+
from redash.utils import json_dumps, deprecated
77

88

99
colors = {
@@ -13,6 +13,7 @@
1313
}
1414

1515

16+
@deprecated()
1617
class HipChat(BaseDestination):
1718
@classmethod
1819
def configuration_schema(cls):

redash/handlers/data_sources.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
class DataSourceTypeListResource(BaseResource):
2020
@require_admin
2121
def get(self):
22-
return [q.to_dict() for q in sorted(query_runners.values(), key=lambda q: q.name())]
22+
available_query_runners = filter(lambda q: not q.deprecated, query_runners.values())
23+
return [q.to_dict() for q in sorted(available_query_runners, key=lambda q: q.name())]
2324

2425

2526
class DataSourceResource(BaseResource):

redash/handlers/destinations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
class DestinationTypeListResource(BaseResource):
1414
@require_admin
1515
def get(self):
16-
return [q.to_dict() for q in destinations.values()]
16+
available_destinations = filter(lambda q: not q.deprecated, destinations.values())
17+
return [q.to_dict() for q in available_destinations]
1718

1819

1920
class DestinationResource(BaseResource):

redash/query_runner/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class NotSupported(Exception):
5353

5454

5555
class BaseQueryRunner(object):
56+
deprecated = False
5657
noop_query = None
5758

5859
def __init__(self, configuration):

redash/query_runner/url.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from redash.query_runner import BaseHTTPQueryRunner, register
2+
from redash.utils import deprecated
23

34

5+
@deprecated()
46
class Url(BaseHTTPQueryRunner):
57
requires_url = False
68

redash/utils/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,11 @@ def to_filename(s):
192192
s = re.sub('[<>:"\\\/|?*]+', " ", s, flags=re.UNICODE)
193193
s = re.sub("\s+", "_", s, flags=re.UNICODE)
194194
return s.strip("_")
195+
196+
197+
def deprecated():
198+
def wrapper(K):
199+
setattr(K, 'deprecated', True)
200+
return K
201+
202+
return wrapper

tests/handlers/test_data_sources.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from funcy import pairwise
22
from tests import BaseTestCase
3+
from mock import patch
34

45
from redash.models import DataSource
6+
from redash.query_runner.pg import PostgreSQL
57

68

79
class TestDataSourceGetSchema(BaseTestCase):
@@ -38,6 +40,14 @@ def test_returns_data_for_admin(self):
3840
rv = self.make_request('get', "/api/data_sources/types", user=admin)
3941
self.assertEqual(rv.status_code, 200)
4042

43+
def test_does_not_show_deprecated_types(self):
44+
admin = self.factory.create_admin()
45+
with patch.object(PostgreSQL, 'deprecated', return_value=True):
46+
rv = self.make_request('get', "/api/data_sources/types", user=admin)
47+
48+
types = map(lambda x: x['type'], rv.json)
49+
self.assertNotIn('pg', types)
50+
4151
def test_returns_403_for_non_admin(self):
4252
rv = self.make_request('get', "/api/data_sources/types")
4353
self.assertEqual(rv.status_code, 403)

tests/handlers/test_destinations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from tests import BaseTestCase
2+
from mock import patch
23

34
from redash.models import NotificationDestination
5+
from redash.destinations.slack import Slack
46

57

68
class TestDestinationListResource(BaseTestCase):
@@ -78,3 +80,13 @@ def test_post(self):
7880
d = NotificationDestination.query.get(d.id)
7981
self.assertEqual(d.name, data['name'])
8082
self.assertEqual(d.options['url'], data['options']['url'])
83+
84+
85+
class DestinationTypesTest(BaseTestCase):
86+
def test_does_not_show_deprecated_types(self):
87+
admin = self.factory.create_admin()
88+
with patch.object(Slack, 'deprecated', return_value=True):
89+
rv = self.make_request('get', "/api/destinations/types", user=admin)
90+
91+
types = map(lambda x: x['type'], rv.json)
92+
self.assertNotIn('slack', types)

0 commit comments

Comments
 (0)