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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -100,7 +100,6 @@ sub check_params {
my $checked = {};
#numeric values
for my $param ('filename') {
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^[A-Za-z\_\-\.\d\/]+$/ ) ) {
$checked->{$param} = $params->{$param};
@@ -115,10 +114,9 @@ sub check_params {
}
}
#numeric values
entry::set_numbers( $checked, $params, [
'project_id', 'studio_id', 'series_id', 'event_id'
])
]);
if ( defined $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' );
$checked->{template} = $template;
#actions
my $action = '';
if ( defined $params->{action} ) {
if ( $params->{action} =~ /^(save|delete)$/ ) {
$checked->{action} = $params->{action};
}
}
$checked->{action} = entry::element_of( $params->{action}, ['save', 'delete']);
entry::set_strings( $checked, $params, [
'name', 'description', 'location', 'stream', 'google_calendar', 'image', 'setImage' ]);

View File

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

View File

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

View File

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