fix bug when editing a check that has already been run
This commit is contained in:
parent
ea3db84f5f
commit
9a56095771
|
@ -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":
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue