From 8481c5adb7b713bb521028f349d8596b73df37e2 Mon Sep 17 00:00:00 2001 From: Rene Krenn Date: Wed, 18 Mar 2026 12:51:30 +0100 Subject: [PATCH] MT#64761 prov templates: support contract-only mode provisioning templates basically work on subscriber level. this change introduces support for processing files with contract data only. Change-Id: I2f75aaf01e70b1348549c957ab68faf0d786bca9 --- lib/NGCP/Panel/Utils/ProvisioningTemplates.pm | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm b/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm index 2f6c3b9086..853b7159eb 100644 --- a/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm +++ b/lib/NGCP/Panel/Utils/ProvisioningTemplates.pm @@ -137,10 +137,12 @@ sub validate_template { my ($data,$prefix) = @_; $prefix //= 'template: '; die($prefix . "not a hash\n") unless 'HASH' eq ref $data; - foreach my $section (qw/subscriber/) { - die($prefix . "section '$section' required\n") unless exists $data->{$section}; - die($prefix . "section '$section' is not a hash\n") unless 'HASH' eq ref $data->{$section}; - } + # todo: validate fields + + #foreach my $section (qw/subscriber/) { + # die($prefix . "section '$section' required\n") unless exists $data->{$section}; + # die($prefix . "section '$section' is not a hash\n") unless 'HASH' eq ref $data->{$section}; + #} } @@ -263,11 +265,19 @@ sub create_provisioning_template_form { c => $c, context => $context, ); - NGCP::Panel::Utils::Message::info( - c => $c, - data => \%log_data, - desc => $c->loc("Provisioning template '[_1]' done: subscriber [_2] created", $template, $context->{subscriber}->{username} . '@' . $context->{domain}->{domain}), - ); + if (exists $context->{subscriber}) { + NGCP::Panel::Utils::Message::info( + c => $c, + data => \%log_data, + desc => $c->loc("Provisioning template '[_1]' done: subscriber [_2] processed", $template, $context->{subscriber}->{username} . '@' . $context->{domain}->{domain}), + ); + } else { + NGCP::Panel::Utils::Message::info( + c => $c, + data => \%log_data, + desc => $c->loc("Provisioning template '[_1]' done: contract [_2] processed", $template, $context->{contract}->{id}), + ); + } } catch($e) { provision_cleanup($c, $context); NGCP::Panel::Utils::Message::error( @@ -695,7 +705,11 @@ sub provision_commit_row { #die(); $guard->commit; - $c->log->debug("provisioning template $template done: " . $context->{subscriber}->{username} . '@' . $context->{domain}->{domain}); + if (exists $context->{subscriber}) { + $c->log->debug("provisioning template $template done: " . $context->{subscriber}->{username} . '@' . $context->{domain}->{domain}); + } else { + $c->log->debug("provisioning template $template done: contract id " . $context->{contract}->{id}); + } } @@ -936,7 +950,7 @@ sub _init_subscriber_context { my ($c, $context, $schema, $template) = @_; - { + if (exists $template->{subscriber}) { my @identifiers = _get_identifiers($template->{subscriber}); my %subscriber = (); foreach my $col (keys %{$template->{subscriber}}) { @@ -1150,9 +1164,10 @@ sub _init_trusted_sources_context { my ($c, $context, $schema, $template) = @_; - my $subscriber = $schema->resultset('voip_subscribers')->find({ + my $subscriber; + $subscriber = $schema->resultset('voip_subscribers')->find({ id => $context->{subscriber}->{id}, - }); + }) if exists $context->{subscriber}; foreach my $template_trusted_source (@{_force_array($template->{trusted_sources})}) { my %trusted_source = (); @@ -1294,7 +1309,7 @@ sub _create_subscriber { my ($c, $context, $schema) = @_; - unless ($context->{subscriber}->{id}) { + if (exists $context->{subscriber} and not $context->{subscriber}->{id}) { my $error_info = { extended => {} }; my @events_to_create = (); @@ -1396,9 +1411,10 @@ sub _create_registrations { my ($c, $context, $schema) = @_; - my $subscriber = $schema->resultset('voip_subscribers')->find({ + my $subscriber; + $subscriber = $schema->resultset('voip_subscribers')->find({ id => $context->{subscriber}->{id}, - }); + }) if exists $context->{subscriber}; foreach my $registration (@{$context->{registrations}}) { my $ret = NGCP::Panel::Utils::Kamailio::create_location($c,