From 69f42629935b2be6f9df50e6ce3ee73c03b6577f Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 26 Nov 2020 06:34:12 +0100 Subject: [PATCH] phonecalls: pass callee to redirect_url (#48850) --- passerelle/apps/phonecalls/models.py | 7 ++++--- tests/test_phonecalls.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/passerelle/apps/phonecalls/models.py b/passerelle/apps/phonecalls/models.py index 5e06592b..4a3ed97d 100644 --- a/passerelle/apps/phonecalls/models.py +++ b/passerelle/apps/phonecalls/models.py @@ -14,13 +14,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import json - from django.contrib.postgres.fields import JSONField from django.db import models +from django.utils.http import urlencode from django.utils.timezone import now, timedelta, make_naive from django.utils.translation import ugettext_lazy as _ -from django.http import HttpResponseRedirect, HttpResponse +from django.http import HttpResponseRedirect from django.shortcuts import render from passerelle.base.models import BaseResource @@ -71,6 +70,8 @@ class PhoneCalls(BaseResource): response = {'data': new_call.json()} redirect_url = self.redirect_url + if redirect_url: + redirect_url += ('&' if '?' in redirect_url else '?') + urlencode({'callee': callee}) # redirect to agent's portal if redirect and redirect_url: diff --git a/tests/test_phonecalls.py b/tests/test_phonecalls.py index d1a573ea..08f99fd7 100644 --- a/tests/test_phonecalls.py +++ b/tests/test_phonecalls.py @@ -220,7 +220,7 @@ def test_phonecalls_start_redirect(app, phonecalls): start_endpoint = utils.generic_endpoint_url('phonecalls', 'call-start', slug=phonecalls.slug) resp = app.get(start_endpoint, status=302, params={ 'apikey': '123', 'callee': '42', 'caller': '0612345678', 'redirect': '1'}) - assert resp.location == 'https://portail-agent.publik/' + assert resp.location == 'https://portail-agent.publik/?callee=42' assert Call.objects.filter(callee='42', caller='0612345678').count() == 1 @@ -233,5 +233,15 @@ def test_phonecalls_start_newtab(app, phonecalls): resp = app.get(start_endpoint, status=200, params={ 'apikey': '123', 'callee': '42', 'caller': '0612345678', 'newtab': '1'}) assert resp.content_type == 'text/html' - assert 'window.open("https://portail\\u002Dagent.publik/")' in resp.text + assert 'window.open("https://portail\\u002Dagent.publik/?callee\\u003D42")' in resp.text assert Call.objects.filter(callee='42', caller='0612345678').count() == 1 + + +def test_phonecalls_add_callee(app, phonecalls): + phonecalls.redirect_url = 'https://portail-agent.publik/' + phonecalls.save() + + start_endpoint = utils.generic_endpoint_url('phonecalls', 'call-start', slug=phonecalls.slug) + resp = app.get(start_endpoint, status=302, params={ + 'apikey': '123', 'callee': '42', 'caller': '0612345678', 'redirect': '1'}) + assert resp.location == 'https://portail-agent.publik/?callee=42' -- 2.29.2