fix bug when editing a check that has already been run

This commit is contained in:
wh1te909 2020-06-15 08:54:15 +00:00
parent ea3db84f5f
commit 9a56095771
2 changed files with 24 additions and 0 deletions

View File

@ -166,6 +166,27 @@ class Check(models.Model):
if self.check_type == "cpuload" or self.check_type == "memory":
return ", ".join(str(f"{x}%") for x in self.history[-6:])
@property
def non_editable_fields(self):
return [
"check_type",
"status",
"more_info",
"last_run",
"fail_count",
"email_sent",
"text_sent",
"outage_history",
"extra_details",
"stdout",
"stderr",
"retcode",
"execution_time",
"history",
"readable_desc",
"history_info",
]
def handle_check(self, data):
if self.check_type != "cpuload" and self.check_type != "memory":

View File

@ -59,6 +59,9 @@ class GetUpdateDeleteCheck(APIView):
def patch(self, request, pk):
check = get_object_or_404(Check, pk=pk)
# removed fields that should not be changed when editing a check from the frontend
[request.data.pop(i) for i in check.non_editable_fields]
serializer = CheckSerializer(instance=check, data=request.data, partial=True)
serializer.is_valid(raise_exception=True)
obj = serializer.save()