Fix handling of temp extension data
This commit is contained in:
parent
ca9c82dd59
commit
6825ba8156
@ -5,6 +5,8 @@ import mitel_ommclient2
|
||||
import time
|
||||
import hashlib
|
||||
|
||||
from .extensions import ExtensionConfig
|
||||
|
||||
logger = logging.getLogger("fieldpoc.dect")
|
||||
|
||||
class Dect:
|
||||
@ -29,12 +31,13 @@ class Dect:
|
||||
used_temp_extensions = self.c.find_users(lambda u: u.num.startswith(self.temp_num_prefix))
|
||||
for u in used_temp_extensions:
|
||||
temp_num = u.num
|
||||
self.fp.temp_extensions[temp_num] = {
|
||||
"name": f"Temp {temp_num[4:]}",
|
||||
"type": "dect",
|
||||
"trunk": False,
|
||||
"dialout_allowed": False,
|
||||
}
|
||||
self.fp.temp_extensions[temp_num] = ExtensionConfig(
|
||||
num=temp_num,
|
||||
name=f"Temp {temp_num[4:]}",
|
||||
type="dect",
|
||||
trunk=False,
|
||||
dialout_allowed=False,
|
||||
)
|
||||
|
||||
def get_temp_number(self):
|
||||
current_temp_extension = 0
|
||||
@ -145,12 +148,13 @@ class Dect:
|
||||
logger.debug(f'Creating and binding tmp-user for {d}: {temp_num}')
|
||||
user = self.create_and_bind_user(d, temp_num)
|
||||
self.c.set_user_name(user.uid, f"Temp {temp_num[4:]}")
|
||||
self.fp.temp_extensions[temp_num] = {
|
||||
"name": f"Temp {temp_num[4:]}",
|
||||
"type": "dect",
|
||||
"trunk": False,
|
||||
"dialout_allowed": False,
|
||||
}
|
||||
self.fp.temp_extensions[temp_num] = ExtensionConfig(
|
||||
num=temp_num,
|
||||
name=f"Temp {temp_num[4:]}",
|
||||
type="dect",
|
||||
trunk=False,
|
||||
dialout_allowed=False,
|
||||
)
|
||||
created_tmp_ext = True
|
||||
|
||||
# update rounting when new extensions got created
|
||||
|
@ -24,7 +24,7 @@ class ExtensionConfig:
|
||||
if self.type is None:
|
||||
raise Exception("Type field for extension {} is required".format(self.num))
|
||||
elif self.type == "dect":
|
||||
if self.dect_ipei is None and self.dect_claim_token is None:
|
||||
if self.dect_ipei is not None and self.dect_claim_token is not None:
|
||||
raise Exception("dect_ipei can't be used together with dect_claim_token in extension {}".format(self.num))
|
||||
elif self.type == "sip":
|
||||
if self.sip_password is None:
|
||||
|
@ -304,7 +304,7 @@ class YwsdForkRankMemberModel(ForkRankMemberModel):
|
||||
return super().delete()
|
||||
|
||||
|
||||
class BackendNerd(diffsync.DiffSync):
|
||||
class BackendFieldPOC(diffsync.DiffSync):
|
||||
yate = YateModel
|
||||
extension = ExtensionModel
|
||||
user = UserModel
|
||||
@ -317,7 +317,7 @@ class BackendNerd(diffsync.DiffSync):
|
||||
self.fp = fp
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def load(self, data):
|
||||
def load(self, extensions):
|
||||
#yate_dect = self.yate(
|
||||
# guru3_identifier="dect", hostname="dect", voip_listener="local"
|
||||
#)
|
||||
@ -327,18 +327,18 @@ class BackendNerd(diffsync.DiffSync):
|
||||
)
|
||||
self.add(yate_sip)
|
||||
|
||||
for key, value in data["extensions"].items():
|
||||
for num, extension in extensions.items():
|
||||
yate = None
|
||||
if value["type"] in ["dect", "static"]:
|
||||
if extension.type in ["dect", "static"]:
|
||||
# yate = yate_dect.guru3_identifier
|
||||
yate = yate_sip.guru3_identifier
|
||||
elif value["type"] in ["sip"]:
|
||||
elif extension.type in ["sip"]:
|
||||
yate = yate_sip.guru3_identifier
|
||||
elif value["type"] in ["callgroup"]:
|
||||
forkrank = self.forkrank(extension=key, index=0, mode="DEFAULT")
|
||||
elif extension.type in ["callgroup"]:
|
||||
forkrank = self.forkrank(extension=num, index=0, mode="DEFAULT")
|
||||
self.add(forkrank)
|
||||
|
||||
for member in value["callgroup_members"]:
|
||||
for member in extension.callgroup_members:
|
||||
frm = self.forkrankmember(
|
||||
forkrank=forkrank.get_unique_id(),
|
||||
extension=member,
|
||||
@ -346,36 +346,30 @@ class BackendNerd(diffsync.DiffSync):
|
||||
active=True,
|
||||
)
|
||||
self.add(frm)
|
||||
elif value["type"] in ["temp"]:
|
||||
elif extension.type in ["temp"]:
|
||||
continue
|
||||
|
||||
extension = self.extension(
|
||||
extension=key,
|
||||
**dict(
|
||||
(k, v)
|
||||
for k, v in value.items()
|
||||
if k in ["name", "outgoing_extension", "dialout_allowed"]
|
||||
),
|
||||
extension_type=("SIMPLE" if not value["trunk"] else "TRUNK")
|
||||
if not value["type"] == "callgroup"
|
||||
else "GROUP",
|
||||
self.add(self.extension(
|
||||
extension=num,
|
||||
name=extension.name,
|
||||
outgoing_extension=extension.outgoing_extension,
|
||||
dialout_allowed=extension.dialout_allowed,
|
||||
extension_type=("SIMPLE" if extension.trunk is not None else "TRUNK") if not extension.type == "callgroup" else "GROUP",
|
||||
forwarding_mode="DISABLED",
|
||||
lang="en-GB",
|
||||
yate=yate,
|
||||
)
|
||||
self.add(extension)
|
||||
))
|
||||
|
||||
if value["type"] in ["sip", "static", "dect"]:
|
||||
if extension.type in ["sip", "static", "dect"]:
|
||||
user_type = {"sip": "user", "dect": "user", "static": "static"}
|
||||
user = self.user(
|
||||
username=key,
|
||||
displayname=value["name"],
|
||||
password=value.get("sip_password", self.fp._dect.get_sip_password_for_number(key)),
|
||||
user_type=user_type[value["type"]],
|
||||
trunk=value["trunk"],
|
||||
static_target=value.get("static_target", ""),
|
||||
)
|
||||
self.add(user)
|
||||
self.add(self.user(
|
||||
username=num,
|
||||
displayname=extension.name,
|
||||
password=extension.sip_password if extension.sip_password is not None else self.fp._dect.get_sip_password_for_number(num),
|
||||
user_type=user_type[extension.type],
|
||||
trunk=extension.trunk,
|
||||
static_target=extension.static_target if extension.static_target is not None else "",
|
||||
))
|
||||
|
||||
|
||||
class BackendYwsd(diffsync.DiffSync):
|
||||
@ -491,9 +485,9 @@ class Routing:
|
||||
|
||||
logger.info("syncing")
|
||||
|
||||
state_fieldpoc = BackendNerd(self.fp)
|
||||
extensions = self.fp.extensions._c.copy()
|
||||
extensions['extensions'].update(self.fp.temp_extensions)
|
||||
state_fieldpoc = BackendFieldPOC(self.fp)
|
||||
extensions = self.fp.extensions.extensions_by_num.copy()
|
||||
extensions.update(self.fp.temp_extensions)
|
||||
state_fieldpoc.load(extensions)
|
||||
state_yate = BackendYwsd()
|
||||
state_yate.load("postgresql+psycopg2://{}:{}@{}/{}".format(
|
||||
|
Loading…
Reference in New Issue
Block a user