MT#6693 Let subadmins edit subscriber profile.

agranig/subprof
Andreas Granig 12 years ago
parent 8c867420e8
commit 202b9c9f39

@ -238,6 +238,18 @@ sub denied_page :Private {
$c->response->status(403);
}
sub emptyajax :Chained('/') :PathPart('emptyajax') :Args(0) {
my ($self, $c) = @_;
$c->stash(
aaData => [],
iTotalDisplayRecords => 0,
iTotalRecords => 0,
sEcho => $c->request->params->{sEcho} // 1,
);
$c->detach( $c->view("JSON") );
}
__PACKAGE__->meta->make_immutable;
1;

@ -162,6 +162,7 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) :Does(ACL) :AC
->find({domain => $billing_domain->domain});
my $reseller = $contract->contact->reseller;
my ($profile_set, $profile);
if($form->values->{profile_set}{id}) {
my $profile_set_rs = $c->model('DB')->resultset('voip_subscriber_profile_sets');
@ -182,11 +183,17 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) :Does(ACL) :AC
return;
}
delete $form->values->{profile_set};
}
if($form->values->{profile}{id}) {
$profile = $profile_set->voip_subscriber_profiles->find({
id => $form->values->{profile}{id},
});
delete $form->values->{profile};
}
if($profile_set && !$profile) {
$profile = $profile_set->voip_subscriber_profiles->find({
set_default => 1,
});
# TODO should we report an error if no default profile is found? Otherwise
# the subscriber has full feature access.
}
my $billing_subscriber = $contract->voip_subscribers->create({
@ -1809,7 +1816,8 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
$c->stash(customer_id => $subscriber->contract->id);
$form = NGCP::Panel::Form::Customer::PbxExtensionSubscriberEditSubadminNoGroup->new(ctx => $c);
} else {
$form = NGCP::Panel::Form::SubscriberEdit->new;
$form = NGCP::Panel::Form::SubscriberEdit->new(ctx => $c);
$is_admin = 1;
}
}
@ -1944,18 +1952,29 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
return;
}
delete $form->values->{profile_set};
$prov_params->{profile_set_id} = $profile_set->id;
} else {
$profile_set = $prov_subscriber->voip_subscriber_profile_set;
}
if($profile_set && $form->values->{profile}{id}) {
$profile = $profile_set->voip_subscriber_profiles->find({
id => $form->values->{profile}{id},
});
}
if($profile_set && !$profile) {
$profile = $profile_set->voip_subscriber_profiles->find({
set_default => 1,
});
}
if($c->user->roles eq "admin" || $c->user->roles eq "reseller") {
$prov_params->{profile_set_id} = $profile_set ? $profile_set->id : undef;
$prov_params->{profile_id} = $profile ? $profile->id : undef;
# TODO should we report an error if no default profile is found? Otherwise
# the subscriber has full feature access.
} else {
$prov_params->{profile_set_id} = undef;
$prov_params->{profile_id} = undef;
# if the subscriberadmin set the profile, then use it; otherwise
# keep it at old value (e.g. if he unset it)
if($prov_subscriber->voip_subscriber_profile_set && $profile) {
$prov_params->{profile_id} = $profile->id;
}
}
$prov_subscriber->update($prov_params);

