From 364cf362f4f58b4a372463b184e735d522ef3988 Mon Sep 17 00:00:00 2001 From: wh1te909 <7434746+wh1te909@users.noreply.github.com> Date: Fri, 21 Jun 2024 00:58:10 +0000 Subject: [PATCH] blacked --- api/tacticalrmm/core/views.py | 15 +++++++-------- api/tacticalrmm/logs/models.py | 10 +++++----- api/tacticalrmm/scripts/views.py | 6 +++--- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/api/tacticalrmm/core/views.py b/api/tacticalrmm/core/views.py index 67080617..2171bd48 100644 --- a/api/tacticalrmm/core/views.py +++ b/api/tacticalrmm/core/views.py @@ -11,22 +11,23 @@ from django.shortcuts import get_object_or_404 from django.utils import timezone as djangotime from django.views.decorators.csrf import csrf_exempt from redis import from_url +from rest_framework import serializers +from rest_framework import status as drf_status from rest_framework.decorators import api_view, permission_classes from rest_framework.exceptions import PermissionDenied from rest_framework.permissions import AllowAny, IsAuthenticated from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView -from rest_framework import serializers, status as drf_status from core.decorators import monitoring_view from core.tasks import sync_mesh_perms_task from core.utils import ( get_core_settings, - sysd_svc_is_running, - token_is_valid, run_server_script, run_test_url_rest_action, + sysd_svc_is_running, + token_is_valid, ) from logs.models import AuditLog from tacticalrmm.constants import AuditActionType, PAStatus @@ -38,14 +39,13 @@ from tacticalrmm.permissions import ( ) from .models import CodeSignToken, CoreSettings, CustomField, GlobalKVStore, URLAction - from .permissions import ( CodeSignPerms, CoreSettingsPerms, CustomFieldPerms, + RunServerScriptPerms, ServerMaintPerms, URLActionPerms, - RunServerScriptPerms, WebTerminalPerms, ) from .serializers import ( @@ -383,7 +383,7 @@ class RunURLAction(APIView): from agents.models import Agent from clients.models import Client, Site - from tacticalrmm.utils import get_db_value, RE_DB_VALUE + from tacticalrmm.utils import RE_DB_VALUE, get_db_value if "agent_id" in request.data.keys(): if not _has_perm_on_agent(request.user, request.data["agent_id"]): @@ -456,7 +456,7 @@ class RunTestURLAction(APIView): elif instance_type == "site": if not _has_perm_on_site(request.user, instance_id): raise PermissionDenied() - + elif instance_type == "client": if not _has_perm_on_client(request.user, instance_id): raise PermissionDenied() @@ -480,7 +480,6 @@ class RunTestURLAction(APIView): debug_info={"ip": request._client_ip}, ) - return Response({"url": replaced_url, "result": result, "body": replaced_body}) diff --git a/api/tacticalrmm/logs/models.py b/api/tacticalrmm/logs/models.py index 975353c0..8be31cd3 100644 --- a/api/tacticalrmm/logs/models.py +++ b/api/tacticalrmm/logs/models.py @@ -1,5 +1,5 @@ from abc import abstractmethod -from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, Union, cast, Literal +from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Tuple, Union, cast from django.db import models @@ -166,9 +166,9 @@ class AuditLog(models.Model): agent: Optional["Agent"], debug_info: Dict[Any, Any] = {}, ) -> None: - + debug_info["script_body"] = script_body - + AuditLog.objects.create( agent=agent.hostname if agent else "Tactical RMM Server", agent_id=agent.agent_id if agent else "N/A", @@ -254,10 +254,10 @@ class AuditLog(models.Model): elif instance_type == "site": instance = Site.objects.get(pk=instance_id) - + elif instance_type == "client": instance = Client.objects.get(pk=instance_id) - + name = instance.hostname if isinstance(instance, Agent) else instance.name classname = type(instance).__name__ AuditLog.objects.create( diff --git a/api/tacticalrmm/scripts/views.py b/api/tacticalrmm/scripts/views.py index f3c1c75f..69f7338d 100644 --- a/api/tacticalrmm/scripts/views.py +++ b/api/tacticalrmm/scripts/views.py @@ -1,25 +1,25 @@ import asyncio +from django.conf import settings from django.shortcuts import get_object_or_404 from rest_framework.decorators import api_view, permission_classes from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView -from django.conf import settings from agents.permissions import RunScriptPerms +from core.utils import clear_entire_cache +from logs.models import AuditLog from tacticalrmm.constants import ScriptShell, ScriptType from tacticalrmm.helpers import notify_error from .models import Script, ScriptSnippet -from logs.models import AuditLog from .permissions import ScriptsPerms from .serializers import ( ScriptSerializer, ScriptSnippetSerializer, ScriptTableSerializer, ) -from core.utils import clear_entire_cache class GetAddScripts(APIView):