2020-03-05 12:54:34 +00:00
|
|
|
from logging import Logger
|
|
|
|
from uuid import uuid4
|
|
|
|
|
2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.bll.queue import QueueBLL
|
2021-01-05 14:44:31 +00:00
|
|
|
from apiserver.config_repo import config
|
2021-01-05 14:28:49 +00:00
|
|
|
from apiserver.database.model.company import Company
|
|
|
|
from apiserver.database.model.queue import Queue
|
|
|
|
from apiserver.database.model.settings import Settings, SettingKeys
|
2020-03-05 12:54:34 +00:00
|
|
|
|
|
|
|
log = config.logger(__file__)
|
|
|
|
|
|
|
|
|
2020-08-10 05:30:40 +00:00
|
|
|
def _ensure_company(company_id, company_name, log: Logger):
|
2020-03-05 12:54:34 +00:00
|
|
|
company = Company.objects(id=company_id).only("id").first()
|
|
|
|
if company:
|
|
|
|
return company_id
|
|
|
|
|
|
|
|
log.info(f"Creating company: {company_name}")
|
|
|
|
company = Company(id=company_id, name=company_name)
|
|
|
|
company.save()
|
|
|
|
return company_id
|
|
|
|
|
|
|
|
|
|
|
|
def _ensure_default_queue(company):
|
|
|
|
"""
|
|
|
|
If no queue is present for the company then
|
|
|
|
create a new one and mark it as a default
|
|
|
|
"""
|
|
|
|
queue = Queue.objects(company=company).only("id").first()
|
|
|
|
if queue:
|
|
|
|
return
|
|
|
|
|
|
|
|
QueueBLL.create(company, name="default", system_tags=["default"])
|
|
|
|
|
|
|
|
|
|
|
|
def _ensure_uuid():
|
2020-06-01 10:01:31 +00:00
|
|
|
Settings.add_value(SettingKeys.server__uuid, str(uuid4()))
|