@ -9,7 +9,7 @@ use NGCP::Panel::Utils::Auth;
use HTTP::Status qw( :constants ) ;
use HTTP::Status qw( :constants ) ;
sub allowed_methods {
sub allowed_methods {
return [ qw/GET OPTIONS HEAD DELETE/] ;
return [ qw/GET OPTIONS HEAD PATCH PUT DELETE/] ;
}
}
sub journal_query_params {
sub journal_query_params {
@ -23,6 +23,42 @@ sub get_journal_methods{
__PACKAGE__ - > set_config ( ) ;
__PACKAGE__ - > set_config ( ) ;
sub PATCH :Allow {
my ( $ self , $ c , $ id ) = @ _ ;
my $ guard = $ c - > model ( 'DB' ) - > txn_scope_guard ;
{
my $ preference = $ self - > require_preference ( $ c ) ;
last unless $ preference ;
my $ json = $ self - > get_valid_patch_data (
c = > $ c ,
id = > $ id ,
media_type = > 'application/json-patch+json' ,
) ;
last unless $ json ;
my $ item = $ self - > item_by_id ( $ c , $ id ) ;
last unless $ self - > resource_exists ( $ c , admin = > $ item ) ;
my $ old_resource = { $ item - > get_inflated_columns } ;
#use saltedpass so we have a password field for applying patch
#we later check in update_item and if the password field is still
#the same with saltedpass we don't update the password
$ old_resource - > { password } = $ old_resource - > { salted_pass } ;
my $ resource = $ self - > apply_patch ( $ c , $ old_resource , $ json ) ;
last unless $ resource ;
my $ form = $ self - > get_form ( $ c ) ;
$ item = $ self - > update_item ( $ c , $ item , $ old_resource , $ resource , $ form ) ;
last unless $ item ;
$ guard - > commit ;
$ self - > return_representation ( $ c , 'item' = > $ item , 'form' = > $ form , 'preference' = > $ preference ) ;
}
return ;
}
sub delete_item {
sub delete_item {
my ( $ self , $ c , $ item ) = @ _ ;
my ( $ self , $ c , $ item ) = @ _ ;
@ -52,19 +88,6 @@ sub delete_item {
return 1 ;
return 1 ;
}
}
#we do not use update_item for the admins now, as we do not allo PUT and PATCH
sub update_item_model {
my ( $ self , $ c , $ item , $ old_resource , $ resource , $ form ) = @ _ ;
if ( $ old_resource - > { login } eq NGCP::Panel::Utils::Auth:: get_special_admin_login ( ) ) {
my $ active = $ resource - > { is_active } ;
$ resource = $ old_resource ;
$ resource - > { is_active } = $ active ;
}
$ item - > update ( $ resource ) ;
return $ item ;
}
1 ;
1 ;
# vim: set tabstop=4 expandtab:
# vim: set tabstop=4 expandtab: