Skip to content

Commit

Permalink
Merge pull request #214 from coderbydesign/add-default-limit-to-access
Browse files Browse the repository at this point in the history
Set default limit on /access/ to max limit when no pagination limit supplied
  • Loading branch information
coderbydesign committed Feb 20, 2020
2 parents 566f0b4 + 42ff120 commit 489ee4d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 84 deletions.
83 changes: 3 additions & 80 deletions docs/source/specs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1521,34 +1521,19 @@
}
},
{
"$ref": "#/components/parameters/QueryLimitNoDefault"
"$ref": "#/components/parameters/QueryLimit"
},
{
"$ref": "#/components/parameters/QueryOffset"
}
],
"responses": {
"200": {
"description": "A list of access objects. By default, this request will not be paginated. To received a paginated response, include the `/?limit=` query parameter.",
"description": "A paginated list of access objects",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/AccessNoPagination"
},
{
"$ref": "#/components/schemas/AccessPagination"
}
]
},
"examples": {
"AccessNoPagination": {
"$ref": "#/components/examples/AccessNoPagination"
},
"AccessPagination": {
"$ref": "#/components/examples/AccessPagination"
}
"$ref": "#/components/schemas/AccessPagination"
}
}
}
Expand Down Expand Up @@ -1610,17 +1595,6 @@
"maximum": 1000
}
},
"QueryLimitNoDefault": {
"in": "query",
"name": "limit",
"required": false,
"description": "Parameter for selecting the amount of data returned.",
"schema": {
"type": "integer",
"minimum": 1,
"maximum": 1000
}
},
"NameFilter": {
"in": "query",
"name": "name",
Expand Down Expand Up @@ -2354,24 +2328,6 @@
}
]
},
"AccessNoPagination": {
"allOf": [
{
"type": "object",
"required": [
"data"
],
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Access"
}
}
}
}
]
},
"Status": {
"required": [
"api_version"
Expand Down Expand Up @@ -2423,39 +2379,6 @@
}
}
}
},
"examples": {
"AccessNoPagination": {
"value": {
"data": [
{
"permission": "app-name:*:*",
"resourceDefinitions": []
}
]
}
},
"AccessPagination": {
"value": {
"meta": {
"count": 1,
"limit": 10,
"offset": 0
},
"links": {
"first": "/access/?application=app-name&limit=10",
"next": null,
"previous": null,
"last": "/access/?application=app-name&limit=10"
},
"data": [
{
"permission": "app-name:*:*",
"resourceDefinitions": []
}
]
}
}
}
}
}
5 changes: 2 additions & 3 deletions rbac/management/access/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ def get(self, request):
def paginator(self):
"""Return the paginator instance associated with the view, or `None`."""
if not hasattr(self, '_paginator'):
self._paginator = self.pagination_class()
if self.pagination_class is None or 'limit' not in self.request.query_params:
self._paginator = None
else:
self._paginator = self.pagination_class()
self._paginator.default_limit = self._paginator.max_limit
return self._paginator

def paginate_queryset(self, queryset):
Expand Down
2 changes: 1 addition & 1 deletion tests/management/access/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_get_access_success(self):
self.assertIsNotNone(response.data.get('data'))
self.assertIsInstance(response.data.get('data'), list)
self.assertEqual(len(response.data.get('data')), 1)
self.assertIsNone(response.data.get('meta'))
self.assertEqual(response.data.get('meta').get('limit'), 1000)
self.assertEqual(self.access_data, response.data.get('data')[0])

def test_get_access_with_limit(self):
Expand Down

0 comments on commit 489ee4d

Please sign in to comment.