Commit 5b67310b authored by Tomas Taraba's avatar Tomas Taraba

Merge branch '2936-disabled-users-generated' into 'master'

2936 disabled users generated

See merge request !58
parents 74542fa4 12cccfe1
xivo-dao (2019.12.06) xivo-deneb; urgency=medium
* 2954 Disabled extensions are still generated in the dialplan
-- Vojtech Sodoma <[email protected]> Mon, 11 Nov 2019 11:14:02 +0100
xivo-dao (2019.12.03) xivo-deneb; urgency=medium
* Bump version to 2019.12.03
......
......@@ -291,7 +291,7 @@ def find_exten_conferences_settings(session, context_name):
def find_exten_xivofeatures_setting(session):
rows = (session.query(Extension)
.filter(and_(Extension.context == 'xivo-features',
Extension.commented == 0)).order_by(text('exten'))
Extension.commented == 0)).order_by(Extension.exten)
.all())
return [row.todict() for row in rows]
......@@ -304,7 +304,7 @@ def find_extenfeatures_settings(session, features=None):
query = (session.query(Extension)
.filter(and_(Extension.context == 'xivo-features',
Extension.type == 'extenfeatures'))
.order_by(text('exten')))
.order_by(Extension.exten))
if features:
query = query.filter(Extension.typeval.in_(features))
......@@ -316,7 +316,9 @@ def find_extenfeatures_settings(session, features=None):
def find_exten_settings(session, context_name):
rows = (_find_user_exten_settings(session, context_name) +
_find_group_exten_settings(session, context_name) +
_find_queue_meetme_exten_settings(session, context_name) +
_find_queue_exten_settings(session, context_name) +
_find_meetme_exten_settings(session, context_name) +
_find_incall_exten_settings(session, context_name) +
_find_other_exten_settings(session, context_name))
return rows
......@@ -332,11 +334,13 @@ def _find_user_exten_settings(session, context_name):
UserLine.main_user == True,
UserLine.main_line == True))
.join(LineFeatures, LineFeatures.id == UserLine.line_id)
.join(UserFeatures, UserFeatures.id == UserLine.user_id)
.filter(and_(Extension.context == context_name,
Extension.commented == 0,
Extension.type == 'user',
LineFeatures.commented == 0))
.order_by(text('exten'))
LineFeatures.commented == 0,
UserFeatures.commented == 0))
.order_by(Extension.exten)
.all())
return [_extension_row_to_dict(row) for row in rows]
......@@ -345,31 +349,63 @@ def _find_group_exten_settings(session, context_name):
rows = (session.query(Extension,
MediaServer.name.label('mediaserver'))
.join(GroupFeatures, cast(GroupFeatures.id, String) == Extension.typeval)
.join(Queue, Queue.name == GroupFeatures.name)
.join(MediaServer, MediaServer.id == GroupFeatures.mediaserverid)
.filter(and_(Extension.context == context_name,
Extension.type == 'group'))
.order_by(text('exten'))
Extension.type == 'group',
Queue.commented == 0))
.order_by(Extension.exten)
.all())
return [_extension_row_to_dict(row) for row in rows]
def _find_queue_meetme_exten_settings(session, context_name):
def _find_queue_exten_settings(session, context_name):
rows = (session.query(Extension,
literal('default').label('mediaserver'))
.join(QueueFeatures, cast(QueueFeatures.id, String) == Extension.typeval)
.join(Queue, Queue.name == QueueFeatures.name)
.filter(and_(Extension.context == context_name,
Extension.type.in_(['queue', 'meetme'])))
.order_by(text('exten'))
Extension.type == 'queue',
Queue.commented == 0))
.order_by(Extension.exten)
.all())
return [_extension_row_to_dict(row) for row in rows]
def _find_meetme_exten_settings(session, context_name):
rows = (session.query(Extension,
literal('default').label('mediaserver'))
.join(MeetmeFeatures, cast(MeetmeFeatures.id, String) == Extension.typeval)
.join(StaticMeetme, StaticMeetme.id == MeetmeFeatures.meetmeid)
.filter(and_(Extension.context == context_name,
Extension.type == 'meetme',
StaticMeetme.commented == 0))
.order_by(Extension.exten)
.all())
return [_extension_row_to_dict(row) for row in rows]
def _find_incall_exten_settings(session, context_name):
rows = (session.query(Extension,
literal(None).label('mediaserver'))
.join(Incall, cast(Incall.id, String) == Extension.typeval)
.filter(and_(Extension.context == context_name,
Extension.type == 'incall',
Incall.commented == 0))
.order_by(Extension.exten)
.all())
return [_extension_row_to_dict(row) for row in rows]
def _find_other_exten_settings(session, context_name):
rows = (session.query(Extension,
literal(None).label('mediaserver'))
.filter(and_(Extension.context == context_name,
Extension.type.notin_(['meetme', 'queue', 'user', 'group'])))
.order_by(text('exten'))
Extension.type.notin_(['meetme', 'queue', 'user', 'group', 'incall'])))
.order_by(Extension.exten)
.all())
return [_extension_row_to_dict(row) for row in rows]
......@@ -418,14 +454,14 @@ def is_sip_trunk_on_current_mds(session, trunk_name, current_mds_name):
@daosession
def find_context_settings(session):
rows = session.query(Context).filter(Context.commented == 0).order_by(text('name')).all()
rows = session.query(Context).filter(Context.commented == 0).order_by(Context.name).all()
return [row.todict() for row in rows]
@daosession
def find_contextincludes_settings(session, context_name):
rows = session.query(ContextInclude).filter(ContextInclude.context == context_name).order_by(text('priority')).all()
rows = session.query(ContextInclude).filter(ContextInclude.context == context_name).order_by(ContextInclude.priority).all()
return [row.todict() for row in rows]
......@@ -669,7 +705,7 @@ def find_meetme_rooms_settings(session):
@daosession
def find_musiconhold_settings(session):
rows = session.query(MusicOnHold).filter(MusicOnHold.commented == 0).order_by(text('category')).all()
rows = session.query(MusicOnHold).filter(MusicOnHold.commented == 0).order_by(MusicOnHold.category).all()
return [row.todict() for row in rows]
......@@ -684,7 +720,7 @@ def find_queue_general_settings(session):
@daosession
def find_queue_settings(session):
rows = session.query(Queue).filter(Queue.commented == 0).order_by(text('name')).all()
rows = session.query(Queue).filter(Queue.commented == 0).order_by(Queue.name).all()
return [row.todict() for row in rows]
......
......@@ -590,6 +590,18 @@ class TestAsteriskConfDAO(DAOTestCase, PickupHelperMixin):
assert_that(result, contains())
def test_find_exten_settings_when_user_disabled(self):
user_row = self.add_user(commented=1)
line_row = self.add_line()
extension_row = self.add_extension(exten='14', context='default')
self.add_user_line(user_id=user_row.id,
extension_id=extension_row.id,
line_id=line_row.id)
result = asterisk_conf_dao.find_exten_settings('default')
assert_that(result, contains())
def test_find_exten_settings_multiple_extensions(self):
user1 = self.add_user()
line1 = self.add_line()
......@@ -630,7 +642,8 @@ class TestAsteriskConfDAO(DAOTestCase, PickupHelperMixin):
def test_find_exten_group(self):
mds = self.add_mediaserver(name='mds1', display_name='MDS1', voip_ip='10.10.0.1')
group = self.add_groupfeatures(mediaserverid=mds.id)
group = self.add_groupfeatures(name='group_1', mediaserverid=mds.id)
self.add_queue(name='group_1', commented=0)
extension_row = self.add_extension(exten='12', context='default', type='group', typeval=str(group.id))
expected_result = [
......@@ -647,9 +660,20 @@ class TestAsteriskConfDAO(DAOTestCase, PickupHelperMixin):
assert_that(result, contains(*expected_result))
def test_find_exten_queue_meetme_on_default_mds(self):
queue = self.add_extension(exten='3000', context='default', type='queue', typeval='2')
meetme = self.add_extension(exten='4000', context='default', type='meetme', typeval='3')
def test_find_exten_group_when_group_disabled(self):
mds = self.add_mediaserver(name='mds1', display_name='MDS1', voip_ip='10.10.0.1')
group = self.add_groupfeatures(name='group_1', mediaserverid=mds.id)
self.add_queue(name='group_1', commented=1)
self.add_extension(exten='12', context='default', type='group', typeval=str(group.id))
result = asterisk_conf_dao.find_exten_settings('default')
assert_that(result, contains())
def test_find_exten_queue_on_default_mds(self):
extension = self.add_extension(exten='3000', context='default', type='queue', typeval='2')
self.add_queuefeatures(id=2, name='queue_1')
self.add_queue(name='queue_1', commented=0)
expected_result = [
{'exten': u'3000',
......@@ -658,20 +682,76 @@ class TestAsteriskConfDAO(DAOTestCase, PickupHelperMixin):
'typeval': '2',
'type': 'queue',
'mediaserver': 'default',
'id': queue.id},
{'exten': u'4000',
'id': extension.id}
]
result = asterisk_conf_dao.find_exten_settings('default')
assert_that(result, contains(*expected_result))
def test_find_exten_queue_on_default_mds_when_queue_disabled(self):
self.add_extension(exten='3000', context='default', type='queue', typeval='2')
self.add_queuefeatures(id=2, name='queue_1')
self.add_queue(name='queue_1', commented=1)
result = asterisk_conf_dao.find_exten_settings('default')
assert_that(result, contains())
def test_find_exten_meetme_on_default_mds(self):
self.add_meetme_general_settings(id=7, category='rooms', commented=0)
self.add_meetmefeatures(id=2, meetmeid=7)
extension = self.add_extension(exten='5000', context='default', type='meetme', typeval='2')
expected_result = [
{'exten': u'5000',
'commented': 0,
'context': u'default',
'typeval': '3',
'typeval': '2',
'type': 'meetme',
'mediaserver': 'default',
'id': meetme.id},
'id': extension.id}
]
result = asterisk_conf_dao.find_exten_settings('default')
assert_that(result, contains(*expected_result))
def test_find_exten_meetme_on_default_mds_when_meetme_disabled(self):
self.add_meetme_general_settings(id=7, category='rooms', commented=1)
self.add_meetmefeatures(id=2, meetmeid=7)
self.add_extension(exten='5000', context='default', type='meetme', typeval='2')
result = asterisk_conf_dao.find_exten_settings('default')
assert_that(result, contains())
def test_find_exten_incall_on_default_mds(self):
self.add_incall(id=2, commented=0)
extension = self.add_extension(exten='_0123X.', context='default', type='incall', typeval='2')
expected_result = [
{'exten': u'_0123X.',
'commented': 0,
'context': u'default',
'typeval': '2',
'type': 'incall',
'mediaserver': None,
'id': extension.id}
]
result = asterisk_conf_dao.find_exten_settings('default')
assert_that(result, contains(*expected_result))
def test_find_exten_incall_on_default_mds_when_incall_disabled(self):
self.add_incall(id=2, commented=1)
self.add_extension(exten='_0123X.', context='default', type='incall', typeval='2')
result = asterisk_conf_dao.find_exten_settings('default')
assert_that(result, contains())
def test_find_exten_other_no_mds(self):
vm = self.add_extension(exten='4000', context='default', type='voicemenu', typeval='2')
......
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