use entry::element_of to set action parameter

This commit is contained in:
Milan
2020-03-08 15:09:07 +01:00
parent 5c73484638
commit accc9393c7
19 changed files with 53 additions and 141 deletions

View File

@@ -11,6 +11,7 @@ use Encode();
use params(); use params();
use config(); use config();
use log(); use log();
use entry();
use template(); use template();
use auth(); use auth();
use uac(); use uac();
@@ -204,15 +205,8 @@ sub check_params {
my $checked = {}; my $checked = {};
#actions and roles $checked->{action} = entry::element_of( $params->{action}, ['assign_series'] );
$checked->{action} = '';
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(assign_series)$/ ) {
$checked->{action} = $params->{action};
}
}
#numeric values
$checked->{exclude} = 0; $checked->{exclude} = 0;
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [
'id', 'project_id', 'studio_id', 'series_id' 'id', 'project_id', 'studio_id', 'series_id'

View File

@@ -352,15 +352,8 @@ sub check_params {
my $checked = {}; my $checked = {};
#actions and roles $checked->{action} = entry::element_of($params->{action}, ['assign_events']);
$checked->{action} = '';
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(assign_events)$/ ) {
$checked->{action} = $params->{action};
}
}
#numeric values
$checked->{exclude} = 0; $checked->{exclude} = 0;
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [
'id', 'project_id', 'studio_id', 'series_id', 'event_id' 'id', 'project_id', 'studio_id', 'series_id', 'event_id'
@@ -389,7 +382,6 @@ sub check_params {
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [
'frequency', 'duration', 'default_duration', 'create_events', 'publish_events', 'live']); 'frequency', 'duration', 'default_duration', 'create_events', 'publish_events', 'live']);
#scalars
entry::set_strings( $checked, $params, entry::set_strings( $checked, $params,
[ 'search', 'from', 'till' ]); [ 'search', 'from', 'till' ]);

View File

@@ -13,6 +13,7 @@ use File::Temp();
use config(); use config();
use log(); use log();
use entry();
use localization(); use localization();
use auth(); use auth();
use uac(); use uac();
@@ -542,8 +543,7 @@ sub check_params {
my $checked = {}; my $checked = {};
$checked->{error} = ''; $checked->{error} = '';
$checked->{template} = $checked->{template} = template::check( $config, $params->{template}, 'upload-audio-recordings' );
template::check( $config, $params->{template}, 'upload-audio-recordings' );
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [
'project_id', 'studio_id', 'default_studio_id', 'series_id', 'event_id', 'id']); 'project_id', 'studio_id', 'default_studio_id', 'series_id', 'event_id', 'id']);
@@ -554,8 +554,11 @@ sub check_params {
$checked->{studio_id} = -1; $checked->{studio_id} = -1;
} }
$checked->{action} = entry::element_of($params->{action},
['update', 'delete']);
entry::set_strings( $checked, $params, [ entry::set_strings( $checked, $params, [
'name', 'description', 'action', 'path' ]); 'name', 'description', 'path' ]);
$checked->{upload} = $params->{upload}; $checked->{upload} = $params->{upload};
return $checked; return $checked;

View File

@@ -242,13 +242,8 @@ sub check_params {
my $checked = {}; my $checked = {};
#actions $checked->{action} = entry::element_of($params->{action},
[ 'setLock', 'setRead', 'showComment', 'update', 'delete']);
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(setLock|setRead|showComment)$/ ) {
$checked->{action} = $params->{action};
}
}
#template #template
my $template = ''; my $template = '';

View File

@@ -202,15 +202,9 @@ sub check_params {
my $checked = {}; my $checked = {};
#actions and roles $checked->{action} = entry::element_of($params->{action},
$checked->{action} = ''; ['create_events', 'show_events']);
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(create_events|show_events)$/ ) {
$checked->{action} = $params->{action};
}
}
#numeric values
$checked->{exclude} = 0; $checked->{exclude} = 0;
$checked->{duration} = 28; $checked->{duration} = 28;
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [

View File

@@ -13,6 +13,7 @@ use Text::Diff::Unified::XS;
use params(); use params();
use config(); use config();
use entry();
use log(); use log();
use template(); use template();
use db(); use db();
@@ -249,7 +250,7 @@ sub check_params {
#numeric values #numeric values
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [
'id', 'project_id', 'studio_id', 'default_studio_id', 'user_id', 'series_id', 'event_id', 'v1', 'v2' ) 'id', 'project_id', 'studio_id', 'default_studio_id', 'user_id', 'series_id', 'event_id', 'v1', 'v2'
]); ]);
if ( defined $checked->{studio_id} ) { if ( defined $checked->{studio_id} ) {
@@ -258,13 +259,8 @@ sub check_params {
$checked->{studio_id} = -1; $checked->{studio_id} = -1;
} }
#actions and roles $checked->{action} = entry::element_of($params->{action}, ['show', 'diff']);
$checked->{action} = '';
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(show|diff)$/ ) {
$checked->{action} = $params->{action};
}
}
return $checked; return $checked;
} }

View File

@@ -843,13 +843,11 @@ sub check_params {
} }
} }
#actions $checked->{action} = entry::element_of($params->{action},
$checked->{action} = ''; [qw{
if ( defined $params->{action} ) {
$checked->{action} = $params->{action} if List::Util::any { $_ eq $params->{action} } qw{
save delete download show_new_event show_new_event_from_schedule save delete download show_new_event show_new_event_from_schedule
create_event create_event_from_schedule get_json create_event create_event_from_schedule get_json
}; }]
} );
return $checked; return $checked;
} }

View File

@@ -370,7 +370,6 @@ sub check_params {
my $checked = {}; my $checked = {};
$checked->{template} = template::check( $config, $params->{template}, 'image-upload' ); $checked->{template} = template::check( $config, $params->{template}, 'image-upload' );
#numeric values
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [
'project_id', 'studio_id', 'default_studio_id' 'project_id', 'studio_id', 'default_studio_id'
]); ]);
@@ -383,7 +382,6 @@ sub check_params {
entry::set_strings( $checked, $params, [ 'action', 'name', 'description', 'licence' ]); entry::set_strings( $checked, $params, [ 'action', 'name', 'description', 'licence' ]);
#checkboxes
entry::set_bools( $checked, $params, [ 'public' ] ); entry::set_bools( $checked, $params, [ 'public' ] );
return $checked; return $checked;
} }

View File

@@ -261,14 +261,7 @@ sub check_params {
$checked->{studio_id} = -1; $checked->{studio_id} = -1;
} }
#actions and roles $checked->{action} = entry::element_of($params->{action}, ['send']);
$checked->{action} = '';
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(send)$/ ) {
$checked->{action} = $params->{action};
}
}
return $checked; return $checked;
} }

View File

@@ -277,13 +277,8 @@ sub check_params {
$template = template::check( $config, $params->{template}, 'projects' ); $template = template::check( $config, $params->{template}, 'projects' );
$checked->{template} = $template; $checked->{template} = $template;
#actions $checked->{action} = entry::element_of($params->{action},
my $action = ''; ['save', 'delete', 'assign_studio', 'unassign_studio'] );
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(save|delete|assign_studio|unassign_studio)$/ ) {
$checked->{action} = $params->{action};
}
}
entry::set_strings( $checked, $params, [ entry::set_strings( $checked, $params, [
'name', 'title', 'subtitle', 'start_date', 'end_date', 'image', 'email', 'setImage' ]); 'name', 'title', 'subtitle', 'start_date', 'end_date', 'image', 'email', 'setImage' ]);

View File

@@ -145,12 +145,7 @@ sub check_params {
entry::set_strings( $checked, $params, [ entry::set_strings( $checked, $params, [
'user', 'token', 'user_password', 'user_password2']); 'user', 'token', 'user_password', 'user_password2']);
$checked->{action} = ''; $checked->{action} = entry::element_of($params->{action}, ['change']);
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(change)$/ ) {
$checked->{action} = $params->{action};
}
}
return $checked; return $checked;
} }

View File

@@ -8,6 +8,7 @@ use Data::Dumper;
use config(); use config();
use params(); use params();
use entry();
use log(); use log();
use template(); use template();
use auth(); use auth();
@@ -434,12 +435,7 @@ sub check_params {
$template = template::check( $config, $params->{template}, 'roles.html' ); $template = template::check( $config, $params->{template}, 'roles.html' );
$checked->{template} = $template; $checked->{template} = $template;
#actions $checked->{action} = entry::element_of( $params->{action}, ['save']);
if ( defined $params->{action} ) {
if ( $params->{action} eq 'save' ) {
$checked->{action} = $params->{action};
}
}
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [
'project_id', 'studio_id', 'default_studio_id' 'project_id', 'studio_id', 'default_studio_id'

View File

@@ -1411,22 +1411,16 @@ sub check_params {
my $checked = {}; my $checked = {};
#actions $checked->{action} = entry::element_of( $params->{action},
$checked->{action} = ''; [ qw( add_user remove_user
if ( defined $params->{action} ) {
$checked->{action} = $params->{action} if List::Util::any { $_ eq $params->{action} } qw{
add_user remove_user
create delete save details show create delete save details show
save_schedule delete_schedule save_schedule delete_schedule
save_scan scan_events save_scan scan_events
assign_event unassign_event reassign_event assign_event unassign_event reassign_event
rebuild_episodes set_rebuilt_episodes rebuild_episodes set_rebuilt_episodes
}; )]);
}
#numeric values
$checked->{exclude} = 0; $checked->{exclude} = 0;
$checked->{action} = $params->{action};
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [
'id', 'project_id', 'id', 'project_id',
'studio_id', 'default_studio_id', 'studio_id', 'default_studio_id',

View File

@@ -100,7 +100,6 @@ sub check_params {
my $checked = {}; my $checked = {};
#numeric values
for my $param ('filename') { for my $param ('filename') {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^[A-Za-z\_\-\.\d\/]+$/ ) ) { if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^[A-Za-z\_\-\.\d\/]+$/ ) ) {
$checked->{$param} = $params->{$param}; $checked->{$param} = $params->{$param};
@@ -115,10 +114,9 @@ sub check_params {
} }
} }
#numeric values
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [
'project_id', 'studio_id', 'series_id', 'event_id' 'project_id', 'studio_id', 'series_id', 'event_id'
]) ]);
if ( defined $checked->{studio_id} ) { if ( defined $checked->{studio_id} ) {
$checked->{default_studio_id} = $checked->{studio_id}; $checked->{default_studio_id} = $checked->{studio_id};

View File

@@ -221,13 +221,7 @@ sub check_params {
$template = template::check( $config, $params->{template}, 'studios' ); $template = template::check( $config, $params->{template}, 'studios' );
$checked->{template} = $template; $checked->{template} = $template;
#actions $checked->{action} = entry::element_of( $params->{action}, ['save', 'delete']);
my $action = '';
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(save|delete)$/ ) {
$checked->{action} = $params->{action};
}
}
entry::set_strings( $checked, $params, [ entry::set_strings( $checked, $params, [
'name', 'description', 'location', 'stream', 'google_calendar', 'image', 'setImage' ]); 'name', 'description', 'location', 'stream', 'google_calendar', 'image', 'setImage' ]);

View File

@@ -10,6 +10,7 @@ use config();
use log(); use log();
use template(); use template();
use auth(); use auth();
use entry();
use uac(); use uac();
use roles(); use roles();
use project(); use project();
@@ -248,12 +249,7 @@ sub check_params {
} }
} }
#actions $checked->{action} = entry::element_of( $params->{action}, ['save', 'updateDefaultProjectStudio']);
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(save|updateDefaultProjectStudio)$/ ) {
$checked->{action} = $params->{action};
}
}
return $checked; return $checked;
} }

