Commit f3b6912b authored by Etienne Allovon's avatar Etienne Allovon

Merge branch '2375-fix-agent-api' into '2018.16'

2375 fix agent api

See merge request !36
parents 6a1dac86 2e1741d7
xivo-dao (2018.16.08) xivo-borealis; urgency=medium
* 2375 Add a CtiProfile to user when it's not set and a login is set
-- Jean-Pierre Thomasset <jpthomasset@gmail.com> Fri, 22 Feb 2019 09:44:53 +0000
xivo-dao (2018.16.06) xivo-borealis; urgency=medium
* 2352 Add api to create func key destination for agent
......
......@@ -75,6 +75,7 @@ def find_all_by(**criteria):
def create(user):
created_user = persistor().create(user)
UserFixes(Session).fix(created_user.id)
DestinationPersistor(Session).create_user_destination(created_user)
return created_user
......
......@@ -16,6 +16,7 @@
# 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.cti_profile import CtiProfile
from xivo_dao.alchemy.userfeatures import UserFeatures as User
from xivo_dao.alchemy.user_line import UserLine
from xivo_dao.alchemy.voicemail import Voicemail
......@@ -31,6 +32,7 @@ class UserFixes(object):
def fix(self, user_id):
self.fix_user(user_id)
self.fix_line(user_id)
self.fix_cti_profile(user_id)
self.session.flush()
def fix_user(self, user_id):
......@@ -57,6 +59,20 @@ class UserFixes(object):
if line_id:
LineFixes(self.session).fix(line_id)
def fix_cti_profile(self, user_id):
user = self.session.query(User).filter(User.id == user_id).first()
updated = False
if user.loginclient is not None and len(user.loginclient) > 0:
if user.cti_profile is None:
user.cti_profile = self.session.query(CtiProfile).first()
updated = True
if user.enableclient == 0:
user.enableclient = 1
updated = True
if updated:
self.session.add(user)
def find_line_id(self, user_id):
return (self.session
.query(UserLine.line_id)
......
......@@ -28,7 +28,9 @@ from hamcrest import none
from hamcrest import has_items
from hamcrest import contains
from hamcrest import not_
from hamcrest import not_none
from xivo_dao.alchemy.cti_profile import CtiProfile
from xivo_dao.alchemy.entity import Entity
from xivo_dao.alchemy.userfeatures import UserFeatures as User
from xivo_dao.alchemy.schedule import Schedule
......@@ -789,6 +791,20 @@ class TestCreate(TestUser):
destunc='789',
musiconhold='music_on_hold'))
def test_create_fix_cti_profile(self):
cti_profile = CtiProfile()
cti_profile.name = 'test_profile'
self.add_me(cti_profile)
created_user = user_dao.create(User(firstname="John",
lastname="Smith",
loginclient="jsmith",
passwdclient="0000"))
updated_user = self.session.query(User).filter(User.id == created_user.id).first()
assert_that(updated_user.cti_profile, not_none())
assert_that(updated_user.cti_profile_id, equal_to(cti_profile.id))
assert_that(updated_user.enableclient, equal_to(1))
def test_that_the_user_uuid_is_unique(self):
shared_uuid = str(uuid.uuid4())
self.prepare_user(firstname='Alice', uuid=shared_uuid)
......
......@@ -16,9 +16,11 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from hamcrest import assert_that, equal_to
from hamcrest import assert_that, equal_to, not_none
from xivo_dao.alchemy.cti_profile import CtiProfile
from xivo_dao.alchemy.voicemail import Voicemail
from xivo_dao.alchemy.userfeatures import UserFeatures
from xivo_dao.alchemy.usersip import UserSIP
from xivo_dao.alchemy.sccpline import SCCPLine
from xivo_dao.tests.test_dao import DAOTestCase
......@@ -76,3 +78,16 @@ class TestUserFixes(DAOTestCase):
sccp = self.session.query(SCCPLine).first()
assert_that(sccp.cid_name, equal_to("John Smith"))
assert_that(sccp.cid_num, equal_to("1000"))
def test_given_user_has_login_cti_wo_profile(self):
cti_profile = CtiProfile()
cti_profile.name = 'test_profile'
self.add_me(cti_profile)
user = self.add_user(firstname="John", lastname="Smith", loginclient="jsmith", passwdclient="0000")
self.fixes.fix(user.id)
updated_user = self.session.query(UserFeatures).filter(UserFeatures.id == user.id).first()
assert_that(updated_user.cti_profile, not_none())
assert_that(updated_user.cti_profile_id, equal_to(cti_profile.id))
assert_that(updated_user.enableclient, equal_to(1))
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