Skip to content

Commit ecf9396

Browse files
author
Emmanouil Konstantinidis
committed
Hide Headers if "AllowAny" or "None"
1 parent 30e593e commit ecf9396

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

rest_framework_docs/api_endpoint.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self, pattern, parent_pattern=None):
1717
self.errors = None
1818
self.fields = self.__get_serializer_fields__()
1919
self.fields_json = self.__get_serializer_fields_json__()
20+
self.permissions = self.__get_permissions_class__()
2021

2122
def __get_path__(self, parent_pattern):
2223
if parent_pattern:
@@ -29,6 +30,10 @@ def __get_allowed_methods__(self):
2930
def __get_docstring__(self):
3031
return inspect.getdoc(self.callback)
3132

33+
def __get_permissions_class__(self):
34+
for perm_class in self.pattern.callback.cls.permission_classes:
35+
return perm_class.__name__
36+
3237
def __get_serializer_fields__(self):
3338
fields = []
3439

rest_framework_docs/static/rest_framework_docs/js/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ $( document ).ready(function() {
119119
});
120120
};
121121

122+
var _setupAuthorization = function (permissions) {
123+
124+
console.log(permissions);
125+
if (permissions === 'None' || permissions === 'AllowAny') {
126+
console.log('EMPTYYYY');
127+
$('#headers').empty();
128+
}
129+
};
130+
122131
var _setupFields = function (fields) {
123132
$.each( fields, function( i, field ) {
124133
var label = field.name.replace('_', ' ');
@@ -140,6 +149,7 @@ $( document ).ready(function() {
140149
$('#urlInput').val(data.path);
141150

142151
_setupMethods(data.methods);
152+
_setupAuthorization(data.permissions);
143153
_setupFields(data.fields);
144154

145155
$('#requestForm').submit(function (e) {

rest_framework_docs/templates/rest_framework_docs/home.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ <h4 class="panel-title title">
4545
data-toggle="modal"
4646
data-path="{{ endpoint.path }}"
4747
data-methods="{{ endpoint.allowed_methods }}"
48+
data-permissions="{{ endpoint.permissions }}"
4849
data-fields="{{ endpoint.fields_json }}">
4950
<i class="fa fa-plug"></i></li>
5051
</ul>
@@ -92,7 +93,7 @@ <h2 class="text-center">No endpoints found for {{ query }}.</h2>
9293
<div class="modal-content">
9394
<div class="modal-header">
9495
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
95-
<h4 class="modal-title">Live API Endpoints</h4>
96+
<h4 class="modal-title">Live API Endpoints <span class="label label-info">Beta</span></h4>
9697
</div>
9798
<div class="modal-body">
9899

@@ -110,11 +111,13 @@ <h3>Request</h3>
110111
<h5 class="section-title"><span>Method</span></h5>
111112
<div class="btn-group methods" id="methods" role="group"></div>
112113

113-
<h5 class="section-title"><span>Headers</span></h5>
114-
<div class="form-group">
115-
<label for="exampleInputPassword1" class="col-sm-4 control-label">Authorization</label>
116-
<div class="col-sm-8">
117-
<input type="text" class="form-control input-sm" id="exampleInputPassword1" placeholder="Token">
114+
<div id="headers">
115+
<h5 class="section-title"><span>Headers</span></h5>
116+
<div class="form-group">
117+
<label for="authorization" class="col-sm-4 control-label">Authorization</label>
118+
<div class="col-sm-8">
119+
<input type="text" class="form-control input-sm" id="authorization" placeholder="Token">
120+
</div>
118121
</div>
119122
</div>
120123

0 commit comments

Comments
 (0)