Bug 34587: (QA follow-up): squash
Tidy $c->validation in API controllers File permissions .inc file filters Signed-off-by: Jessica Zairo <jzairo@bywatersolutions.com> Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
f7e2bc5d9b
commit
c81112e798
|
|
@ -104,11 +104,11 @@ sub enqueue_sushi_harvest_jobs {
|
|||
|
||||
my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue(
|
||||
{
|
||||
ud_provider_id => $self->erm_usage_data_provider_id,
|
||||
report_type => $report_type,
|
||||
begin_date => $args->{begin_date},
|
||||
end_date => $args->{end_date},
|
||||
ud_provider_name => $self->name,
|
||||
ud_provider_id => $self->erm_usage_data_provider_id,
|
||||
report_type => $report_type,
|
||||
begin_date => $args->{begin_date},
|
||||
end_date => $args->{end_date},
|
||||
ud_provider_name => $self->name,
|
||||
}
|
||||
);
|
||||
|
||||
|
|
@ -220,15 +220,14 @@ sub harvest_sushi {
|
|||
return if $self->_sushi_errors($decoded_response);
|
||||
|
||||
# Parse the SUSHI response
|
||||
my $sushi_counter =
|
||||
Koha::ERM::EUsage::SushiCounter->new( { response => $decoded_response } );
|
||||
my $counter_file = $sushi_counter->get_COUNTER_from_SUSHI;
|
||||
my $sushi_counter = Koha::ERM::EUsage::SushiCounter->new( { response => $decoded_response } );
|
||||
my $counter_file = $sushi_counter->get_COUNTER_from_SUSHI;
|
||||
|
||||
return if $self->_counter_file_size_too_large($counter_file);
|
||||
|
||||
$self->counter_files(
|
||||
$self->counter_files(
|
||||
[
|
||||
{
|
||||
{
|
||||
usage_data_provider_id => $self->erm_usage_data_provider_id,
|
||||
file_content => $counter_file,
|
||||
date_uploaded => POSIX::strftime( "%Y%m%d%H%M%S", localtime ),
|
||||
|
|
@ -272,7 +271,7 @@ Tests the connection of the harvester to the SUSHI service and returns any alert
|
|||
sub test_connection {
|
||||
my ($self) = @_;
|
||||
|
||||
my $url = _validate_url($self->service_url, 'status');
|
||||
my $url = _validate_url( $self->service_url, 'status' );
|
||||
$url .= 'status';
|
||||
$url .= '?customer_id=' . $self->customer_id;
|
||||
$url .= '&requestor_id=' . $self->requestor_id if $self->requestor_id;
|
||||
|
|
@ -389,19 +388,18 @@ sub _build_url_query {
|
|||
$self->erm_usage_data_provider_id;
|
||||
}
|
||||
|
||||
my $url = _validate_url($self->service_url, 'harvest');
|
||||
my $url = _validate_url( $self->service_url, 'harvest' );
|
||||
|
||||
$url .= lc $self->{report_type};
|
||||
$url .= '?customer_id=' . $self->customer_id;
|
||||
$url .= '&requestor_id=' . $self->requestor_id if $self->requestor_id;
|
||||
$url .= '&api_key=' . $self->api_key if $self->api_key;
|
||||
$url .= '&begin_date=' . substr $self->{begin_date}, 0, 7 if $self->{begin_date};
|
||||
$url .= '&end_date=' . substr $self->{end_date}, 0, 7 if $self->{end_date};
|
||||
$url .= '&begin_date=' . substr $self->{begin_date}, 0, 7 if $self->{begin_date};
|
||||
$url .= '&end_date=' . substr $self->{end_date}, 0, 7 if $self->{end_date};
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
=head3 _validate_url
|
||||
|
||||
Checks whether the url ends in a trailing "/" and adds one if not
|
||||
|
|
@ -415,9 +413,11 @@ $caller is either the harvest_sushi function ("harvest") or the test_connection
|
|||
sub _validate_url {
|
||||
my ( $url, $caller ) = @_;
|
||||
|
||||
if($caller eq 'harvest') {
|
||||
if ( $caller eq 'harvest' ) {
|
||||
|
||||
# Not all urls will end in "/" - add one so they are standardised
|
||||
$url = _check_trailing_character($url);
|
||||
|
||||
# All SUSHI report requests should be to the "/reports" endpoint
|
||||
# Not all providers in the counter registry include this in their data so we need to check and add it
|
||||
my $reports_param = substr $url, -8;
|
||||
|
|
@ -436,7 +436,7 @@ Checks whether a url string ends in a "/" before we concatenate further params t
|
|||
=cut
|
||||
|
||||
sub _check_trailing_character {
|
||||
my ( $url ) = @_;
|
||||
my ($url) = @_;
|
||||
|
||||
my $trailing_char = substr $url, -1;
|
||||
if ( $trailing_char ne '/' ) {
|
||||
|
|
|
|||
|
|
@ -57,10 +57,7 @@ sub get {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
return try {
|
||||
my $counter_file_id = $c->validation->param('erm_counter_files_id');
|
||||
|
||||
# Do not use $c->objects->find here, we need the file_content
|
||||
my $counter_file = Koha::ERM::EUsage::CounterFiles->find($counter_file_id);
|
||||
my $counter_file = Koha::ERM::EUsage::CounterFiles->find( $c->param('erm_counter_files_id') );
|
||||
|
||||
if ( !$counter_file ) {
|
||||
return $c->render(
|
||||
|
|
@ -85,8 +82,8 @@ sub get {
|
|||
sub delete {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $counter_file_id = $c->validation->param('erm_counter_files_id');
|
||||
my $counter_file = Koha::ERM::EUsage::CounterFiles->find($counter_file_id);
|
||||
my $counter_file = Koha::ERM::EUsage::CounterFiles->find( $c->param('erm_counter_files_id') );
|
||||
|
||||
unless ($counter_file) {
|
||||
return $c->render(
|
||||
status => 404,
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ sub monthly_report {
|
|||
}
|
||||
}
|
||||
|
||||
my $data_type = $c->validation->param('data_type');
|
||||
my $data_type = $c->param('data_type');
|
||||
my $data_set = _get_data_set($data_type);
|
||||
my $data = $c->objects->search($data_set);
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ sub yearly_report {
|
|||
}
|
||||
}
|
||||
|
||||
my $data_type = $c->validation->param('data_type');
|
||||
my $data_type = $c->param('data_type');
|
||||
my $data_set = _get_data_set($data_type);
|
||||
my $data = $c->objects->search($data_set);
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ sub metric_types_report {
|
|||
}
|
||||
}
|
||||
|
||||
my $data_type = $c->validation->param('data_type');
|
||||
my $data_type = $c->param('data_type');
|
||||
my $data_set = _get_data_set($data_type);
|
||||
my $data = $c->objects->search($data_set);
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ sub add {
|
|||
Koha::Database->new->schema->txn_do(
|
||||
sub {
|
||||
|
||||
my $body = $c->validation->param('body');
|
||||
my $body = $c->param('body');
|
||||
|
||||
my $default_report = Koha::ERM::EUsage::DefaultUsageReport->new_from_api($body)->store;
|
||||
|
||||
|
|
@ -114,8 +114,7 @@ Controller function that handles updating a Koha::ERM::EUsage::DefaultUsageRepor
|
|||
sub update {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $default_report_id = $c->validation->param('erm_default_usage_report_id');
|
||||
my $default_report = Koha::ERM::EUsage::DefaultUsageReports->find($default_report_id);
|
||||
my $default_report = Koha::ERM::EUsage::DefaultUsageReports->find( $c->param('erm_default_usage_report_id') );
|
||||
|
||||
unless ($default_report) {
|
||||
return $c->render(
|
||||
|
|
@ -128,7 +127,7 @@ sub update {
|
|||
Koha::Database->new->schema->txn_do(
|
||||
sub {
|
||||
|
||||
my $body = $c->validation->param('body');
|
||||
my $body = $c->req->json;
|
||||
|
||||
$default_report->set_from_api($body)->store;
|
||||
|
||||
|
|
@ -173,8 +172,7 @@ sub update {
|
|||
sub delete {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $default_report_id = $c->validation->param('erm_default_usage_report_id');
|
||||
my $default_report = Koha::ERM::EUsage::DefaultUsageReports->find($default_report_id);
|
||||
my $default_report = Koha::ERM::EUsage::DefaultUsageReports->find( $c->param('erm_default_usage_report_id') );
|
||||
unless ($default_report) {
|
||||
return $c->render(
|
||||
status => 404,
|
||||
|
|
|
|||
|
|
@ -43,70 +43,66 @@ sub list {
|
|||
return try {
|
||||
my $usage_data_providers_set = Koha::ERM::EUsage::UsageDataProviders->new;
|
||||
my $usage_data_providers = $c->objects->search($usage_data_providers_set);
|
||||
# if ( $c->validation->output->{"x-koha-embed"}[0]
|
||||
# && $c->validation->output->{"x-koha-embed"}[0] eq 'counter_files' )
|
||||
# {
|
||||
foreach my $provider (@$usage_data_providers) {
|
||||
my $title_dates = _get_earliest_and_latest_dates(
|
||||
'TR',
|
||||
$provider->{erm_usage_data_provider_id}
|
||||
);
|
||||
$provider->{earliest_title} =
|
||||
$title_dates->{earliest_date}
|
||||
? $title_dates->{earliest_date}
|
||||
: '';
|
||||
$provider->{latest_title} =
|
||||
$title_dates->{latest_date}
|
||||
? $title_dates->{latest_date}
|
||||
: '';
|
||||
foreach my $provider (@$usage_data_providers) {
|
||||
my $title_dates = _get_earliest_and_latest_dates(
|
||||
'TR',
|
||||
$provider->{erm_usage_data_provider_id}
|
||||
);
|
||||
$provider->{earliest_title} =
|
||||
$title_dates->{earliest_date}
|
||||
? $title_dates->{earliest_date}
|
||||
: '';
|
||||
$provider->{latest_title} =
|
||||
$title_dates->{latest_date}
|
||||
? $title_dates->{latest_date}
|
||||
: '';
|
||||
|
||||
my $platform_dates = _get_earliest_and_latest_dates(
|
||||
'PR',
|
||||
$provider->{erm_usage_data_provider_id}
|
||||
);
|
||||
$provider->{earliest_platform} =
|
||||
$platform_dates->{earliest_date}
|
||||
? $platform_dates->{earliest_date}
|
||||
: '';
|
||||
$provider->{latest_platform} =
|
||||
$platform_dates->{latest_date}
|
||||
? $platform_dates->{latest_date}
|
||||
: '';
|
||||
my $platform_dates = _get_earliest_and_latest_dates(
|
||||
'PR',
|
||||
$provider->{erm_usage_data_provider_id}
|
||||
);
|
||||
$provider->{earliest_platform} =
|
||||
$platform_dates->{earliest_date}
|
||||
? $platform_dates->{earliest_date}
|
||||
: '';
|
||||
$provider->{latest_platform} =
|
||||
$platform_dates->{latest_date}
|
||||
? $platform_dates->{latest_date}
|
||||
: '';
|
||||
|
||||
my $item_dates = _get_earliest_and_latest_dates(
|
||||
'IR',
|
||||
$provider->{erm_usage_data_provider_id}
|
||||
);
|
||||
$provider->{earliest_item} =
|
||||
$item_dates->{earliest_date}
|
||||
? $item_dates->{earliest_date}
|
||||
: '';
|
||||
$provider->{latest_item} =
|
||||
$item_dates->{latest_date} ? $item_dates->{latest_date} : '';
|
||||
my $item_dates = _get_earliest_and_latest_dates(
|
||||
'IR',
|
||||
$provider->{erm_usage_data_provider_id}
|
||||
);
|
||||
$provider->{earliest_item} =
|
||||
$item_dates->{earliest_date}
|
||||
? $item_dates->{earliest_date}
|
||||
: '';
|
||||
$provider->{latest_item} =
|
||||
$item_dates->{latest_date} ? $item_dates->{latest_date} : '';
|
||||
|
||||
my $database_dates = _get_earliest_and_latest_dates(
|
||||
'DR',
|
||||
$provider->{erm_usage_data_provider_id}
|
||||
);
|
||||
$provider->{earliest_database} =
|
||||
$database_dates->{earliest_date}
|
||||
? $database_dates->{earliest_date}
|
||||
: '';
|
||||
$provider->{latest_database} =
|
||||
$database_dates->{latest_date}
|
||||
? $database_dates->{latest_date}
|
||||
: '';
|
||||
my $database_dates = _get_earliest_and_latest_dates(
|
||||
'DR',
|
||||
$provider->{erm_usage_data_provider_id}
|
||||
);
|
||||
$provider->{earliest_database} =
|
||||
$database_dates->{earliest_date}
|
||||
? $database_dates->{earliest_date}
|
||||
: '';
|
||||
$provider->{latest_database} =
|
||||
$database_dates->{latest_date}
|
||||
? $database_dates->{latest_date}
|
||||
: '';
|
||||
|
||||
my @last_run = Koha::ERM::EUsage::CounterFiles->search(
|
||||
{
|
||||
usage_data_provider_id => $provider->{erm_usage_data_provider_id},
|
||||
},
|
||||
{ columns => [ { date_uploaded => { max => "date_uploaded" } }, ] }
|
||||
)->unblessed;
|
||||
$provider->{last_run} = $last_run[0][0]->{date_uploaded} ? $last_run[0][0]->{date_uploaded} : '';
|
||||
my @last_run = Koha::ERM::EUsage::CounterFiles->search(
|
||||
{
|
||||
usage_data_provider_id => $provider->{erm_usage_data_provider_id},
|
||||
},
|
||||
{ columns => [ { date_uploaded => { max => "date_uploaded" } }, ] }
|
||||
)->unblessed;
|
||||
$provider->{last_run} = $last_run[0][0]->{date_uploaded} ? $last_run[0][0]->{date_uploaded} : '';
|
||||
|
||||
}
|
||||
# }
|
||||
}
|
||||
|
||||
return $c->render( status => 200, openapi => $usage_data_providers );
|
||||
} catch {
|
||||
|
|
@ -125,11 +121,8 @@ sub get {
|
|||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
return try {
|
||||
my $usage_data_provider_id = $c->validation->param('erm_usage_data_provider_id');
|
||||
my $usage_data_provider = $c->objects->find(
|
||||
Koha::ERM::EUsage::UsageDataProviders->search,
|
||||
$usage_data_provider_id
|
||||
);
|
||||
my $usage_data_provider =
|
||||
Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
|
||||
|
||||
unless ($usage_data_provider) {
|
||||
return $c->render(
|
||||
|
|
@ -160,7 +153,7 @@ sub add {
|
|||
Koha::Database->new->schema->txn_do(
|
||||
sub {
|
||||
|
||||
my $body = $c->validation->param('body');
|
||||
my $body = $c->req->json;
|
||||
|
||||
my $usage_data_provider = Koha::ERM::EUsage::UsageDataProvider->new_from_api($body)->store;
|
||||
|
||||
|
|
@ -213,8 +206,7 @@ Controller function that handles updating a Koha::ERM::EUsage::UsageDataProvider
|
|||
sub update {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $usage_data_provider_id = $c->validation->param('erm_usage_data_provider_id');
|
||||
my $usage_data_provider = Koha::ERM::EUsage::UsageDataProviders->find($usage_data_provider_id);
|
||||
my $usage_data_provider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
|
||||
|
||||
unless ($usage_data_provider) {
|
||||
return $c->render(
|
||||
|
|
@ -227,7 +219,7 @@ sub update {
|
|||
Koha::Database->new->schema->txn_do(
|
||||
sub {
|
||||
|
||||
my $body = $c->validation->param('body');
|
||||
my $body = $c->req->json;
|
||||
|
||||
$usage_data_provider->set_from_api($body)->store;
|
||||
|
||||
|
|
@ -272,8 +264,7 @@ sub update {
|
|||
sub delete {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $usage_data_provider_id = $c->validation->param('erm_usage_data_provider_id');
|
||||
my $usage_data_provider = Koha::ERM::EUsage::UsageDataProviders->find($usage_data_provider_id);
|
||||
my $usage_data_provider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
|
||||
unless ($usage_data_provider) {
|
||||
return $c->render(
|
||||
status => 404,
|
||||
|
|
@ -306,7 +297,7 @@ sub process_COUNTER_file {
|
|||
Koha::Database->new->schema->txn_do(
|
||||
sub {
|
||||
|
||||
my $body = $c->validation->param('body');
|
||||
my $body = $c->req->json;
|
||||
|
||||
my $file_content =
|
||||
defined( $body->{file_content} )
|
||||
|
|
@ -323,7 +314,7 @@ sub process_COUNTER_file {
|
|||
|
||||
# Validation was successful, enqueue the job
|
||||
my $udprovider =
|
||||
Koha::ERM::EUsage::UsageDataProviders->find( $c->validation->param('erm_usage_data_provider_id') );
|
||||
Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
|
||||
|
||||
my $jobs = $udprovider->enqueue_counter_file_processing_job(
|
||||
{
|
||||
|
|
@ -384,7 +375,7 @@ It will ->enqueue_sushi_harvest_jobs for this usage data provider
|
|||
sub process_SUSHI_response {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $body = $c->validation->param('body');
|
||||
my $body = $c->req->json;
|
||||
my $begin_date = $body->{begin_date};
|
||||
my $end_date = $body->{end_date};
|
||||
|
||||
|
|
@ -395,7 +386,7 @@ sub process_SUSHI_response {
|
|||
);
|
||||
}
|
||||
|
||||
my $udprovider = Koha::ERM::EUsage::UsageDataProviders->find( $c->validation->param('erm_usage_data_provider_id') );
|
||||
my $udprovider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
|
||||
|
||||
unless ($udprovider) {
|
||||
return $c->render(
|
||||
|
|
@ -428,7 +419,7 @@ sub process_SUSHI_response {
|
|||
sub test_connection {
|
||||
my $c = shift->openapi->valid_input or return;
|
||||
|
||||
my $udprovider = Koha::ERM::EUsage::UsageDataProviders->find( $c->validation->param('erm_usage_data_provider_id') );
|
||||
my $udprovider = Koha::ERM::EUsage::UsageDataProviders->find( $c->param('erm_usage_data_provider_id') );
|
||||
|
||||
unless ($udprovider) {
|
||||
return $c->render(
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use Modern::Perl;
|
||||
|
||||
return {
|
||||
bug_number => "XXXX",
|
||||
bug_number => "XXXX",
|
||||
description => "Creating the tables for ERM Usage Statistics",
|
||||
up => sub {
|
||||
up => sub {
|
||||
my ($args) = @_;
|
||||
my ($dbh, $out) = @$args{qw(dbh out)};
|
||||
my ( $dbh, $out ) = @$args{qw(dbh out)};
|
||||
|
||||
unless( TableExists( 'erm_usage_data_providers')) {
|
||||
unless ( TableExists('erm_usage_data_providers') ) {
|
||||
$dbh->do(
|
||||
q{
|
||||
CREATE TABLE `erm_usage_data_providers` (
|
||||
|
|
@ -30,13 +30,13 @@ return {
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
say $out "Added new table erm_usage_data_providers";
|
||||
} else {
|
||||
say $out "erm_usage_data_providers table already exists - skipping to next table";
|
||||
}
|
||||
|
||||
unless( TableExists( 'erm_counter_files')) {
|
||||
unless ( TableExists('erm_counter_files') ) {
|
||||
$dbh->do(
|
||||
q{
|
||||
CREATE TABLE `erm_counter_files` (
|
||||
|
|
@ -51,13 +51,13 @@ return {
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
say $out "Added new table erm_counter_files";
|
||||
} else {
|
||||
say $out "erm_counter_files table already exists - skipping to next table";
|
||||
}
|
||||
|
||||
unless( TableExists( 'erm_counter_logs')) {
|
||||
unless ( TableExists('erm_counter_logs') ) {
|
||||
$dbh->do(
|
||||
q{
|
||||
CREATE TABLE `erm_counter_logs` (
|
||||
|
|
@ -75,13 +75,13 @@ return {
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
say $out "Added new table erm_counter_logs";
|
||||
} else {
|
||||
say $out "erm_counter_logs table already exists - skipping to next table";
|
||||
}
|
||||
|
||||
unless( TableExists( 'erm_usage_titles')) {
|
||||
unless ( TableExists('erm_usage_titles') ) {
|
||||
$dbh->do(
|
||||
q{
|
||||
CREATE TABLE `erm_usage_titles` (
|
||||
|
|
@ -102,7 +102,7 @@ return {
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
say $out "Added new table erm_usage_titles";
|
||||
} else {
|
||||
say $out "erm_usage_titles table already exists - skipping to next table";
|
||||
|
|
@ -167,7 +167,7 @@ return {
|
|||
say $out "erm_usage_items table already exists - skipping to next table";
|
||||
}
|
||||
|
||||
unless( TableExists( 'erm_usage_mus')) {
|
||||
unless ( TableExists('erm_usage_mus') ) {
|
||||
$dbh->do(
|
||||
q{
|
||||
CREATE TABLE `erm_usage_mus` (
|
||||
|
|
@ -193,13 +193,13 @@ return {
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
say $out "Added new table erm_usage_mus";
|
||||
} else {
|
||||
say $out "erm_usage_mus table already exists - skipping to next table";
|
||||
}
|
||||
|
||||
unless( TableExists( 'erm_usage_yus')) {
|
||||
unless ( TableExists('erm_usage_yus') ) {
|
||||
$dbh->do(
|
||||
q{
|
||||
CREATE TABLE `erm_usage_yus` (
|
||||
|
|
@ -224,13 +224,13 @@ return {
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
say $out "Added new table erm_usage_yus";
|
||||
} else {
|
||||
say $out "erm_usage_yus table already exists - skipping to next table";
|
||||
}
|
||||
|
||||
unless( TableExists( 'erm_default_usage_reports')) {
|
||||
unless ( TableExists('erm_default_usage_reports') ) {
|
||||
$dbh->do(
|
||||
q{
|
||||
CREATE TABLE `erm_default_usage_reports` (
|
||||
|
|
@ -241,13 +241,14 @@ return {
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
say $out "Added new table erm_default_usage_reports";
|
||||
} else {
|
||||
say $out "erm_default_usage_reports table already exists - skipping to next table";
|
||||
}
|
||||
|
||||
$dbh->do(q{
|
||||
|
||||
$dbh->do(
|
||||
q{
|
||||
INSERT IGNORE INTO authorised_value_categories (category_name, is_system)
|
||||
VALUES
|
||||
('ERM_REPORT_TYPES', 1),
|
||||
|
|
@ -255,8 +256,10 @@ return {
|
|||
('ERM_DATABASE_REPORTS_METRICS', 1),
|
||||
('ERM_TITLE_REPORTS_METRICS', 1),
|
||||
('ERM_ITEM_REPORTS_METRICS', 1);
|
||||
});
|
||||
$dbh->do(q{
|
||||
}
|
||||
);
|
||||
$dbh->do(
|
||||
q{
|
||||
INSERT IGNORE INTO authorised_values (category, authorised_value, lib)
|
||||
VALUES
|
||||
('ERM_REPORT_TYPES', 'PR', 'PR - Platform master report'),
|
||||
|
|
@ -307,6 +310,7 @@ return {
|
|||
('ERM_ITEM_REPORTS_METRICS', 'Unique_Item_Requests', 'Unique item requests'),
|
||||
('ERM_ITEM_REPORTS_METRICS', 'Limit_Exceeded', 'Limit exceeded'),
|
||||
('ERM_ITEM_REPORTS_METRICS', 'No_License', 'No license');
|
||||
});
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<table id="finishedtable">
|
||||
<tr>
|
||||
<td>Usage data provider</td>
|
||||
<td><a href="/cgi-bin/koha/erm/eusage/usage_data_providers/[% report.ud_provider_id %]" title="Visit usage data provider">[% report.ud_provider_name | html %]</a></td>
|
||||
<td><a href="/cgi-bin/koha/erm/eusage/usage_data_providers/[% report.ud_provider_id | uri %]" title="Visit usage data provider">[% report.ud_provider_name | html %]</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Report type</td>
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>Report rows processed</td>
|
||||
<td>[% job.progress %]</td>
|
||||
<td>[% job.progress | html %]</td>
|
||||
</tr>
|
||||
<tr>
|
||||
[% IF report.report_type.match( '^PR' ) %]
|
||||
|
|
@ -53,7 +53,7 @@
|
|||
<table id="finishedtable">
|
||||
<tr>
|
||||
<td>Usage data provider</td>
|
||||
<td><a id="failed_provider_name" href="/cgi-bin/koha/erm/eusage/usage_data_providers/[% report.ud_provider_id %]" title="Visit usage data provider"></a></td>
|
||||
<td><a id="failed_provider_name" href="/cgi-bin/koha/erm/eusage/usage_data_providers/[% report.ud_provider_id | uri %]" title="Visit usage data provider"></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Report type</td>
|
||||
|
|
@ -85,19 +85,19 @@
|
|||
[% END %]
|
||||
[% SWITCH m.code %]
|
||||
[% CASE 'object_already_exists' %]
|
||||
<span><strong>[% m.title %]</strong> already exists in this data provider and was not created. New usage statistics were verified anyway</span>
|
||||
<span><strong>[% m.title | html %]</strong> already exists in this data provider and was not created. New usage statistics were verified anyway</span>
|
||||
[% CASE 'object_added' %]
|
||||
<span><strong>[% m.title %]</strong> successfully added</span>
|
||||
<span><strong>[% m.title | html %]</strong> successfully added</span>
|
||||
[% CASE 'object_could_not_be_added' %]
|
||||
<span><strong>[% m.title %]</strong> could not be processed - please check the logs</span>
|
||||
<span><strong>[% m.title | html %]</strong> could not be processed - please check the logs</span>
|
||||
[% CASE 'payload_too_large' %]
|
||||
<span>COUNTER report file size exceeds limit defined by the database. Limit is [% m.message %] MB.</span><br>
|
||||
<span>COUNTER report file size exceeds limit defined by the database. Limit is [% m.message | html %] MB.</span><br>
|
||||
<span>Please increase this limit or harvest a shorter period.</span>
|
||||
[% CASE 'no_items' %]
|
||||
<span>SUSHI response returned no items.</span><br>
|
||||
<span>Please try a different harvest period.</span>
|
||||
[% CASE %]
|
||||
<span>SUSHI returned: [% m.message %] [% m.code %]</span>
|
||||
<span>SUSHI returned: [% m.message | html %] [% m.code | html %]</span>
|
||||
[% END %]
|
||||
</div>
|
||||
[% END %]
|
||||
|
|
@ -109,7 +109,7 @@
|
|||
[% INCLUDE 'str/erm_sushi_harvester.inc' %]
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
let job_id = [% job.id | html %];
|
||||
let job_id = [% job.id | $raw %];
|
||||
updateProgress(job_id, {
|
||||
progress_callback : function(){
|
||||
$.getJSON('/api/v1/jobs/'+job_id, function(job){
|
||||
|
|
@ -128,8 +128,8 @@
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
let job_data = [% job.data %];
|
||||
|
||||
let job_data = [% job.data | $raw %];
|
||||
let report_type = job_data.report_type;
|
||||
let ud_provider_name = job_data.ud_provider_name;
|
||||
$('#failed_report_type').text(report_type);
|
||||
|
|
|
|||
|
|
@ -64,15 +64,12 @@ subtest 'list() tests' => sub {
|
|||
|
||||
## Authorized user tests
|
||||
# No counter files, so empty array should be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files")->status_is(200)
|
||||
->json_is( [] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files")->status_is(200)->json_is( [] );
|
||||
|
||||
my $counter_file =
|
||||
$builder->build_object( { class => 'Koha::ERM::EUsage::CounterFiles' } );
|
||||
my $counter_file = $builder->build_object( { class => 'Koha::ERM::EUsage::CounterFiles' } );
|
||||
|
||||
# One counter_file created, should get returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files")->status_is(200)
|
||||
->json_is( [ $counter_file->to_api ] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files")->status_is(200)->json_is( [ $counter_file->to_api ] );
|
||||
|
||||
my $another_counter_file = $builder->build_object(
|
||||
{
|
||||
|
|
@ -82,14 +79,13 @@ subtest 'list() tests' => sub {
|
|||
|
||||
# Two counter_files created, they should both be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files")->status_is(200)
|
||||
->json_is( [ $counter_file->to_api, $another_counter_file->to_api, ] );
|
||||
->json_is( [ $counter_file->to_api, $another_counter_file->to_api, ] );
|
||||
|
||||
# Attempt to search by type like 'ko'
|
||||
$counter_file->delete;
|
||||
$another_counter_file->delete;
|
||||
$t->get_ok(
|
||||
qq~//$userid:$password@/api/v1/erm/counter_files?q=[{"me.type":{"like":"%ko%"}}]~
|
||||
)->status_is(200)->json_is( [] );
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/counter_files?q=[{"me.type":{"like":"%ko%"}}]~)->status_is(200)
|
||||
->json_is( [] );
|
||||
|
||||
my $counter_file_to_search = $builder->build_object(
|
||||
{
|
||||
|
|
@ -101,19 +97,15 @@ qq~//$userid:$password@/api/v1/erm/counter_files?q=[{"me.type":{"like":"%ko%"}}]
|
|||
);
|
||||
|
||||
# Search works, searching for type like 'ko'
|
||||
$t->get_ok(
|
||||
qq~//$userid:$password@/api/v1/erm/counter_files?q=[{"me.type":{"like":"%ko%"}}]~
|
||||
)->status_is(200)->json_is( [ $counter_file_to_search->to_api ] );
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/counter_files?q=[{"me.type":{"like":"%ko%"}}]~)->status_is(200)
|
||||
->json_is( [ $counter_file_to_search->to_api ] );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files?blah=blah")
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
[ { path => '/query/blah', message => 'Malformed query string' } ] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files?blah=blah")->status_is(400)
|
||||
->json_is( [ { path => '/query/blah', message => 'Malformed query string' } ] );
|
||||
|
||||
# Unauthorized access
|
||||
$t->get_ok("//$unauth_userid:$password@/api/v1/erm/counter_files")
|
||||
->status_is(403);
|
||||
$t->get_ok("//$unauth_userid:$password@/api/v1/erm/counter_files")->status_is(403);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
@ -124,9 +116,8 @@ subtest 'get() tests' => sub {
|
|||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $counter_file =
|
||||
$builder->build_object( { class => 'Koha::ERM::EUsage::CounterFiles' } );
|
||||
my $librarian = $builder->build_object(
|
||||
my $counter_file = $builder->build_object( { class => 'Koha::ERM::EUsage::CounterFiles' } );
|
||||
my $librarian = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Patrons',
|
||||
value => { flags => 2**28 }
|
||||
|
|
@ -147,21 +138,22 @@ subtest 'get() tests' => sub {
|
|||
my $unauth_userid = $patron->userid;
|
||||
|
||||
# This counter_file exists, should get returned
|
||||
$t->get_ok( "//$userid:$password@/api/v1/erm/counter_files/"
|
||||
. $counter_file->erm_counter_files_id . "/file/content" )->status_is(200);
|
||||
$t->get_ok(
|
||||
"//$userid:$password@/api/v1/erm/counter_files/" . $counter_file->erm_counter_files_id . "/file/content" )
|
||||
->status_is(200);
|
||||
|
||||
# Unauthorized access
|
||||
$t->get_ok( "//$unauth_userid:$password@/api/v1/erm/counter_files/"
|
||||
. $counter_file->erm_counter_files_id . "/file/content")->status_is(403);
|
||||
. $counter_file->erm_counter_files_id
|
||||
. "/file/content" )->status_is(403);
|
||||
|
||||
# Attempt to get non-existent counter_file
|
||||
my $counter_file_to_delete =
|
||||
$builder->build_object( { class => 'Koha::ERM::EUsage::CounterFiles' } );
|
||||
my $non_existent_id = $counter_file_to_delete->erm_counter_files_id;
|
||||
my $counter_file_to_delete = $builder->build_object( { class => 'Koha::ERM::EUsage::CounterFiles' } );
|
||||
my $non_existent_id = $counter_file_to_delete->erm_counter_files_id;
|
||||
$counter_file_to_delete->delete;
|
||||
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files/$non_existent_id/file/content")
|
||||
->status_is(404)->json_is( '/error' => 'Counter file not found' );
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/counter_files/$non_existent_id/file/content")->status_is(404)
|
||||
->json_is( '/error' => 'Counter file not found' );
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
@ -193,23 +185,17 @@ subtest 'delete() tests' => sub {
|
|||
my $unauth_userid = $patron->userid;
|
||||
|
||||
my $counter_file_id =
|
||||
$builder->build_object( { class => 'Koha::ERM::EUsage::CounterFiles' } )
|
||||
->erm_counter_files_id;
|
||||
$builder->build_object( { class => 'Koha::ERM::EUsage::CounterFiles' } )->erm_counter_files_id;
|
||||
|
||||
# Unauthorized attempt to delete
|
||||
$t->delete_ok(
|
||||
"//$unauth_userid:$password@/api/v1/erm/counter_files/$counter_file_id")
|
||||
->status_is(403);
|
||||
$t->delete_ok("//$unauth_userid:$password@/api/v1/erm/counter_files/$counter_file_id")->status_is(403);
|
||||
|
||||
# Delete existing counter_file
|
||||
$t->delete_ok(
|
||||
"//$userid:$password@/api/v1/erm/counter_files/$counter_file_id")
|
||||
->status_is( 204, 'SWAGGER3.2.4' )->content_is( '', 'SWAGGER3.3.4' );
|
||||
$t->delete_ok("//$userid:$password@/api/v1/erm/counter_files/$counter_file_id")->status_is( 204, 'SWAGGER3.2.4' )
|
||||
->content_is( '', 'SWAGGER3.3.4' );
|
||||
|
||||
# Attempt to delete non-existent counter_file
|
||||
$t->delete_ok(
|
||||
"//$userid:$password@/api/v1/erm/counter_files/$counter_file_id")
|
||||
->status_is(404);
|
||||
$t->delete_ok("//$userid:$password@/api/v1/erm/counter_files/$counter_file_id")->status_is(404);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -335,8 +335,3 @@ subtest "metric_types_report" => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -79,11 +79,10 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
|
||||
my $usage_data_provider = $builder->build_object( { class => 'Koha::ERM::EUsage::UsageDataProviders' } );
|
||||
my $udp_result = { %{ $usage_data_provider->to_api }, %additional_fields };
|
||||
my $udp_result = { %{ $usage_data_provider->to_api }, %additional_fields };
|
||||
|
||||
# One usage_data_provider created, should get returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/usage_data_providers")->status_is(200)
|
||||
->json_is( [ $udp_result ] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/usage_data_providers")->status_is(200)->json_is( [$udp_result] );
|
||||
|
||||
my $another_usage_data_provider = $builder->build_object(
|
||||
{
|
||||
|
|
@ -116,10 +115,9 @@ subtest 'list() tests' => sub {
|
|||
);
|
||||
my $search_udp_result = { %{ $usage_data_provider_to_search->to_api }, %additional_fields };
|
||||
|
||||
|
||||
# Search works, searching for name like 'ko'
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/usage_data_providers?q=[{"me.name":{"like":"%ko%"}}]~)
|
||||
->status_is(200)->json_is( [ $search_udp_result ] );
|
||||
->status_is(200)->json_is( [$search_udp_result] );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/usage_data_providers?blah=blah")->status_is(400)
|
||||
|
|
|
|||
|
|
@ -64,15 +64,12 @@ subtest 'list() tests' => sub {
|
|||
|
||||
## Authorized user tests
|
||||
# No titles, so empty array should be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/usage_titles")->status_is(200)
|
||||
->json_is( [] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/usage_titles")->status_is(200)->json_is( [] );
|
||||
|
||||
my $usage_title =
|
||||
$builder->build_object( { class => 'Koha::ERM::EUsage::UsageTitles' } );
|
||||
my $usage_title = $builder->build_object( { class => 'Koha::ERM::EUsage::UsageTitles' } );
|
||||
|
||||
# One usage_title created, should get returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/usage_titles")->status_is(200)
|
||||
->json_is( [ $usage_title->to_api ] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/usage_titles")->status_is(200)->json_is( [ $usage_title->to_api ] );
|
||||
|
||||
my $another_usage_title = $builder->build_object(
|
||||
{
|
||||
|
|
@ -82,14 +79,13 @@ subtest 'list() tests' => sub {
|
|||
|
||||
# Two usage_titles created, they should both be returned
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/usage_titles")->status_is(200)
|
||||
->json_is( [ $usage_title->to_api, $another_usage_title->to_api, ] );
|
||||
->json_is( [ $usage_title->to_api, $another_usage_title->to_api, ] );
|
||||
|
||||
# Attempt to search by title like 'ko'
|
||||
$usage_title->delete;
|
||||
$another_usage_title->delete;
|
||||
$t->get_ok(
|
||||
qq~//$userid:$password@/api/v1/erm/usage_titles?q=[{"me.title":{"like":"%ko%"}}]~
|
||||
)->status_is(200)->json_is( [] );
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/usage_titles?q=[{"me.title":{"like":"%ko%"}}]~)->status_is(200)
|
||||
->json_is( [] );
|
||||
|
||||
my $usage_title_to_search = $builder->build_object(
|
||||
{
|
||||
|
|
@ -101,20 +97,15 @@ qq~//$userid:$password@/api/v1/erm/usage_titles?q=[{"me.title":{"like":"%ko%"}}]
|
|||
);
|
||||
|
||||
# Search works, searching for title like 'ko'
|
||||
$t->get_ok(
|
||||
qq~//$userid:$password@/api/v1/erm/usage_titles?q=[{"me.title":{"like":"%ko%"}}]~
|
||||
)->status_is(200)->json_is( [ $usage_title_to_search->to_api ] );
|
||||
$t->get_ok(qq~//$userid:$password@/api/v1/erm/usage_titles?q=[{"me.title":{"like":"%ko%"}}]~)->status_is(200)
|
||||
->json_is( [ $usage_title_to_search->to_api ] );
|
||||
|
||||
# Warn on unsupported query parameter
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/usage_titles?blah=blah")
|
||||
->status_is(400)
|
||||
->json_is(
|
||||
[ { path => '/query/blah', message => 'Malformed query string' } ] );
|
||||
$t->get_ok("//$userid:$password@/api/v1/erm/usage_titles?blah=blah")->status_is(400)
|
||||
->json_is( [ { path => '/query/blah', message => 'Malformed query string' } ] );
|
||||
|
||||
# Unauthorized access
|
||||
$t->get_ok("//$unauth_userid:$password@/api/v1/erm/usage_titles")
|
||||
->status_is(403);
|
||||
$t->get_ok("//$unauth_userid:$password@/api/v1/erm/usage_titles")->status_is(403);
|
||||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue