phone: don't use SSO username as a line by default (#16648)

This commit is contained in:
Thomas NOËL 2017-05-31 23:55:20 +02:00
parent 8bbb458eae
commit 5ed78d803e
3 changed files with 58 additions and 5 deletions

View File

@ -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

View File

@ -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']

View File

@ -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)