forked from enviPath/enviPy
Add API key authentication to v1 API Also includes: - management command to create keys for users - Improvements to API tests Minor: - more robust way to start docker dev container. Reviewed-on: enviPath/enviPy#327 Co-authored-by: Tobias O <tobias.olenyi@envipath.com> Co-committed-by: Tobias O <tobias.olenyi@envipath.com>
33 lines
856 B
Python
33 lines
856 B
Python
from django.conf import settings as s
|
|
from ninja import Router
|
|
from ninja_extra.pagination import paginate
|
|
import logging
|
|
|
|
from ..auth import OptionalBearerTokenAuth
|
|
from ..dal import get_user_packages_for_read
|
|
from ..pagination import EnhancedPageNumberPagination
|
|
from ..schemas import PackageOutSchema, SelfReviewStatusFilter
|
|
|
|
router = Router()
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@router.get(
|
|
"/packages/",
|
|
response=EnhancedPageNumberPagination.Output[PackageOutSchema],
|
|
auth=OptionalBearerTokenAuth(),
|
|
)
|
|
@paginate(
|
|
EnhancedPageNumberPagination,
|
|
page_size=s.API_PAGINATION_DEFAULT_PAGE_SIZE,
|
|
filter_schema=SelfReviewStatusFilter,
|
|
)
|
|
def list_all_packages(request):
|
|
"""
|
|
List packages accessible to the user.
|
|
|
|
"""
|
|
user = request.user
|
|
qs = get_user_packages_for_read(user)
|
|
return qs.order_by("name").all()
|