mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-26 18:38:38 -06:00
Convert secrets to use subqueries
This commit is contained in:
parent
ea5696e700
commit
c138712dd3
@ -1,7 +1,6 @@
|
||||
import base64
|
||||
|
||||
from Crypto.PublicKey import RSA
|
||||
from django.db.models import Count
|
||||
from django.http import HttpResponseBadRequest
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
@ -13,6 +12,7 @@ from secrets import filters
|
||||
from secrets.exceptions import InvalidKey
|
||||
from secrets.models import Secret, SecretRole, SessionKey, UserKey
|
||||
from utilities.api import ModelViewSet
|
||||
from utilities.utils import get_subquery
|
||||
from . import serializers
|
||||
|
||||
ERR_USERKEY_MISSING = "No UserKey found for the current user."
|
||||
@ -35,8 +35,8 @@ class SecretsRootView(APIRootView):
|
||||
|
||||
class SecretRoleViewSet(ModelViewSet):
|
||||
queryset = SecretRole.objects.annotate(
|
||||
secret_count=Count('secrets')
|
||||
).order_by(*SecretRole._meta.ordering)
|
||||
secret_count=get_subquery(Secret, 'role')
|
||||
)
|
||||
serializer_class = serializers.SecretRoleSerializer
|
||||
filterset_class = filters.SecretRoleFilterSet
|
||||
|
||||
|
@ -2,11 +2,11 @@ import base64
|
||||
import logging
|
||||
|
||||
from django.contrib import messages
|
||||
from django.db.models import Count
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from utilities.utils import get_subquery
|
||||
from utilities.views import (
|
||||
BulkDeleteView, BulkEditView, BulkImportView, ObjectView, ObjectDeleteView, ObjectEditView, ObjectListView,
|
||||
)
|
||||
@ -29,7 +29,9 @@ def get_session_key(request):
|
||||
#
|
||||
|
||||
class SecretRoleListView(ObjectListView):
|
||||
queryset = SecretRole.objects.annotate(secret_count=Count('secrets')).order_by(*SecretRole._meta.ordering)
|
||||
queryset = SecretRole.objects.annotate(
|
||||
secret_count=get_subquery(Secret, 'role')
|
||||
)
|
||||
table = tables.SecretRoleTable
|
||||
|
||||
|
||||
@ -49,7 +51,9 @@ class SecretRoleBulkImportView(BulkImportView):
|
||||
|
||||
|
||||
class SecretRoleBulkDeleteView(BulkDeleteView):
|
||||
queryset = SecretRole.objects.annotate(secret_count=Count('secrets')).order_by(*SecretRole._meta.ordering)
|
||||
queryset = SecretRole.objects.annotate(
|
||||
secret_count=get_subquery(Secret, 'role')
|
||||
)
|
||||
table = tables.SecretRoleTable
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user