MT#7793 Implement event billing for subprofiles.

Write start/end/update_profile event on subscriber modification.
gjungwirth/voicemail_number
Andreas Granig 12 years ago
parent 90c2eda399
commit 213e6bb606

@ -16,6 +16,7 @@ use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Utils::Sems;
use NGCP::Panel::Utils::Hylafax;
use NGCP::Panel::Utils::Kamailio;
use NGCP::Panel::Utils::Events;
use NGCP::Panel::Form::Subscriber;
use NGCP::Panel::Form::SubscriberEdit;
use NGCP::Panel::Form::Customer::PbxSubscriberEdit;
@ -2099,6 +2100,7 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
}
}
my $old_profile = $prov_subscriber->profile_id;
my ($profile_set, $profile);
if($form->values->{profile_set}{id}) {
my $profile_set_rs = $c->model('DB')->resultset('voip_subscriber_profile_sets');
@ -2172,6 +2174,21 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
$prov_subscriber->update($prov_params);
if($prov_subscriber->profile_id // 0 != $old_profile) {
my $type;
if(defined $prov_subscriber->profile_id && defined $old_profile) {
$type = "update_profile";
} elsif(defined $prov_subscriber->profile_id) {
$type = "start_profile";
} else {
$type = "end_profile";
}
NGCP::Panel::Utils::Events::insert(
c => $c, schema => $schema, subscriber => $subscriber,
type => $type, old => $old_profile, new => $prov_subscriber->profile_id
);
}
my @old_groups = $prov_subscriber->voip_pbx_groups->get_column('group_id')->all;
my $new_group_ids = decode_json($form->value->{group_select});
my @new_groups = ();

@ -17,6 +17,7 @@ use NGCP::Panel::Form::Subscriber::SubscriberAPI;
use NGCP::Panel::Utils::XMLDispatcher;
use NGCP::Panel::Utils::Prosody;
use NGCP::Panel::Utils::Subscriber;
use NGCP::Panel::Utils::Events;
sub get_form {
my ($self, $c) = @_;
@ -452,7 +453,7 @@ sub update_item {
my $alias_numbers = $full_resource->{alias_numbers};
my $preferences = $full_resource->{preferences};
my $groups = $full_resource->{groups};
my $prov_subscriber = $subscriber->provisioning_voip_subscriber;
if($subscriber->provisioning_voip_subscriber->is_pbx_pilot && !$self->is_true($resource->{is_pbx_pilot})) {
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Cannot revoke is_pbx_pilot status from a subscriber.");
@ -590,10 +591,27 @@ sub update_item {
$provisioning_res->{pbx_hunt_policy} = $resource->{pbx_hunt_policy};
$provisioning_res->{pbx_hunt_timeout} = $resource->{pbx_hunt_timeout};
}
my $old_profile = $prov_subscriber->profile_id;
$subscriber->update($billing_res);
$subscriber->provisioning_voip_subscriber->update($provisioning_res);
$subscriber->discard_changes;
if($prov_subscriber->profile_id // 0 != $old_profile) {
my $type;
if(defined $prov_subscriber->profile_id && defined $old_profile) {
$type = "update_profile";
} elsif(defined $prov_subscriber->profile_id) {
$type = "start_profile";
} else {
$type = "end_profile";
}
NGCP::Panel::Utils::Events::insert(
c => $c, schema => $schema, subscriber => $subscriber,
type => $type, old => $old_profile, new => $prov_subscriber->profile_id
);
}
NGCP::Panel::Utils::Subscriber::update_preferences(
c => $c,
prov_subscriber => $subscriber->provisioning_voip_subscriber,

@ -0,0 +1,27 @@
package NGCP::Panel::Utils::Events;
use Sipwise::Base;
sub insert {
my %params = @_;
my $c = $params{c};
my $schema = $params{schema} // $c->model('DB');
my $type = $params{type};
my $subscriber = $params{subscriber};
my $old = $params{old};
my $new = $params{new};
$schema->resultset('events')->create({
type => $type,
subscriber_id => $subscriber->id,
old_status => $old // '',
new_status => $new // '',
timestamp => NGCP::Panel::Utils::DateTime::current_local->hires_epoch,
});
}
1;
# vim: set tabstop=4 expandtab:

@ -8,6 +8,7 @@ use String::MkPasswd;
use NGCP::Panel::Utils::DateTime;
use NGCP::Panel::Utils::Preferences;
use NGCP::Panel::Utils::Email;
use NGCP::Panel::Utils::Events;
use UUID qw/generate unparse/;
use JSON qw/decode_json encode_json/;
@ -287,6 +288,13 @@ sub create_subscriber {
NGCP::Panel::Utils::Email::new_subscriber($c, $billing_subscriber, $url);
}
if($prov_subscriber->profile_id) {
NGCP::Panel::Utils::Events::insert(
c => $c, schema => $schema, subscriber => $billing_subscriber,
type => 'start_profile', old => undef, new => $prov_subscriber->profile_id
);
}
if(defined $params->{e164range} && ref $params->{e164range} eq "ARRAY") {
my @alias_numbers = ();
foreach my $range(@{ $params->{e164range} }) {

Loading…
Cancel
Save