Commit 1c8c67ba authored by Etienne Allovon's avatar Etienne Allovon

2506 - add explicit join to Linefeatures table and generate custom/agents/bs hint per mds too

parent 0bab7ca8
......@@ -61,6 +61,8 @@ def _common_filter(query, context):
UserFeatures.id == UserLine.user_id)
.join(user_extension,
UserLine.extension_id == user_extension.id)
.join(LineFeatures,
LineFeatures.id == UserLine.line_id)
.filter(user_extension.context == context)
.filter(UserLine.main_user == True)
.filter(UserLine.main_line == True)
......@@ -181,7 +183,8 @@ def forward_hints(session, context):
def agent_hints(session, context):
query = (session.query(sql.cast(FuncKeyDestAgent.agent_id, Unicode).label('argument'),
UserFeatures.id.label('user_id'),
Extension.exten.label('extension'))
Extension.exten.label('extension'),
LineFeatures.configregistrar.label('mediaserver'))
.join(Extension,
Extension.id == FuncKeyDestAgent.extension_id)
.join(FuncKeyMapping,
......@@ -192,13 +195,14 @@ def agent_hints(session, context):
return tuple(Hint(user_id=row.user_id,
extension=clean_extension(row.extension),
argument=row.argument,
mediaserver='default')
mediaserver=row.mediaserver)
for row in query)
@daosession
def custom_hints(session, context):
query = (session.query(FuncKeyDestCustom.exten.label('extension'))
query = (session.query(FuncKeyDestCustom.exten.label('extension'),
LineFeatures.configregistrar.label('mediaserver'))
.join(FuncKeyMapping,
FuncKeyDestCustom.func_key_id == FuncKeyMapping.func_key_id))
query = _common_filter(query, context)
......@@ -206,7 +210,7 @@ def custom_hints(session, context):
return tuple(Hint(user_id=None,
extension=row.extension,
argument=None,
mediaserver=None)
mediaserver=row.mediaserver)
for row in query)
......@@ -214,7 +218,8 @@ def custom_hints(session, context):
def bsfilter_hints(session, context):
bsfilter_extension = clean_extension(_find_extenfeatures(session, 'bsfilter'))
query = (session.query(sql.cast(FuncKeyDestBSFilter.filtermember_id, Unicode).label('argument'))
query = (session.query(sql.cast(FuncKeyDestBSFilter.filtermember_id, Unicode).label('argument'),
LineFeatures.configregistrar.label('mediaserver'))
.join(Callfiltermember,
Callfiltermember.id == FuncKeyDestBSFilter.filtermember_id)
.join(Callfilter,
......@@ -225,6 +230,8 @@ def bsfilter_hints(session, context):
UserLine.user_id == UserFeatures.id)
.join(Extension,
Extension.id == UserLine.extension_id)
.join(LineFeatures,
LineFeatures.id == UserLine.line_id)
.filter(UserLine.main_user == True)
.filter(UserLine.main_line == True)
.filter(Extension.commented == 0)
......@@ -234,5 +241,5 @@ def bsfilter_hints(session, context):
return tuple(Hint(user_id=None,
extension=bsfilter_extension,
argument=row.argument,
mediaserver=None)
mediaserver=row.mediaserver)
for row in query)
......@@ -329,6 +329,20 @@ class TestAgentHints(TestHints):
assert_that(hint_dao.agent_hints(self.context), contains(expected))
def test_given_agent_func_key_then_returns_agent_hint_mds1(self):
self.add_mediaserver(name='mds1', display_name='MDS1', voip_ip='10.10.0.1')
destination_row = self.create_agent_func_key('_*31.', 'agentstaticlogin')
user_row = self.add_user_and_func_key(configregistrar='mds1')
self.add_func_key_to_user(destination_row, user_row)
expected = Hint(user_id=user_row.id,
extension='*31',
argument=str(destination_row.agent_id),
mediaserver='mds1')
assert_that(hint_dao.agent_hints(self.context), contains(expected))
def test_given_commented_extension_then_returns_no_hints(self):
destination_row = self.create_agent_func_key('_*31.', 'agentstaticlogin')
......@@ -378,7 +392,22 @@ class TestCustomHints(TestHints):
expected = Hint(user_id=None,
extension='1234',
argument=None,
mediaserver=None)
mediaserver='default')
assert_that(hint_dao.custom_hints(self.context), contains(expected))
def test_given_custom_func_key_then_returns_custom_hint_mds(self):
self.add_mediaserver(name='mds1', display_name='MDS1', voip_ip='10.10.0.1')
destination_row = self.create_custom_func_key('1234')
user_row = self.add_user_and_func_key(configregistrar='mds1')
self.add_func_key_to_user(destination_row, user_row)
expected = Hint(user_id=None,
extension='1234',
argument=None,
mediaserver='mds1')
assert_that(hint_dao.custom_hints(self.context), contains(expected))
......@@ -400,9 +429,12 @@ class TestBSFilterHints(TestHints):
type='extenfeatures',
typeval='bsfilter')
def create_boss_and_secretary(self, commented=0):
boss_row = self.add_user_and_func_key(exten='1000')
secretary_row = self.add_user_and_func_key(exten='1001')
def create_boss_and_secretary(self, commented=0, mediaserver='default'):
if mediaserver != 'default':
self.add_mediaserver(name=mediaserver, display_name='MDS1', voip_ip='10.10.0.1')
boss_row = self.add_user_and_func_key(exten='1000', configregistrar=mediaserver)
secretary_row = self.add_user_and_func_key(exten='1001', configregistrar=mediaserver)
callfilter_row = self.add_call_filter('bsfilter', commented=commented)
boss_member_row = self.add_filter_member(callfilter_row.id, boss_row.id)
......@@ -434,7 +466,17 @@ class TestBSFilterHints(TestHints):
expected = Hint(user_id=None,
extension='*37',
argument=str(filtermember_row.id),
mediaserver=None)
mediaserver='default')
assert_that(hint_dao.bsfilter_hints(self.context), contains(expected))
def test_given_bs_filter_func_key_then_returns_bs_filter_hint_mds1(self):
_, filtermember_row = self.create_boss_and_secretary(mediaserver='mds1')
expected = Hint(user_id=None,
extension='*37',
argument=str(filtermember_row.id),
mediaserver='mds1')
assert_that(hint_dao.bsfilter_hints(self.context), contains(expected))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment