mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-07-25 12:01:04 +02:00
chore: incorporate review comments
This commit is contained in:
parent
e486920db2
commit
fdc181e75d
11 changed files with 215 additions and 152 deletions
|
|
@ -566,34 +566,6 @@ def _set_nested_field(value: dict, dotted_path: str, field_value) -> None:
|
|||
current[parts[-1]] = field_value
|
||||
|
||||
|
||||
async def _enforce_external_pbx_feature(
|
||||
organization_id: int,
|
||||
provider: str,
|
||||
credentials: dict,
|
||||
*,
|
||||
existing_credentials: Optional[dict] = None,
|
||||
) -> None:
|
||||
if provider != "ari":
|
||||
return
|
||||
if await external_pbx_integrations_enabled(organization_id):
|
||||
return
|
||||
requested_external_pbx = credentials.get("external_pbx")
|
||||
existing_external_pbx = (existing_credentials or {}).get("external_pbx")
|
||||
if not requested_external_pbx and not existing_external_pbx:
|
||||
return
|
||||
# Disabling the feature hides and disables the integration, but does not
|
||||
# destroy saved credentials. Allow only an unchanged masked round-trip.
|
||||
if requested_external_pbx == existing_external_pbx:
|
||||
return
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail=(
|
||||
"External PBX integrations are disabled for this organization. "
|
||||
"Enable them in Platform Settings before changing this configuration."
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def _credentials_from_payload(config: TelephonyConfigRequest) -> dict:
|
||||
"""Provider credentials only — strip provider/from_numbers from the payload."""
|
||||
payload = config.model_dump()
|
||||
|
|
@ -690,9 +662,6 @@ async def create_telephony_configuration(
|
|||
raise HTTPException(status_code=400, detail="No organization selected")
|
||||
|
||||
credentials = _credentials_from_payload(request.config)
|
||||
await _enforce_external_pbx_feature(
|
||||
user.selected_organization_id, request.config.provider, credentials
|
||||
)
|
||||
credentials = await _run_preprocess_hook(request.config.provider, credentials)
|
||||
|
||||
try:
|
||||
|
|
@ -775,12 +744,6 @@ async def update_telephony_configuration(
|
|||
preserve_masked_fields(
|
||||
existing.provider, credentials, existing.credentials or {}
|
||||
)
|
||||
await _enforce_external_pbx_feature(
|
||||
user.selected_organization_id,
|
||||
existing.provider,
|
||||
credentials,
|
||||
existing_credentials=existing.credentials or {},
|
||||
)
|
||||
credentials = await _run_preprocess_hook(existing.provider, credentials)
|
||||
|
||||
row = await db_client.update_telephony_configuration(
|
||||
|
|
|
|||
|
|
@ -41,10 +41,14 @@ from api.services.configuration.resolve import (
|
|||
resolve_effective_config,
|
||||
)
|
||||
from api.services.mps_service_key_client import mps_service_key_client
|
||||
from api.services.organization_preferences import external_pbx_integrations_enabled
|
||||
from api.services.posthog_client import capture_event
|
||||
from api.services.reports import generate_workflow_report_csv
|
||||
from api.services.storage import storage_fs
|
||||
from api.services.workflow.configuration_policy import (
|
||||
ExternalPBXConfigurationDisabledError,
|
||||
WorkflowConfigurationNotFoundError,
|
||||
apply_external_pbx_mapping_policy,
|
||||
)
|
||||
from api.services.workflow.dto import ReactFlowDTO, sanitize_workflow_definition
|
||||
from api.services.workflow.duplicate import duplicate_workflow
|
||||
from api.services.workflow.errors import ItemKind, WorkflowError
|
||||
|
|
@ -1051,41 +1055,16 @@ async def update_workflow(
|
|||
if request.workflow_configurations is not None
|
||||
else None
|
||||
)
|
||||
if workflow_configurations is not None and not (
|
||||
await external_pbx_integrations_enabled(user.selected_organization_id)
|
||||
):
|
||||
existing_workflow = await db_client.get_workflow(
|
||||
workflow_id, organization_id=user.selected_organization_id
|
||||
try:
|
||||
workflow_configurations = await apply_external_pbx_mapping_policy(
|
||||
workflow_configurations,
|
||||
workflow_id=workflow_id,
|
||||
organization_id=user.selected_organization_id,
|
||||
)
|
||||
if existing_workflow is None:
|
||||
raise HTTPException(
|
||||
status_code=404, detail=f"Workflow with id {workflow_id} not found"
|
||||
)
|
||||
existing_draft = await db_client.get_draft_version(workflow_id)
|
||||
existing_configs = (
|
||||
existing_draft.workflow_configurations
|
||||
if existing_draft
|
||||
else existing_workflow.released_definition.workflow_configurations
|
||||
)
|
||||
existing_mappings = (existing_configs or {}).get(
|
||||
"external_pbx_field_mappings", []
|
||||
)
|
||||
incoming_mappings = workflow_configurations.get(
|
||||
"external_pbx_field_mappings", existing_mappings
|
||||
)
|
||||
if incoming_mappings != existing_mappings:
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail=(
|
||||
"External PBX integrations are disabled for this organization. "
|
||||
"Enable them in Platform Settings before changing field "
|
||||
"mappings."
|
||||
),
|
||||
)
|
||||
if existing_mappings:
|
||||
workflow_configurations["external_pbx_field_mappings"] = (
|
||||
existing_mappings
|
||||
)
|
||||
except WorkflowConfigurationNotFoundError as exc:
|
||||
raise HTTPException(status_code=404, detail=str(exc)) from exc
|
||||
except ExternalPBXConfigurationDisabledError as exc:
|
||||
raise HTTPException(status_code=403, detail=str(exc)) from exc
|
||||
if workflow_configurations and workflow_configurations.get(
|
||||
WORKFLOW_MODEL_CONFIGURATION_V2_OVERRIDE_KEY
|
||||
):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue