def post(self, request): policy = get_object_or_404(Policy, pk=request.data["policy"]) serializer = WinUpdatePolicySerializer(data=request.data, partial=True) serializer.is_valid(raise_exception=True) serializer.policy = policy # type: ignore serializer.save() return Response("ok")
def put(self, request, patchpolicy): policy = get_object_or_404(WinUpdatePolicy, pk=patchpolicy) serializer = WinUpdatePolicySerializer(instance=policy, data=request.data, partial=True) serializer.is_valid(raise_exception=True) serializer.save() return Response("ok")
def edit_agent(request): agent = get_object_or_404(Agent, pk=request.data["id"]) a_serializer = AgentSerializer(instance=agent, data=request.data, partial=True) a_serializer.is_valid(raise_exception=True) a_serializer.save() policy = WinUpdatePolicy.objects.get(agent=agent) p_serializer = WinUpdatePolicySerializer( instance=policy, data=request.data["winupdatepolicy"][0] ) p_serializer.is_valid(raise_exception=True) p_serializer.save() return Response("ok")
def edit_agent(request): agent = get_object_or_404(Agent, pk=request.data["id"]) a_serializer = AgentSerializer(instance=agent, data=request.data, partial=True) a_serializer.is_valid(raise_exception=True) a_serializer.save() if "winupdatepolicy" in request.data.keys(): policy = agent.winupdatepolicy.get() # type: ignore p_serializer = WinUpdatePolicySerializer( instance=policy, data=request.data["winupdatepolicy"][0]) p_serializer.is_valid(raise_exception=True) p_serializer.save() if "custom_fields" in request.data.keys(): for field in request.data["custom_fields"]: custom_field = field custom_field["agent"] = agent.id # type: ignore if AgentCustomField.objects.filter( field=field["field"], agent=agent.id # type: ignore ): value = AgentCustomField.objects.get( field=field["field"], agent=agent.id # type: ignore ) serializer = AgentCustomFieldSerializer(instance=value, data=custom_field) serializer.is_valid(raise_exception=True) serializer.save() else: serializer = AgentCustomFieldSerializer(data=custom_field) serializer.is_valid(raise_exception=True) serializer.save() return Response("ok")
def edit_agent(request): agent = get_object_or_404(Agent, pk=request.data["id"]) old_site = agent.site.pk a_serializer = AgentSerializer(instance=agent, data=request.data, partial=True) a_serializer.is_valid(raise_exception=True) a_serializer.save() policy = agent.winupdatepolicy.get() p_serializer = WinUpdatePolicySerializer( instance=policy, data=request.data["winupdatepolicy"][0] ) p_serializer.is_valid(raise_exception=True) p_serializer.save() # check if site changed and initiate generating correct policies if old_site != request.data["site"]: agent.generate_checks_from_policies(clear=True) agent.generate_tasks_from_policies(clear=True) return Response("ok")