@ -54,6 +54,16 @@ sub set_ajax :Chained('set_list') :PathPart('ajax') :Args(0) :Does(ACL) :ACLDeta
$c->detach( $c->view("JSON") );
}
sub set_ajax_reseller :Chained('set_list') :PathPart('ajax/reseller') :Args(1) :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) {
my ($self, $c, $reseller_id) = @_;
my $rs = $c->stash->{set_rs};
$rs = $rs->search({
reseller_id => $reseller_id,
});
NGCP::Panel::Utils::Datatables::process($c, $rs, $c->stash->{set_dt_columns});
$c->detach( $c->view("JSON") );
}
sub set_base :Chained('set_list') :PathPart('') :CaptureArgs(1) {
my ($self, $c, $set_id) = @_;
@ -279,6 +289,7 @@ sub profile_list :Chained('set_base') :PathPart('profile') :CaptureArgs(0) {
$c->stash->{profile_dt_columns} = NGCP::Panel::Utils::Datatables::set_columns($c, [
{ name => 'id', search => 1, title => $c->loc('#') },
{ name => 'profile_set.name', search => 0, title => $c->loc('Profile Set') },
{ name => 'name', search => 1, title => $c->loc('Name') },
{ name => 'description', search => 1, title => $c->loc('Description') },
{ name => 'set_default', search => 0, title => $c->loc('Default') },

@ -7,7 +7,7 @@ has '+widget' => (default => ''); # leave this empty, as there is no widget ...
has 'template' => ( isa => 'Str',
is => 'rw',
default => 'helpers/datatables_field.tt' );
has 'ajax_src' => ( isa => 'Str', is => 'rw' );
has 'ajax_src' => ( isa => 'Str', is => 'rw', default => '/emptyajax' );
has 'table_fields' => ( isa => 'ArrayRef', is => 'rw' );
has 'table_titles' => ( isa => 'ArrayRef', is => 'rw' );
has 'language_file' => (isa => 'Str', is => 'rw', default => 'dataTables.default.js' );

@ -0,0 +1,25 @@
package NGCP::Panel::Field::SubscriberProfile;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Field::Compound';
has_field 'id' => (
type => '+NGCP::Panel::Field::DataTable',
label => 'Profile',
do_label => 0,
do_wrapper => 0,
required => 1,
template => 'helpers/datatables_field.tt',
table_titles => ['#', 'Profile Set', 'Name', 'Description'],
table_fields => ['id', 'profile_set_name', 'name', 'description'],
);
=pod
has_field 'create' => (
type => 'Button',
do_label => 0,
value => 'Create Profile Set',
element_class => [qw/btn btn-tertiary pull-right/],
);
=cut
1;

@ -19,7 +19,7 @@ has_field 'alias_select' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/group extension display_name webusername webpassword password external_id alias_select profile_set/ ],
render_list => [qw/group extension display_name webusername webpassword password external_id alias_select profile/ ],
);
sub update_fields {
@ -37,6 +37,13 @@ sub update_fields {
$c->uri_for_action('/customer/pbx_group_ajax', [$c->stash->{customer_id}])->as_string
);
my $profile_set = $c->stash->{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
);
}
$self->field('password')->required(0); # optional on edit
}

@ -19,7 +19,7 @@ has_field 'alias_select' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/display_name webusername webpassword password external_id alias_select profile_set/ ],
render_list => [qw/display_name webusername webpassword password external_id alias_select profile/ ],
);
sub update_fields {
@ -32,6 +32,13 @@ sub update_fields {
"".$c->uri_for_action("/subscriber/aliases_ajax", $c->req->captures)
);
my $profile_set = $c->stash->{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
);
}
$self->field('password')->required(0); # optional on edit
}

@ -83,7 +83,7 @@ has_field 'external_id' => (
has_field 'profile_set' => (
type => '+NGCP::Panel::Field::SubscriberProfileSet',
label => 'Subscriber Profile',
label => 'Subscriber Profile Set',
validate_when_empty => 0,
element_attr => {
rel => ['tooltip'],
@ -91,6 +91,16 @@ has_field 'profile_set' => (
},
);
has_field 'profile' => (
type => '+NGCP::Panel::Field::SubscriberProfile',
label => 'Subscriber Profile',
validate_when_empty => 0,
element_attr => {
rel => ['tooltip'],
title => ['The profile defining the actual feature set for this subscriber.']
},
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
@ -102,7 +112,7 @@ 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/ ],
render_list => [qw/display_name webusername webpassword username password status external_id profile_set profile/ ],
);
has_block 'actions' => (

@ -113,7 +113,7 @@ has_field 'external_id' => (
has_field 'profile_set' => (
type => '+NGCP::Panel::Field::SubscriberProfileSet',
label => 'Profile Set',
label => 'Subscriber Profile Set',
validate_when_empty => 0,
element_attr => {
rel => ['tooltip'],
@ -121,6 +121,16 @@ has_field 'profile_set' => (
},
);
has_field 'profile' => (
type => '+NGCP::Panel::Field::SubscriberProfile',
label => 'Subscriber Profile',
validate_when_empty => 0,
element_attr => {
rel => ['tooltip'],
title => ['The profile defining the actual feature set for this subscriber.']
},
);
has_field 'save' => (
type => 'Submit',
value => 'Save',
@ -132,7 +142,7 @@ has_field 'save' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/e164 alias_number alias_number_add webusername webpassword password lock status external_id administrative profile_set/ ],
render_list => [qw/e164 alias_number alias_number_add webusername webpassword password lock status external_id administrative profile_set profile/ ],
);
has_block 'actions' => (
@ -141,6 +151,26 @@ has_block 'actions' => (
render_list => [qw/save/],
);
sub field_list {
my ($self) = @_;
my $c = $self->ctx;
return unless($c);
my $profile_set = $self->field('profile_set');
$profile_set->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/set_ajax_reseller', [$c->stash->{subscriber}->contract->contact->reseller_id])->as_string
);
my $set_id = $c->stash->{subscriber}->provisioning_voip_subscriber->profile_set_id;
if($set_id) {
my $profile = $self->field('profile');
$profile->field('id')->ajax_src(
$c->uri_for_action('/subscriberprofile/profile_ajax', [$set_id])->as_string
);
}
}
1;
# vim: set tabstop=4 expandtab:

Loading…
Cancel
Save