sync after creating temp-extensions
This commit is contained in:
parent
d6d664b469
commit
4382942ad8
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
__pycache__
|
||||
dist/
|
||||
.venv
|
||||
|
@ -18,15 +18,31 @@ class Dect:
|
||||
ommsync=True,
|
||||
)
|
||||
|
||||
def get_temp_number(self):
|
||||
temp_num_prefix = next(self.fp.extensions.extensions_by_type("temp")).num
|
||||
@property
|
||||
def temp_num_prefix(self):
|
||||
return next(self.fp.extensions.extensions_by_type("temp")).num
|
||||
|
||||
def load_temp_extensions(self):
|
||||
current_temp_extension = 0
|
||||
used_temp_extensions = [u.num[len(temp_num_prefix):] for u in self.c.find_users(lambda u: u.num.startswith(temp_num_prefix))]
|
||||
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,
|
||||
}
|
||||
|
||||
|
||||
def get_temp_number(self):
|
||||
current_temp_extension = 0
|
||||
used_temp_extensions = [num[len(self.temp_num_prefix):] for num, ext in self.fp.temp_extensions.items()]
|
||||
|
||||
while "{:0>4}".format(current_temp_extension) in used_temp_extensions:
|
||||
current_temp_extension += 1
|
||||
|
||||
return "{}{:0>4}".format(temp_num_prefix, current_temp_extension)
|
||||
return "{}{:0>4}".format(self.temp_num_prefix, current_temp_extension)
|
||||
|
||||
def get_sip_password_for_number(self, num):
|
||||
return num
|
||||
@ -36,10 +52,12 @@ class Dect:
|
||||
self.c.attach_user_device(u.uid, d.ppn)
|
||||
self.c.set_user_relation_fixed(u.uid)
|
||||
self.c.set_user_sipauth(u.uid, num, self.get_sip_password_for_number(num))
|
||||
return u
|
||||
|
||||
def run(self):
|
||||
logger.info("initialising connection to OMM")
|
||||
self._init_client()
|
||||
self.load_temp_extensions()
|
||||
|
||||
while True:
|
||||
msg = self.fp.queues["dect"].get()
|
||||
@ -53,6 +71,7 @@ class Dect:
|
||||
extensions = self.fp.extensions.extensions_by_type("dect")
|
||||
extensions_by_num = {e.num: e for e in extensions}
|
||||
extensions_by_ipei = {e._c['dect_ipei']: e for _, e in extensions_by_num.items() if e._c.get('dect_ipei')}
|
||||
created_tmp_ext = False
|
||||
|
||||
users_by_ext = {}
|
||||
users_by_uid = {}
|
||||
@ -90,15 +109,30 @@ class Dect:
|
||||
ui = users_by_uid.get(d.uid)
|
||||
if ui.num != e.num:
|
||||
logger.debug(f'User for {d} has wrong number')
|
||||
if self.fp.temp_extensions.get(ui.num):
|
||||
self.fp.temp_extensions.pop(ui.num)
|
||||
self.c.set_user_num(d.uid, e.num)
|
||||
self.c.set_user_sipauth(d.uid, e.num, self.get_sip_password_for_number(e.num))
|
||||
self.c.set_user_name(user.uid, e._c['name'])
|
||||
else:
|
||||
logger.debug(f'Creating and binding user for {d}')
|
||||
self.create_and_bind_user(d, e.num)
|
||||
user = self.create_and_bind_user(d, e.num)
|
||||
self.c.set_user_name(user.uid, e._c['name'])
|
||||
|
||||
elif d.relType == mitel_ommclient2.types.PPRelTypeType("Unbound"):
|
||||
temp_num = self.get_temp_number()
|
||||
logger.debug(f'Creating and binding tmp-user for {d}: {temp_num}')
|
||||
self.create_and_bind_user(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,
|
||||
}
|
||||
created_tmp_ext = True
|
||||
|
||||
if created_tmp_ext:
|
||||
self.fp.queues['routing'].put({"type": "sync"})
|
||||
|
||||
self.c.connection.close()
|
||||
|
@ -17,6 +17,7 @@ logger = logging.getLogger("fieldpoc.fieldpoc")
|
||||
class FieldPOC:
|
||||
config = None
|
||||
extensions = None
|
||||
temp_extensions = {}
|
||||
|
||||
def __init__(self, config_file_path, extensions_file_path):
|
||||
logger.info("loading configuration")
|
||||
|
@ -488,7 +488,9 @@ class Routing:
|
||||
logger.info("syncing")
|
||||
|
||||
state_fieldpoc = BackendNerd()
|
||||
state_fieldpoc.load(self.fp.extensions._c)
|
||||
extensions = self.fp.extensions._c.copy()
|
||||
extensions['extensions'].update(self.fp.temp_extensions)
|
||||
state_fieldpoc.load(extensions)
|
||||
state_yate = BackendYwsd()
|
||||
state_yate.load("postgresql+psycopg2://{}:{}@{}/{}".format(
|
||||
self.fp.config.database.username,
|
||||
|
@ -95,7 +95,7 @@
|
||||
"name": "Temporary Numbers",
|
||||
"trunk": false,
|
||||
"dialout_allowed": true,
|
||||
"type": "static"
|
||||
"type": "temp"
|
||||
},
|
||||
"9999": {
|
||||
"name": "DECT Claim Extensions",
|
||||
|
Loading…
Reference in New Issue
Block a user