MT#6693 Add separate form for subadmin pbx flow.

agranig/subprof
Andreas Granig 12 years ago
parent 340542c55c
commit 17d4140b64

@ -9,6 +9,7 @@ use NGCP::Panel::Form::CustomerBalance;
use NGCP::Panel::Form::Customer::Subscriber;
use NGCP::Panel::Form::Customer::PbxAdminSubscriber;
use NGCP::Panel::Form::Customer::PbxExtensionSubscriber;
use NGCP::Panel::Form::Customer::PbxExtensionSubscriberSubadmin;
use NGCP::Panel::Form::Customer::PbxGroupBase;
use NGCP::Panel::Form::Customer::PbxGroup;
use NGCP::Panel::Form::Customer::PbxFieldDevice;
@ -499,6 +500,9 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) {
my $posted = ($c->request->method eq 'POST');
my $admin_subscribers = NGCP::Panel::Utils::Subscriber::get_admin_subscribers(
voip_subscribers => $c->stash->{subscribers});
$c->stash->{admin_subscriber} = $c->model('DB')->resultset('voip_subscribers')->find(
$admin_subscribers->[0]->{id},
);
if($c->config->{features}->{cloudpbx} && $pbx) {
$c->stash(customer_id => $c->stash->{contract}->id);
@ -507,7 +511,11 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) {
$pbxadmin = 1;
$form = NGCP::Panel::Form::Customer::PbxAdminSubscriber->new(ctx => $c);
} else {
$form = NGCP::Panel::Form::Customer::PbxExtensionSubscriber->new(ctx => $c);
if($c->user->roles eq "subscriberadmin") {
$form = NGCP::Panel::Form::Customer::PbxExtensionSubscriberSubadmin->new(ctx => $c);
} else {
$form = NGCP::Panel::Form::Customer::PbxExtensionSubscriber->new(ctx => $c);
}
}
} else {
$form = NGCP::Panel::Form::Customer::Subscriber->new;
@ -569,6 +577,10 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) {
if($default_sound_set) {
$preferences->{contract_sound_set} = $default_sound_set->id;
}
if($c->stash->{admin_subscriber}) {
my $profile_set = $c->stash->{admin_subscriber}->provisioning_voip_subscriber->voip_subscriber_profile_set;
$form->params->{profile_set}{id} = $profile_set->id;
}
# TODO: if number changes, also update cloud_pbx_base_cli

@ -223,6 +223,8 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) :Does(ACL) :ACLDetachTo('/d
);
if($posted && $form->validated) {
# TODO: why is this needed here?
delete $form->params->{back};
try {
$c->model('DB')->txn_do(sub {
$form->params->{contract_id} = delete $form->params->{contract}{id};

@ -0,0 +1,71 @@
package NGCP::Panel::Form::Customer::PbxExtensionSubscriberSubadmin;
use HTML::FormHandler::Moose;
use NGCP::Panel::Field::PosInteger;
extends 'NGCP::Panel::Form::Customer::PbxSubscriber';
has_field 'group' => (
type => '+NGCP::Panel::Field::PbxGroup',
label => 'Group',
validate_when_empty => 1,
);
has_field 'extension' => (
type => '+NGCP::Panel::Field::PosInteger',
element_attr => {
rel => ['tooltip'],
title => ['Extension Number, e.g. 101']
},
required => 1,
label => 'Extension',
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/group extension display_name webusername webpassword username password status profile/ ],
);
sub field_list {
my $self = shift;
my $c = $self->ctx;
return unless $c;
my $group = $self->field('group');
$group->field('id')->ajax_src(
$c->uri_for_action('/customer/pbx_group_ajax', [$c->stash->{customer_id}])->as_string
);
my $profile_set = $c->stash->{admin_subscriber}->provisioning_voip_subscriber->voip_subscriber_profile_set;
if($profile_set) {
$self->field('profile')->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/profile_ajax', [$profile_set->id])->as_string
);
}
}
1;
=head1 NAME
NGCP::Panel::Form::Subscriber
=head1 DESCRIPTION
Form to modify a subscriber.
=head1 METHODS
=head1 AUTHOR
Gerhard Jungwirth
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# vim: set tabstop=4 expandtab:

@ -112,7 +112,8 @@ has_field 'save' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/display_name webusername webpassword username password status external_id profile_set profile/ ],
#render_list => [qw/display_name webusername webpassword username password status external_id profile_set profile/ ],
render_list => [qw/display_name webusername webpassword username password status profile_set profile/ ],
);
has_block 'actions' => (

@ -155,10 +155,17 @@ sub create_subscriber {
$c->log->error("invalid subscriber profile set id '".$params->{profile_set}{id}."' detected");
return;
}
if($params->{profile}{id}) {
$profile = $profile_set->voip_subscriber_profiles->find({
id => $params->{profile}{id},
});
}
# TODO: use profile from user input if given
$profile = $profile_set->voip_subscriber_profiles->find({
set_default => 1,
});
unless($profile) {
$profile = $profile_set->voip_subscriber_profiles->find({
set_default => 1,
});
}
}
$schema->txn_do(sub {

Loading…
Cancel
Save