Projet

Général

Profil

0001-phonecalls-pass-callee-to-redirect_url-48850.patch

Benjamin Dauvergne, 26 novembre 2020 06:34

Télécharger (2,99 ko)

Voir les différences:

Subject: [PATCH] phonecalls: pass callee to redirect_url (#48850)

 passerelle/apps/phonecalls/models.py | 16 +++++++++++++++-
 tests/test_phonecalls.py             | 10 ++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
passerelle/apps/phonecalls/models.py
15 15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import json
18
from urllib.parse import urlparse, urlunparse
18 19

  
19 20
from django.contrib.postgres.fields import JSONField
20 21
from django.db import models
21 22
from django.utils.timezone import now, timedelta, make_naive
22 23
from django.utils.translation import ugettext_lazy as _
23
from django.http import HttpResponseRedirect, HttpResponse
24
from django.http import HttpResponseRedirect, HttpResponse, QueryDict
24 25
from django.shortcuts import render
25 26

  
26 27
from passerelle.base.models import BaseResource
......
46 47
    class Meta:
47 48
        verbose_name = _('Phone Calls')
48 49

  
50
    @classmethod
51
    def add_callee_to_url(self, url, callee):
52
        parsed_url = urlparse(url)
53
        if parsed_url.query:
54
            query = QueryDict(parsed_url.query, mutable=True)
55
            for key in query:
56
                if query[key] == 'callee':
57
                    query[key] = callee
58
            url = urlunparse(parsed_url._replace(query=query.urlencode()))
59
        return url
60

  
49 61
    @endpoint(name='call-start',
50 62
              description=_('Notify a call start'),
51 63
              perm='can_access',
......
71 83
            response = {'data': new_call.json()}
72 84

  
73 85
        redirect_url = self.redirect_url
86
        if redirect_url:
87
            redirect_url = self.add_callee_to_url(redirect_url, callee)
74 88

  
75 89
        # redirect to agent's portal
76 90
        if redirect and redirect_url:
tests/test_phonecalls.py
235 235
    assert resp.content_type == 'text/html'
236 236
    assert 'window.open("https://portail\\u002Dagent.publik/")' in resp.text
237 237
    assert Call.objects.filter(callee='42', caller='0612345678').count() == 1
238

  
239

  
240
def test_phonecalls_add_callee(app, phonecalls):
241
    phonecalls.redirect_url = 'https://portail-agent.publik/?callee=callee'
242
    phonecalls.save()
243

  
244
    start_endpoint = utils.generic_endpoint_url('phonecalls', 'call-start', slug=phonecalls.slug)
245
    resp = app.get(start_endpoint, status=302, params={
246
        'apikey': '123', 'callee': '42', 'caller': '0612345678', 'redirect': '1'})
247
    assert resp.location == 'https://portail-agent.publik/?callee=42'
238
-