Commit ae90be09 authored by Jean-Pierre Thomasset's avatar Jean-Pierre Thomasset

2397 - Add helper to get mds of a user or group

parent 9a750a87
......@@ -18,7 +18,7 @@
from xivo_dao.alchemy.groupfeatures import GroupFeatures
from xivo_dao.alchemy.queuemember import QueueMember
from xivo_dao.helpers.db_manager import daosession
from xivo_dao.alchemy.mediaserver import MediaServer
@daosession
def get(session, group_id):
......@@ -45,3 +45,15 @@ def is_user_member_of_group(session, user_id, group_id):
@daosession
def all(session):
return session.query(GroupFeatures).all()
@daosession
def get_mds_by_group_id(session, group_id):
mds = (session.query(MediaServer.name)
.join(GroupFeatures, MediaServer.id == GroupFeatures.mediaserverid)
.filter(GroupFeatures.id == int(group_id))
.scalar())
if not mds:
raise LookupError('Could not find a group with id %s', group_id)
else:
return mds
......@@ -513,7 +513,7 @@ class TestSimpleSearch(TestSearch):
context=user_line.extension.context,
provisioning_code=user_line.linefeatures.provisioning_code,
protocol=user_line.linefeatures.endpoint,
configregistrar=None,)])
configregistrar="default",)])
self.assert_search_returns_result(expected, view='summary')
......
......@@ -281,6 +281,7 @@ class DAOTestCase(unittest.TestCase):
kwargs.setdefault('protocolid', kwargs.get('endpoint_id', self._generate_int()))
kwargs.setdefault('provisioningid', int(''.join(random.choice('123456789') for _ in range(6))))
kwargs.setdefault('id', self._generate_int())
kwargs.setdefault('configregistrar', 'default')
line = LineFeatures(**kwargs)
self.add_me(line)
......
......@@ -62,3 +62,10 @@ class TestGroupDAO(DAOTestCase):
queue_member.category = 'group'
self.add_me(queue_member)
def test_get_mds(self):
mediaserver = self.add_mediaserver(name="mds1")
group = self.add_groupfeatures(name='test_name', number='1234', context='my_ctx', mediaserverid=mediaserver.id)
mds = group_dao.get_mds_by_group_id(group.id)
self.assertEqual(mds, 'mds1')
......@@ -76,3 +76,14 @@ class TestUserFeaturesDAO(DAOTestCase):
assert_that(res.UserFeatures.agentid, equal_to(agent.id))
assert_that(res.agent_number, equal_to(unicode(agent.number)))
assert_that(res.agent_group_id, equal_to(agent.numgroup))
def test_get_mds_by_user_id(self):
user = self.add_user()
line = self.add_line(configregistrar='mds1')
self.add_user_line(user_id=user.id, line_id=line.id)
res = user_dao.get_mds_by_user_id(user.id)
assert_that(res, equal_to('mds1'))
......@@ -83,3 +83,17 @@ def get_user_with_agent_number(session, user_id):
raise errors.not_found('User', id=user_id)
return result
@daosession
def get_mds_by_user_id(session, user_id):
mds = (session.query(LineFeatures.configregistrar)
.join(UserLine, and_(UserLine.line_id == LineFeatures.id,
UserLine.user_id == int(user_id),
UserLine.main_user == True,
UserLine.main_line == True))
.scalar())
if not mds:
raise LookupError('Could not find a line for user %s', user_id)
else:
return mds
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