Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified the retain endpoint #589

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions tr_sys/tr_ars/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(update_fields=['retain'])
children = Message.objects.filter(ref__pk=parent_mesg.pk)
for child in children:
child.retain = True
child.save(update_fields=['retain'])
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)
Expand Down