Skip to content

Commit

Permalink
fixes bug 1208172 - swap supersearch-custom-query waffle flag to nega…
Browse files Browse the repository at this point in the history
…tive
  • Loading branch information
peterbe committed Sep 25, 2015
1 parent ecfc2a0 commit f0a6bae
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
11 changes: 9 additions & 2 deletions docs/development/elasticsearch.rst
Expand Up @@ -163,11 +163,18 @@ Here is a list of the switches you need to turn on to use each feature:
+-----------------------+-----------------------------------------------------+
| Feature | Switches |
+=======================+=====================================================+
| Custom Queries | supersearch-custom-query |
+-----------------------+-----------------------------------------------------+
| Signature report | signature-report |
+-----------------------+-----------------------------------------------------+

Here are features that are enabled by default, that you need to switch
if you want to *disable* them:

+-----------------------+-----------------------------------------------------+
| Feature | Switches |
+=======================+=====================================================+
| Custom Queries | supersearch-custom-query-disabled |
+-----------------------+-----------------------------------------------------+

Validate your configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Expand Up @@ -24,7 +24,7 @@
<h2>Super Search</h2>
<ul class="options">
<li><a href="{{ url('supersearch.search') }}" class="selected">Search by fields</a></li>
{% if waffle.switch('supersearch-custom-query') and request.user.has_perm('crashstats.run_custom_queries') %}
{% if not waffle.switch('supersearch-custom-query-disabled') and request.user.has_perm('crashstats.run_custom_queries') %}
<li><a href="{{ url('supersearch.search_custom') }}">Custom query</a></li>
{% endif %}
</ul>
Expand Down Expand Up @@ -75,7 +75,7 @@ <h2>Super Search</h2>

<!-- Advanced search UI -->
<div id="advanced-search">
{% if waffle.switch('supersearch-custom-query') and request.user.has_perm('crashstats.run_custom_queries') %}
{% if not waffle.switch('supersearch-custom-query-disabled') and request.user.has_perm('crashstats.run_custom_queries') %}
<button class="customize">Customize</button>
{% endif %}
<button class="new-line">New line</button>
Expand Down
45 changes: 23 additions & 22 deletions webapp-django/crashstats/supersearch/tests/test_views.py
Expand Up @@ -20,34 +20,35 @@

class TestViews(BaseTestViews):

@classmethod
def setUpClass(cls):
super(cls, TestViews).setUpClass()
TestViews.custom_switch = Switch.objects.create(
name='supersearch-custom-query',
active=True,
)
def test_search_waffle_switch(self):
url_custom = reverse('supersearch.search_custom')
url_query = reverse('supersearch.search_query')

@classmethod
def tearDownClass(cls):
TestViews.custom_switch.delete()
super(cls, TestViews).tearDownClass()
response = self.client.get(url_custom)
# By default, it's available, but it redirects because
# you're not signed in.
eq_(response.status_code, 302)
response = self.client.get(url_query)
eq_(response.status_code, 302)

def test_search_waffle_switch(self):
# Deactivate the switch to verify it's not accessible.
TestViews.custom_switch.active = False
TestViews.custom_switch.save()
# disable it
switch = Switch.objects.create(
name='supersearch-custom-query-disabled',
active=True
)

url = reverse('supersearch.search_custom')
response = self.client.get(url)
response = self.client.get(url_custom)
eq_(response.status_code, 404)

url = reverse('supersearch.search_query')
response = self.client.get(url)
response = self.client.get(url_query)
eq_(response.status_code, 404)

TestViews.custom_switch.active = True
TestViews.custom_switch.save()
# leave it but disable the disabling switch
switch.active = False
switch.save()
response = self.client.get(url_custom)
eq_(response.status_code, 302)
response = self.client.get(url_query)
eq_(response.status_code, 302)

def test_search(self):
self._login()
Expand Down
4 changes: 2 additions & 2 deletions webapp-django/crashstats/supersearch/views.py
Expand Up @@ -340,7 +340,7 @@ def to_hours(delta):
return params


@waffle_switch('supersearch-custom-query')
@waffle_switch('!supersearch-custom-query-disabled')
@permission_required('crashstats.run_custom_queries')
@pass_default_context
def search_custom(request, default_context=None):
Expand Down Expand Up @@ -381,7 +381,7 @@ def search_custom(request, default_context=None):
return render(request, 'supersearch/search_custom.html', context)


@waffle_switch('supersearch-custom-query')
@waffle_switch('!supersearch-custom-query-disabled')
@permission_required('crashstats.run_custom_queries')
@require_POST
@utils.json_view
Expand Down

0 comments on commit f0a6bae

Please sign in to comment.