Commit fee30d75 authored by Francois Blackburn's avatar Francois Blackburn

incall: delete associations when incall deleted

parent be4877d3
......@@ -16,7 +16,9 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from xivo_dao.alchemy.extension import Extension
from xivo_dao.alchemy.incall import Incall
from xivo_dao.alchemy.rightcallmember import RightCallMember
from xivo_dao.helpers import errors
from xivo_dao.resources.utils.search import SearchResult, CriteriaBuilderMixin
......@@ -62,5 +64,17 @@ class IncallPersistor(CriteriaBuilderMixin):
self.session.flush()
def delete(self, incall):
self._delete_associations(incall)
self.session.delete(incall)
self.session.flush()
def _delete_associations(self, incall):
(self.session.query(RightCallMember)
.filter(RightCallMember.type == 'incall')
.filter(RightCallMember.typeval == str(incall.id))
.delete())
(self.session.query(Extension)
.filter(Extension.type == 'incall')
.filter(Extension.typeval == str(incall.id))
.update({'type': 'user', 'typeval': '0'}))
......@@ -24,9 +24,11 @@ from hamcrest import (assert_that,
is_not,
none)
from xivo_dao.alchemy.incall import Incall
from xivo_dao.alchemy.callerid import Callerid
from xivo_dao.alchemy.dialaction import Dialaction
from xivo_dao.alchemy.extension import Extension
from xivo_dao.alchemy.incall import Incall
from xivo_dao.alchemy.rightcallmember import RightCallMember
from xivo_dao.tests.test_dao import DAOTestCase
from xivo_dao.resources.incall import dao as incall_dao
from xivo_dao.resources.extension import dao as extension_dao
......@@ -372,6 +374,25 @@ class TestDelete(DAOTestCase):
caller_id = self.session.query(Callerid).first()
assert_that(caller_id, none())
def test_when_deleting_then_call_permission_are_dissociated(self):
incall = self.add_incall()
self.add_call_permission()
self.add_incall_call_permission(typeval=str(incall.id))
incall_dao.delete(incall)
incall_call_permission = self.session.query(RightCallMember).first()
assert_that(incall_call_permission, none())
def test_when_deleting_then_extension_are_dissociated(self):
incall = self.add_incall()
extension = self.add_extension(type='incall', typeval=str(incall.id))
incall_dao.delete(incall)
extension = self.session.query(Extension).filter(Extension.id == extension.id).first()
assert_that(extension, has_properties(type='user', typeval='0'))
class TestFindLineExtensionByExtensionId(DAOTestCase):
......
......@@ -66,7 +66,7 @@ from xivo_dao.alchemy.queueskill import QueueSkill
from xivo_dao.alchemy.queueskillrule import QueueSkillRule
from xivo_dao.alchemy.outcall import Outcall
from xivo_dao.alchemy.rightcall import RightCall as CallPermission
from xivo_dao.alchemy.rightcallmember import RightCallMember as UserCallPermission
from xivo_dao.alchemy.rightcallmember import RightCallMember as CallPermissionAssociation
from xivo_dao.alchemy.sccpdevice import SCCPDevice as SCCPDeviceSchema
from xivo_dao.alchemy.sccpgeneralsettings import SCCPGeneralSettings
from xivo_dao.alchemy.sccpline import SCCPLine as SCCPLineSchema
......@@ -340,13 +340,20 @@ class DAOTestCase(unittest.TestCase):
return user_call_permission
def add_user_call_permission(self, **kwargs):
user_call_permission = UserCallPermission(**kwargs)
kwargs.setdefault('type', 'user')
user_call_permission = CallPermissionAssociation(**kwargs)
self.add_me(user_call_permission)
return user_call_permission
def add_group_call_permission(self, **kwargs):
kwargs.setdefault('type', 'group')
group_call_permission = UserCallPermission(**kwargs)
group_call_permission = CallPermissionAssociation(**kwargs)
self.add_me(group_call_permission)
return group_call_permission
def add_incall_call_permission(self, **kwargs):
kwargs.setdefault('type', 'incall')
group_call_permission = CallPermissionAssociation(**kwargs)
self.add_me(group_call_permission)
return group_call_permission
......
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