remove dead code, update middleware

This commit is contained in:
wh1te909
2020-12-04 06:25:53 +00:00
parent 2f3c3361cf
commit 14bca52e8f
3 changed files with 5 additions and 24 deletions

View File

@@ -16,16 +16,15 @@ def get_debug_info():
EXCLUDE_PATHS = (
"/api/v3",
"/api/v2",
"/api/v1",
"/logs/auditlogs",
"/winupdate/winupdater",
"/winupdate/results",
f"/{settings.ADMIN_URL}",
"/logout",
"/agents/installagent",
"/logs/downloadlog",
)
ENDS_WITH = "/refreshedservices/"
class AuditMiddleware:
def __init__(self, get_response):
@@ -37,7 +36,9 @@ class AuditMiddleware:
return response
def process_view(self, request, view_func, view_args, view_kwargs):
if not request.path.startswith(EXCLUDE_PATHS):
if not request.path.startswith(EXCLUDE_PATHS) and not request.path.endswith(
ENDS_WITH
):
# https://stackoverflow.com/questions/26240832/django-and-middleware-which-uses-request-user-is-always-anonymous
try:
# DRF saves the class of the view function as the .cls property

View File

@@ -1,12 +1,9 @@
from django.urls import path
from . import views
from apiv3 import views as v3_views
urlpatterns = [
path("<int:pk>/getwinupdates/", views.get_win_updates),
path("<int:pk>/runupdatescan/", views.run_update_scan),
path("editpolicy/", views.edit_policy),
path("winupdater/", views.win_updater),
path("results/", v3_views.WinUpdater.as_view()),
path("<int:pk>/installnow/", views.install_updates),
]

View File

@@ -58,20 +58,3 @@ def edit_policy(request):
patch.action = request.data["policy"]
patch.save(update_fields=["action"])
return Response("ok")
@api_view()
@authentication_classes((TokenAuthentication,))
@permission_classes((IsAuthenticated,))
def win_updater(request):
agent = get_object_or_404(Agent, agent_id=request.data["agent_id"])
agent.delete_superseded_updates()
patches = (
WinUpdate.objects.filter(agent=agent)
.exclude(installed=True)
.filter(action="approve")
)
if patches:
return Response(ApprovedUpdateSerializer(patches, many=True).data)
return Response("nopatches")