From 1dd54d5e29aec6aeaaf2d7be1c37f0157f76165c Mon Sep 17 00:00:00 2001 From: abdollahis2 Date: Tue, 5 Mar 2024 10:37:40 -0500 Subject: [PATCH 1/2] modified the retain endpoint --- tr_sys/tr_ars/api.py | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/tr_sys/tr_ars/api.py b/tr_sys/tr_ars/api.py index c831454b..9cd87f6f 100644 --- a/tr_sys/tr_ars/api.py +++ b/tr_sys/tr_ars/api.py @@ -790,22 +790,44 @@ def block(req,key): #return redirect('/ars/api/messages/'+str(blocked_id)) return HttpResponse(json.dumps(httpjson, indent=2), content_type='application/json', status=200) + +def retain_all(parent_mesg, json_response): + + if parent_mesg.status != 'R': + parent_mesg.retain = True + parent_mesg.save() + children = Message.objects.filter(ref__pk=parent_mesg.pk) + for child in children: + child.retain = True + child.save() + json_response["success"]=True + json_response["parent_pk"]= str(parent_mesg.id) + else: + json_response["parent_pk"]= str(parent_mesg.id) + json_response["description"] = 'PK still running' + + return json_response @csrf_exempt def retain(req, key): mesg=Message.objects.get(pk=key) + json_response={ + "success":False + } if str(mesg.actor.agent.name) == 'ars-default-agent': - mesg.retain = True - mesg.save() + + json_response = retain_all(mesg, json_response) + + elif mesg.ref_id is not None: + parent_mesg = Message.objects.get(pk=mesg.ref_id) + json_response = retain_all(parent_mesg,json_response) + else: - if mesg.ref_id is not None: - parent_mesg = Message.objects.get(pk=mesg.ref_id) - parent_mesg.retain = True - parent_mesg.save() - return HttpResponse('retained the message for parent pk: %s' % mesg.ref_id) - else: - logger.error('pk: %s doesnt have a parent level pk' % key) - return HttpResponse('retained the message for parent pk: %s' % key) + json_response["description"] = 'Invalid PK' + + return HttpResponse(json.dumps(json_response, indent=2), + content_type='application/json', status=200) + def merge(req, key): logger.debug("Beginning merge for %s " % key) From 77d2b9bbf9126361cfefb947925b350b6f41f85e Mon Sep 17 00:00:00 2001 From: abdollahis2 Date: Tue, 5 Mar 2024 10:57:51 -0500 Subject: [PATCH 2/2] modified the retain endpoint --- tr_sys/tr_ars/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tr_sys/tr_ars/api.py b/tr_sys/tr_ars/api.py index 9cd87f6f..772203ba 100644 --- a/tr_sys/tr_ars/api.py +++ b/tr_sys/tr_ars/api.py @@ -795,11 +795,11 @@ def retain_all(parent_mesg, json_response): if parent_mesg.status != 'R': parent_mesg.retain = True - parent_mesg.save() + parent_mesg.save(update_fields=['retain']) children = Message.objects.filter(ref__pk=parent_mesg.pk) for child in children: child.retain = True - child.save() + child.save(update_fields=['retain']) json_response["success"]=True json_response["parent_pk"]= str(parent_mesg.id) else: