use different Forms for BillingProfile when admin/reseller is logged in

reseller cannot create billing_profiles for other resellers/admins...
agranig/1_0_subfix
Gerhard Jungwirth 12 years ago
parent 4ef08be450
commit ae4c3660d7

@ -6,7 +6,8 @@ use I18N::Langinfo qw(langinfo DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7);
BEGIN { extends 'Catalyst::Controller'; }
use NGCP::Panel::Form::BillingProfile;
use NGCP::Panel::Form::BillingProfile_admin;
use NGCP::Panel::Form::BillingProfile_reseller;
use NGCP::Panel::Form::BillingFee;
use NGCP::Panel::Form::BillingZone;
use NGCP::Panel::Form::BillingPeaktimeWeekdays;
@ -27,12 +28,29 @@ sub profile_list :Chained('/') :PathPart('billing') :CaptureArgs(0) {
my ( $self, $c ) = @_;
NGCP::Panel::Utils::check_redirect_chain(c => $c);
my $dispatch_to = '_profile_resultset_' . $c->user->auth_realm;
my $profiles_rs = $self->$dispatch_to($c);
$c->stash(profiles_rs => $profiles_rs);
$c->stash(has_edit => 1);
$c->stash(has_delete => 0);
$c->stash(template => 'billing/list.tt');
}
sub _profile_resultset_admin {
my ($self, $c) = @_;
my $rs = $c->model('billing')->resultset('billing_profiles');
return $rs;
}
sub _profile_resultset_reseller {
my ($self, $c) = @_;
my $rs = $c->model('billing')->resultset('admins')
->find($c->user->id)->reseller->billing_profiles;
return $rs;
}
sub root :Chained('profile_list') :PathPart('') :Args(0) {
my ($self, $c) = @_;
}
@ -40,7 +58,7 @@ sub root :Chained('profile_list') :PathPart('') :Args(0) {
sub ajax :Chained('profile_list') :PathPart('ajax') :Args(0) {
my ($self, $c) = @_;
my $resultset = $c->model('billing')->resultset('billing_profiles');
my $resultset = $c->stash->{profiles_rs};
$c->forward( "/ajax_process_resultset", [$resultset,
["id", "name"],
@ -58,7 +76,7 @@ sub base :Chained('profile_list') :PathPart('') :CaptureArgs(1) {
return;
}
my $res = $c->model('billing')->resultset('billing_profiles')->find($profile_id);
my $res = $c->stash->{profiles_rs}->find($profile_id);
unless(defined($res)) {
$c->flash(messages => [{type => 'error', text => 'Billing Profile does not exist!'}]);
$c->response->redirect($c->uri_for());
@ -72,15 +90,15 @@ sub edit :Chained('base') :PathPart('edit') {
my ($self, $c) = @_;
my $posted = ($c->request->method eq 'POST');
my $form = NGCP::Panel::Form::BillingProfile->new;
my $dispatch_to = 'NGCP::Panel::Form::BillingProfile_' . $c->user->auth_realm;
my $form = $dispatch_to->new;
$form->process(
posted => 1,
params => $posted ? $c->request->params : $c->stash->{profile},
posted => $posted,
params => $c->request->params,
action => $c->uri_for($c->stash->{profile}->{id}, 'edit'),
item => $c->stash->{profile_result},
);
if($posted && $form->validated) {
$c->model('billing')->resultset('billing_profiles')
->find($form->field('id')->value)->update($form->fif);
$c->flash(messages => [{type => 'success', text => 'Billing Profile successfully changed!'}]);
$c->response->redirect($c->uri_for());
@ -94,15 +112,15 @@ sub edit :Chained('base') :PathPart('edit') {
sub create :Chained('profile_list') :PathPart('create') :Args(0) {
my ($self, $c) = @_;
my $form = NGCP::Panel::Form::BillingProfile->new;
my $dispatch_to = 'NGCP::Panel::Form::BillingProfile_' . $c->user->auth_realm;
my $form = $dispatch_to->new;
$form->process(
posted => ($c->request->method eq 'POST'),
params => $c->request->params,
action => $c->uri_for('create'),
item => $c->stash->{profiles_rs}->new_result({}),
);
if($form->validated) {
$c->model('billing')->resultset('billing_profiles')->create(
$form->fif() );
$c->flash(messages => [{type => 'success', text => 'Billing profile successfully created!'}]);
$c->response->redirect($c->uri_for());
return;

@ -0,0 +1,21 @@
package NGCP::Panel::Form::BillingProfile_admin;
use HTML::FormHandler::Moose;
extends 'NGCP::Panel::Form::BillingProfile_reseller';
has_field 'reseller' => (
type => '+NGCP::Panel::Field::Reseller',
);
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/handle name interval_charge interval_free_time interval_free_cash
fraud_interval_limit fraud_interval_lock fraud_interval_notify
fraud_daily_limit fraud_daily_lock fraud_daily_notify
currency vat_rate vat_included reseller id/],
);
1;
# vim: set tabstop=4 expandtab:

@ -1,7 +1,7 @@
package NGCP::Panel::Form::BillingProfile;
package NGCP::Panel::Form::BillingProfile_reseller;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
extends 'HTML::FormHandler::Model::DBIC';
use Moose::Util::TypeConstraints;
use HTML::FormHandler::Widget::Block::Bootstrap;
@ -20,6 +20,11 @@ has_field 'name' => (
maxlength => 31,
);
has_field 'handle' => (
type => 'Text',
required => 1,
);
has_field 'interval_charge' => (
type => 'Money',
);
@ -102,7 +107,7 @@ has_field 'save' => (
has_block 'fields' => (
tag => 'div',
class => [qw/modal-body/],
render_list => [qw/name interval_charge interval_free_time interval_free_cash
render_list => [qw/handle name interval_charge interval_free_time interval_free_cash
fraud_interval_limit fraud_interval_lock fraud_interval_notify
fraud_daily_limit fraud_daily_lock fraud_daily_notify
currency vat_rate vat_included id/],
@ -114,5 +119,12 @@ has_block 'actions' => (
render_list => [qw/save/],
);
before 'update_model' => sub {
my $self = shift;
foreach my $val(values $self->value) {
$val = '' unless defined($val);
}
};
1;
# vim: set tabstop=4 expandtab:
Loading…
Cancel
Save