View File

@@ -10,6 +10,7 @@ use config();
use log(); use log();
use template(); use template();
use auth(); use auth();
use entry();
use uac(); use uac();
use roles(); use roles();
use project(); use project();
@@ -117,12 +118,9 @@ sub check_params {
my $checked = {}; my $checked = {};
$checked->{action} = ''; $checked->{action} = entry::element_of( $params->{action},
if ( defined $params->{action} ) { ['show-user-stats', 'show-active-users']
if ( $params->{action} =~ /^(show-user-stats|show-active-users)$/ ) { );
$checked->{action} = $params->{action};
}
}
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [
'project_id', 'default_studio_id', 'studio_id', 'series_id']); 'project_id', 'default_studio_id', 'studio_id', 'series_id']);

View File

@@ -7,6 +7,7 @@ no warnings 'redefine';
use Data::Dumper; use Data::Dumper;
use config(); use config();
use entry();
use log(); use log();
use template(); use template();
use auth(); use auth();
@@ -407,32 +408,17 @@ sub check_params {
$checked->{studio_id} = -1; $checked->{studio_id} = -1;
} }
for my $param ( 'user_name', 'user_full_name', 'user_email' ) { entry::set_strings( $checked, $params,
if ( defined $params->{$param} ) { [ 'user_name', 'user_full_name', 'user_email', 'user_password', 'user_password2' ]
my $value = $params->{$param}; );
$value =~ s/^\s+//g;
$value =~ s/\s+$//g;
$checked->{$param} = $value;
}
}
for my $param ( 'user_password', 'user_password2' ) { $checked->{action} = entry::element_of( $params->{action},
if ( defined $params->{$param} ) { ['save', 'assign', 'delete', 'change_password']);
$checked->{$param} = $params->{$param};
}
}
#actions and roles if ( $params->{action} eq 'assign' ) {
if ( defined $params->{action} ) { $checked->{action} = $params->{action};
if ( $params->{action} =~ /^(save|assign|delete|change_password)$/ ) { for my $param ( keys %$params ) {
$checked->{action} = $params->{action}; $checked->{role_ids}->{$1} = 1 if ( $param =~ /^role_(\d+)$/ );
}
if ( $params->{action} eq 'assign' ) {
$checked->{action} = $params->{action};
for my $param ( keys %$params ) {
$checked->{role_ids}->{$1} = 1 if ( $param =~ /^role_(\d+)$/ );
}
} }
} }

View File

@@ -8,6 +8,7 @@ use Data::Dumper;
use URI::Escape(); use URI::Escape();
use params(); use params();
use config(); use config();
use entry();
use log(); use log();
use template(); use template();
use auth(); use auth();
@@ -264,13 +265,9 @@ sub check_params {
my $checked = {}; my $checked = {};
#actions and roles $checked->{action} = entry::element_of( $params->{action},
$checked->{action} = ''; ['show', 'save_schedule', 'delete_schedule']
if ( defined $params->{action} ) { );
if ( $params->{action} =~ /^(show|save_schedule|delete_schedule)$/ ) {
$checked->{action} = $params->{action};
}
}
$checked->{exclude} = 0; $checked->{exclude} = 0;
entry::set_numbers( $checked, $params, [ entry::set_numbers( $checked, $params, [