in modular_sdk/services/tenant_service.py [0:0]
def add_to_parent_map(tenant: Tenant, parent: Parent,
type_: str) -> Tenant:
if type_ not in ALLOWED_TENANT_PARENT_MAP_KEYS:
_LOG.warning(f'Unsupported type \'{type_}\'. Available options: '
f'{", ".join(ALLOWED_TENANT_PARENT_MAP_KEYS)}')
raise ModularException(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'Unsupported type \'{type_}\'. Available options: '
f'{", ".join(ALLOWED_TENANT_PARENT_MAP_KEYS)}'
)
if not tenant.is_active:
_LOG.warning(f'Tenant \'{tenant.name}\' is not active.')
raise ModularException(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'Tenant \'{tenant.name}\' is not active.'
)
if parent.is_deleted:
_LOG.warning(f'Parent \'{parent.parent_id}\' is deleted.')
raise ModularException(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'Tenant \'{tenant.name}\' is deleted.'
)
parent_map = tenant.parent_map.as_dict() # default "dict"
if type_ in parent_map:
_LOG.warning(f'Tenant \'{tenant.name}\' already has \'{type_}\' '
f'linkage type.')
raise ModularException(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'Tenant \'{tenant.name}\' already has \'{type_}\' '
f'linkage type.'
)
# we can update just one attribute only in
# case the map already exists in DB. Otherwise -> ValidationException
parent_map[type_] = parent.parent_id
tenant.update(actions=[
Tenant.parent_map.set(parent_map)
])
return tenant # no need to return