@ -21,13 +21,12 @@ sub config_allowed_roles {
}
}
sub _item_rs {
sub _item_rs {
my ( $ self , $ c , $ type ) = @ _ ;
my ( $ self , $ c , $ by_id ) = @ _ ;
my $ item_rs = $ c - > model ( 'DB' ) - > resultset ( 'voip_header_rules' ) - > search_rs ( undef , {
my $ item_rs = $ c - > model ( 'DB' ) - > resultset ( 'voip_header_rules' ) - > search_rs ( undef , {
join = > 'ruleset'
join = > 'ruleset'
} ) ;
} ) ;
if ( $ c - > user - > roles eq "reseller" ) {
if ( $ c - > user - > roles eq "reseller" ) {
$ item_rs = $ c - > model ( 'DB' ) - > resultset ( 'voip_header_rules' ) - > search_rs ( {
$ item_rs = $ c - > model ( 'DB' ) - > resultset ( 'voip_header_rules' ) - > search_rs ( {
'ruleset.reseller_id' = > $ c - > user - > reseller_id ,
'ruleset.reseller_id' = > $ c - > user - > reseller_id ,
@ -40,7 +39,7 @@ sub _item_rs {
) ;
) ;
$ item_rs = $ item_rs - > search_rs (
$ item_rs = $ item_rs - > search_rs (
{ 'ruleset.subscriber_id' = > $ prov_subscriber_id } ) ;
{ 'ruleset.subscriber_id' = > $ prov_subscriber_id } ) ;
} els e {
} els if ( ! $ by_id ) {
$ item_rs = $ item_rs - > search_rs (
$ item_rs = $ item_rs - > search_rs (
{ 'ruleset.subscriber_id' = > undef } ) ;
{ 'ruleset.subscriber_id' = > undef } ) ;
}
}
@ -48,6 +47,12 @@ sub _item_rs {
return $ item_rs ;
return $ item_rs ;
}
}
sub item_by_id {
my ( $ self , $ c , $ id ) = @ _ ;
my $ item_rs = $ self - > item_rs ( $ c , 1 ) ;
return $ item_rs - > find ( $ id ) ;
}
sub get_form {
sub get_form {
my ( $ self , $ c ) = @ _ ;
my ( $ self , $ c ) = @ _ ;
return ( NGCP::Panel::Form:: get ( "NGCP::Panel::Form::Header::RuleAPI" , $ c ) ) ;
return ( NGCP::Panel::Form:: get ( "NGCP::Panel::Form::Header::RuleAPI" , $ c ) ) ;
@ -64,8 +69,8 @@ sub check_resource {
my ( $ self , $ c , $ item , $ old_resource , $ resource , $ form , $ process_extras ) = @ _ ;
my ( $ self , $ c , $ item , $ old_resource , $ resource , $ form , $ process_extras ) = @ _ ;
my $ schema = $ c - > model ( 'DB' ) ;
my $ schema = $ c - > model ( 'DB' ) ;
unless ( defined $ resource - > { set _id} ) {
unless ( $ resource - > { set_id } || $ resource - > { subscriber _id} ) {
$ self - > error ( $ c , HTTP_UNPROCESSABLE_ENTITY , "Required: 'set_id' ") ;
$ self - > error ( $ c , HTTP_UNPROCESSABLE_ENTITY , "Required: 'set_id' or 'subscriber_id' ") ;
return ;
return ;
}
}
@ -74,6 +79,7 @@ sub check_resource {
$ reseller_id = $ c - > user - > reseller_id ;
$ reseller_id = $ c - > user - > reseller_id ;
}
}
if ( $ resource - > { set_id } ) {
my $ ruleset = $ schema - > resultset ( 'voip_header_rule_sets' ) - > find ( {
my $ ruleset = $ schema - > resultset ( 'voip_header_rule_sets' ) - > find ( {
id = > $ resource - > { set_id } ,
id = > $ resource - > { set_id } ,
( $ reseller_id ? ( reseller_id = > $ reseller_id ) : ( ) ) ,
( $ reseller_id ? ( reseller_id = > $ reseller_id ) : ( ) ) ,
@ -82,8 +88,24 @@ sub check_resource {
$ self - > error ( $ c , HTTP_UNPROCESSABLE_ENTITY , "Invalid 'set_id'." ) ;
$ self - > error ( $ c , HTTP_UNPROCESSABLE_ENTITY , "Invalid 'set_id'." ) ;
return ;
return ;
}
}
$ c - > stash - > { checked } - > { ruleset } = $ ruleset ;
$ c - > stash - > { checked } - > { ruleset } = $ ruleset ;
}
if ( $ resource - > { subscriber_id } ) {
my $ sub = $ schema - > resultset ( 'voip_subscribers' ) - > find ( {
id = > $ resource - > { subscriber_id } ,
status = > { '!=' = > 'terminated' } ,
( $ reseller_id
? ( 'contract.contact.reseller_id' = > $ reseller_id )
: ( ) ) ,
} , {
join = > { 'contract' = > 'contact' } ,
} ) ;
unless ( $ sub ) {
$ self - > error ( $ c , HTTP_UNPROCESSABLE_ENTITY , "Invalid 'subscriber_id'" ) ;
return ;
}
}
return 1 ;
return 1 ;
}
}