MT#4955 Introduce customer default sound sets.

If a new contract sound set is marked as contract_default, use this
for every existing subscriber in contract_sound_set prefs if no
other set is specified yet.
If a new subscriber is created and such a sound set exists, also
use this one.

This prevents having to go over each single subscriber to assign
the contract_sound_set preference.
gjungwirth/fix_tests
Andreas Granig 12 years ago
parent 224ca10e8d
commit f9e96aad30

@ -517,12 +517,18 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) {
}
if($pbx) {
$preferences->{cloud_pbx} = 1;
if($form->params->{e164}{cc} && $form->params->{e164}{sn}) {
if($pbxadmin && $form->params->{e164}{cc} && $form->params->{e164}{sn}) {
$preferences->{cloud_pbx_base_cli} = $form->params->{e164}{cc} .
($form->params->{e164}{ac} // '') .
$form->params->{e164}{sn};
}
# if there is a contract default sound set, use it.
my $default_sound_set = $c->stash->{contract}->voip_sound_sets->search({ contract_default => 1 })->first;
if($default_sound_set) {
$preferences->{contract_sound_set} = $default_sound_set->id;
}
# TODO: if number changes, also update cloud_pbx_base_cli
# TODO: only if it's not a fax/conf extension:

@ -202,7 +202,21 @@ sub delete :Chained('base') :PathPart('delete') {
my ($self, $c) = @_;
try {
$c->stash->{set_result}->delete;
my $schema = $c->model('DB');
$schema->txn_do(sub {
# remove all usr_preferenes where this set is assigned
my $pref_rs = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => 'contract_sound_set',
);
$pref_rs->search({ value => $c->stash->{set_result}->id })
->delete_all;
# TODO: what about normal sound_sets for usr/dom/peer?
$c->stash->{set_result}->delete;
});
$c->flash(messages => [{type => 'success', text => 'Sound set successfully deleted'}]);
} catch($e) {
$c->log->error("failed to delete sound set: $e");
@ -211,8 +225,8 @@ sub delete :Chained('base') :PathPart('delete') {
NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/sound'));
}
sub create :Chained('sets_list') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
sub create :Chained('sets_list') :PathPart('create') :Args() {
my ($self, $c, $contract_id) = @_;
my $posted = ($c->request->method eq 'POST');
my $form;
@ -220,8 +234,21 @@ sub create :Chained('sets_list') :PathPart('create') :Args(0) {
$params = $params->merge($c->session->{created_objects});
if($c->user->roles eq "admin") {
$form = NGCP::Panel::Form::Sound::AdminSet->new;
if($contract_id) {
my $contract = $c->model('DB')->resultset('contracts')->find($contract_id);
if($contract) {
$params->{contract}{id} = $contract->id;
$params->{reseller}{id} = $contract->contact->reseller_id;
}
}
} elsif($c->user->roles eq "reseller") {
$form = NGCP::Panel::Form::Sound::ResellerSet->new;
if($contract_id) {
my $contract = $c->model('DB')->resultset('contracts')->find($contract_id);
if($contract && $contract->contact->reseller_id == $c->user->reseller_id) {
$params->{contract}{id} = $contract->id;
}
}
} else {
$form = NGCP::Panel::Form::Sound::CustomerSet->new;
}
@ -244,17 +271,54 @@ sub create :Chained('sets_list') :PathPart('create') :Args(0) {
if($c->user->roles eq "admin") {
$form->values->{reseller_id} = $form->values->{reseller}{id};
$form->values->{contract_id} = $form->values->{contract}{id} // undef;
if(defined $form->values->{contract_id}) {
$form->values->{contract_default} //= 0;
} else {
$form->values->{contract_default} = 0;
}
} elsif($c->user->roles eq "reseller") {
$form->values->{reseller_id} = $c->user->reseller_id;
$form->values->{contract_id} = $form->values->{contract}{id} // undef;
if(defined $form->values->{contract_id}) {
$form->values->{contract_default} //= 0;
} else {
$form->values->{contract_default} = 0;
}
} else {
$form->values->{reseller_id} = $c->user->contract->contact->reseller_id;
$form->values->{contract_id} = $c->user->account_id;
$form->values->{contract_default} //= 0;
}
delete $form->values->{reseller};
delete $form->values->{contract};
$c->stash->{sets_rs}->create($form->values);
my $schema = $c->model('DB');
$schema->txn_do(sub {
my $set = $c->stash->{sets_rs}->create($form->values);
if($set->contract_default == 1) {
# go over each subscriber in the contract and set the contract_sound_set
# preference if it doesn't have one set yet
my $contract;
if($c->user->roles eq "admin" || $c->user->roles eq "reseller") {
$contract = $schema->resultset('contracts')->find($form->values->{contract_id});
} else {
$contract = $c->user->contract;
}
foreach my $bill_subscriber($contract->voip_subscribers->all) {
my $prov_subscriber = $bill_subscriber->provisioning_voip_subscriber;
if($prov_subscriber) {
my $pref_rs = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, prov_subscriber => $prov_subscriber, attribute => 'contract_sound_set',
);
unless($pref_rs->first) {
$pref_rs->create({ value => $set->id });
}
}
}
}
});
delete $c->session->{created_objects}->{reseller};
$c->flash(messages => [{type => 'success', text => 'Sound set successfully created'}]);
} catch($e) {

@ -18,7 +18,7 @@ has_field 'contract' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/reseller contract name description/],
render_list => [qw/reseller contract name description contract_default/],
);
1;

@ -21,6 +21,15 @@ has_field 'description' => (
type => 'Text',
);
has_field 'contract_default' => (
type => 'Boolean',
label => 'Default for Subscribers',
element_attr => {
rel => ['tooltip'],
title => ['If active, this sound set is used for all existing and new subscribers if no specific sound set is specified for them'],
},
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
@ -31,7 +40,7 @@ has_field 'save' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/name description/],
render_list => [qw/name description contract_default/],
);
has_block 'actions' => (

@ -27,6 +27,15 @@ has_field 'description' => (
type => 'Text',
);
has_field 'contract_default' => (
type => 'Boolean',
label => 'Default for Subscribers',
element_attr => {
rel => ['tooltip'],
title => ['If active and a customer is selected, this sound set is used for all existing and new subscribers within this customer if no specific sound set is specified for the subscribers'],
},
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
@ -37,7 +46,7 @@ has_field 'save' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/contract name description/],
render_list => [qw/contract name description contract_default/],
);
has_block 'actions' => (

@ -432,14 +432,17 @@ sub get_usr_preference_rs {
my $c = $params{c};
my $attribute = $params{attribute};
my $prov_subscriber= $params{prov_subscriber};
my $prov_subscriber = $params{prov_subscriber};
my $preference = $c->model('DB')->resultset('voip_preferences')->find({
my $pref_rs = $c->model('DB')->resultset('voip_preferences')->find({
attribute => $attribute, 'usr_pref' => 1,
})->voip_usr_preferences->search_rs({
subscriber_id => $prov_subscriber->id,
});
return $preference;
})->voip_usr_preferences;
if($prov_subscriber) {
$pref_rs = $pref_rs->search({
subscriber_id => $prov_subscriber->id,
});
}
return $pref_rs;
}
sub get_dom_preference_rs {

@ -332,7 +332,7 @@
{ name = 'Files', uri = "/sound/'+full.id+'/handles", class = 'btn-small btn-tertiary', icon = 'icon-list' },
];
helper.top_buttons = [
{ name = 'Create Sound Set', uri = c.uri_for('/sound/create'), icon = 'icon-star', accordion_button = 1 },
{ name = 'Create Sound Set', uri = c.uri_for_action('/sound/create', c.req.captures.0), icon = 'icon-star', accordion_button = 1 },
];
ELSE;
helper.dt_buttons = [

Loading…
Cancel
Save