summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas NOEL <tnoel@entrouvert.com>2017-05-31 21:55:20 (GMT)
committerThomas NOEL <tnoel@entrouvert.com>2017-06-02 07:33:06 (GMT)
commit5ed78d803ee4744bab8faf59d4f363e1df324ba6 (patch)
treec5d96bfa340576932217be0a7734e5416b12ac41
parent8bbb458eaef67cdb5388bbbe67c96f0738df51d0 (diff)
downloadwelco-0.47.zip
welco-0.47.tar.gz
welco-0.47.tar.bz2
phone: don't use SSO username as a line by default (#16648)v0.47
-rw-r--r--tests/test_source_phone.py49
-rw-r--r--welco/settings.py3
-rw-r--r--welco/sources/phone/views.py11
3 files changed, 58 insertions, 5 deletions
diff --git a/tests/test_source_phone.py b/tests/test_source_phone.py
index c95b458..d344a44 100644
--- a/tests/test_source_phone.py
+++ b/tests/test_source_phone.py
@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
+import re
import pytest
@@ -224,6 +225,54 @@ def test_take_release_line(user, client):
users=user, callee='102').count() == 0
+def test_phone_zone(user, client):
+ client.login(username='toto', password='toto')
+ response = client.get(reverse('phone-zone'))
+ assert response.status_code == 200
+ assert 'You do not have a phoneline configured' in response.content
+
+ models.PhoneLine.take(callee='102', user=user)
+
+ response = client.get(reverse('phone-zone'))
+ assert response.status_code == 200
+ assert 'You do not have a phoneline configured' not in response.content
+ assert '<li>102' in response.content
+ assert 'data-callee="102"' in response.content
+ currents = re.search('<div id="source-mainarea" '
+ 'data-current-calls="/api/phone/current-calls/">'
+ '(.*?)</div>', response.content, flags=re.DOTALL)
+ assert currents.group(1).strip() == ''
+
+ # create a call
+ payload = {'event': 'start', 'caller': '003369999999', 'callee': '102'}
+ response = client.post(reverse('phone-call-event'), json.dumps(payload),
+ content_type='application/json')
+ assert response.status_code == 200
+ response = client.get(reverse('phone-zone'))
+ assert response.status_code == 200
+ assert '<h1>Current Call: <strong>003369999999</strong></h1>' in response.content
+
+ # simulate a mellon user
+ session = client.session
+ session['mellon_session'] = {'username': ['agent007@ldap']}
+ session.save()
+ response = client.get(reverse('phone-zone'))
+ assert response.status_code == 200
+ assert 'agent007' not in response.content
+ assert 'data-callee="agent007"' not in response.content
+ assert '<li>102' in response.content
+ assert 'data-callee="102"' in response.content
+
+ with override_settings(PHONE_AUTOTAKE_MELLON_USERNAME=True):
+ response = client.get(reverse('phone-zone'))
+ assert response.status_code == 200
+ assert '<h1>Current Call: <strong>003369999999</strong></h1>' in response.content
+ assert 'agent007' in response.content
+ assert 'data-callee="agent007"' in response.content
+ assert '<li>102' in response.content
+ assert 'data-callee="102"' in response.content
+
+
def test_call_expiration(user, client):
assert models.PhoneCall.objects.count() == 0
# create a call
diff --git a/welco/settings.py b/welco/settings.py
index ec05e60..6bba920 100644
--- a/welco/settings.py
+++ b/welco/settings.py
@@ -201,6 +201,9 @@ COUNTER_LINKS = [
# phone system
PHONE_ONE_CALL_PER_CALLEE = True
PHONE_MAX_CALL_DURATION = 0 # in minutes, 0 stands for infinity
+# If user is from SSO (ie django-mellon session), consider username
+# as a phone line number and take it automatically.
+PHONE_AUTOTAKE_MELLON_USERNAME = False
# enable/disable specific features
# ex: FLAVOURS = ['alfortville']
diff --git a/welco/sources/phone/views.py b/welco/sources/phone/views.py
index 0211bc4..8ac3096 100644
--- a/welco/sources/phone/views.py
+++ b/welco/sources/phone/views.py
@@ -52,12 +52,13 @@ class PhoneZone(TemplateView):
template_name = 'welco/phone_home.html'
def get_context_data(self, **kwargs):
- username = self.request.session.get('mellon_session', {}).get('username')
- if username:
- # user is from SSO, username is a phone line (callee), create a link to it
- username = username[0].split('@', 1)[0][:80] # remove realm
+ if settings.PHONE_AUTOTAKE_MELLON_USERNAME:
+ username = self.request.session.get('mellon_session', {}).get('username')
if username:
- PhoneLine.take(callee=username, user=self.request.user)
+ # user is from SSO, username is a phone line (callee), create a link to it
+ username = username[0].split('@', 1)[0][:80] # remove realm
+ if username:
+ PhoneLine.take(callee=username, user=self.request.user)
context = super(PhoneZone, self).get_context_data(**kwargs)
context['source_type'] = ContentType.objects.get_for_model(PhoneCall)
context['phonelines'] = PhoneLine.objects.filter(users__id=self.request.user.id)