Permalink
Browse files

fixes bug 967555 - Add authentication for public API, r=rhelmer

  • Loading branch information...
peterbe committed Feb 20, 2014
1 parent 68ebf1d commit 53c6653b694d232cc99509e0dd7026e10e820bec
@@ -50,3 +50,10 @@ def make_test_input(parameter, defaults):
template += '>'
html = template % data
return jinja2.Markup(html)
+
+
+@register.filter
+def pluralize(count, multiple='s', single=''):
+ if count == 1:
+ return single
+ return multiple
@@ -41,3 +41,14 @@ img.loading-ajax {
.title h2 a {
text-decoration: none;
}
+p.required-permission {
+ float: right;
+ margin: 0;
+}
+p.tokens-callout {
+ float: right;
+ font-size: 120%;
+}
+p.tokens-callout a {
+ font-weight: bold;
+}
@@ -28,20 +28,29 @@ <h2>API Documentation</h2>
<div class="panel">
<div class="body notitle">
- <p>
- These API endpoints are publicly available. The parameters to some endpoints
- are non-trivial as some might require deeper understanding of the Soccoro backend.
- </p>
- <p>
- <b>Note:</b> All Personal Identifiable Information
- will be <b>removed or scrubbed</b> from all responses.
- </p>
+ <p class="tokens-callout">
+ You current have <a href="{{ url('tokens:home') }}">{{ count_tokens }} active API Token{{ count_tokens|pluralize }}</a>.
+ </p>
+ <p>
+ These API endpoints are publicly available. The parameters to some endpoints
+ are non-trivial as some might require deeper understanding of the Soccoro backend.
+ </p>
+ <p>
+ <b>Note:</b> The API does depend on <a href="{{ url('crashstats.permissions') }}">your permissions</a>
+ and if you include an <a href="{{ url('tokens:home') }}">API Token</a> with your requests.<br>
+ Some endpoints' accessibility depend entirely on your permissions and use of API Tokens.
+ </p>
</div>
</div>
{% for endpoint in endpoints %}
<div class="panel" id="{{ endpoint.name }}">
<div class="title">
+ {% if endpoint.required_permission %}
+ <p class="required-permission">
+ Only available if used with an <b>API Token</b> associated with <b>{{ endpoint.required_permission }}</b> permission.
+ </p>
+ {% endif %}
<h2><a href="#{{ endpoint.name }}">{{ endpoint.name }}</a></h2>
</div>
<div class="body">
@@ -0,0 +1,18 @@
+from nose.tools import eq_
+from django.test import TestCase
+
+
+from crashstats.api.helpers import (
+ pluralize
+)
+
+
+class TestPluralize(TestCase):
+
+ def test_basics(self):
+ eq_(pluralize(0), 's')
+ eq_(pluralize(1), '')
+ eq_(pluralize(59), 's')
+
+ def test_overide_s(self):
+ eq_(pluralize(59, 'ies'), 'ies')
Oops, something went wrong.

0 comments on commit 53c6653

Please sign in to comment.