View | Details | Raw Unified | Return to bug 35386
Collapse All | Expand All

(-)a/Koha/Item.pm (-13 / +29 lines)
Lines 1195-1224 Returns the branchcode to be recorded in statistics renewal of the item Link Here
1195
1195
1196
sub renewal_branchcode {
1196
sub renewal_branchcode {
1197
1197
1198
    my ($self, $params ) = @_;
1198
    my ( $self, $params ) = @_;
1199
1199
1200
    my $interface = C4::Context->interface;
1200
    my $interface = C4::Context->interface;
1201
    my $branchcode;
1201
    my $branchcode;
1202
    if ( $interface eq 'opac' ){
1202
    my $renewal_branchcode;
1203
        my $renewal_branchcode = C4::Context->preference('OpacRenewalBranch');
1203
1204
        if( !defined $renewal_branchcode || $renewal_branchcode eq 'opacrenew' ){
1204
    if ( $interface eq 'opac' ) {
1205
        $renewal_branchcode = C4::Context->preference('OpacRenewalBranch');
1206
        if ( !defined $renewal_branchcode || $renewal_branchcode eq 'opacrenew' ) {
1205
            $branchcode = 'OPACRenew';
1207
            $branchcode = 'OPACRenew';
1206
        }
1208
        }
1207
        elsif ( $renewal_branchcode eq 'itemhomebranch' ) {
1209
    } elsif ( $interface eq 'api' ) {
1208
            $branchcode = $self->homebranch;
1210
        $renewal_branchcode = C4::Context->preference('RESTAPIRenewalBranch');
1211
        if ( !defined $renewal_branchcode || $renewal_branchcode eq 'apirenew' ) {
1212
            $branchcode = 'APIRenew';
1209
        }
1213
        }
1210
        elsif ( $renewal_branchcode eq 'patronhomebranch' ) {
1214
    }
1215
1216
    return $branchcode if $branchcode;
1217
1218
    if ($renewal_branchcode) {
1219
        if ( $renewal_branchcode eq 'itemhomebranch' ) {
1220
            $branchcode = $self->homebranch;
1221
        } elsif ( $renewal_branchcode eq 'patronhomebranch' ) {
1211
            $branchcode = $self->checkout->patron->branchcode;
1222
            $branchcode = $self->checkout->patron->branchcode;
1212
        }
1223
        } elsif ( $renewal_branchcode eq 'checkoutbranch' ) {
1213
        elsif ( $renewal_branchcode eq 'checkoutbranch' ) {
1214
            $branchcode = $self->checkout->branchcode;
1224
            $branchcode = $self->checkout->branchcode;
1215
        }
1225
        } elsif ( $renewal_branchcode eq 'apiuserbranch' ) {
1216
        else {
1226
            $branchcode =
1227
                ( C4::Context->userenv && defined C4::Context->userenv->{branch} )
1228
                ? C4::Context->userenv->{branch}
1229
                : $params->{branch};
1230
        } else {
1217
            $branchcode = "";
1231
            $branchcode = "";
1218
        }
1232
        }
1219
    } else {
1233
    } else {
1220
        $branchcode = ( C4::Context->userenv && defined C4::Context->userenv->{branch} )
1234
        $branchcode =
1221
            ? C4::Context->userenv->{branch} : $params->{branch};
1235
            ( C4::Context->userenv && defined C4::Context->userenv->{branch} )
1236
            ? C4::Context->userenv->{branch}
1237
            : $params->{branch};
1222
    }
1238
    }
1223
    return $branchcode;
1239
    return $branchcode;
1224
}
1240
}
(-)a/installer/data/mysql/atomicupdate/bug_35386.pl (+17 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "35386",
5
    description => "Add RESTAPIRenewalBranch preference",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        $dbh->do(q{
11
            INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
12
            ('RESTAPIRenewalBranch','apiuserbranch','itemhomebranch|patronhomebranch|checkoutbranch|apiuserbranch|none','Choose how the branch for an API renewal is recorded in statistics','Choice')
13
        });
14
15
        say $out "Added new system preference 'RESTAPIRenewalBranch'";
16
    },
17
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 637-642 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
637
('RESTOAuth2ClientCredentials','0',NULL,'If enabled, the OAuth2 client credentials flow is enabled for the REST API.','YesNo'),
637
('RESTOAuth2ClientCredentials','0',NULL,'If enabled, the OAuth2 client credentials flow is enabled for the REST API.','YesNo'),
638
('RESTPublicAnonymousRequests','1',NULL,'If enabled, the API will allow anonymous access to public routes that don\'t require authenticated access.','YesNo'),
638
('RESTPublicAnonymousRequests','1',NULL,'If enabled, the API will allow anonymous access to public routes that don\'t require authenticated access.','YesNo'),
639
('RESTPublicAPI','1',NULL,'If enabled, the REST API will expose the /public endpoints.','YesNo'),
639
('RESTPublicAPI','1',NULL,'If enabled, the REST API will expose the /public endpoints.','YesNo'),
640
('RESTAPIRenewalBranch','apiuserbranch','itemhomebranch|patronhomebranch|checkoutbranch|apiuserbranch|none','Choose how the branch for an API renewal is recorded in statistics','Choice'),
640
('RestrictedPageLocalIPs','',NULL,'Beginning of IP addresses considered as local (comma separated ex: "127.0.0,127.0.2")','Free'),
641
('RestrictedPageLocalIPs','',NULL,'Beginning of IP addresses considered as local (comma separated ex: "127.0.0,127.0.2")','Free'),
641
('RestrictedPageContent','',NULL,'HTML content of the restricted page','TextArea'),
642
('RestrictedPageContent','',NULL,'HTML content of the restricted page','TextArea'),
642
('RestrictedPageTitle','',NULL,'Title of the restricted page (breadcrumb and header)','Free'),
643
('RestrictedPageTitle','',NULL,'Title of the restricted page (breadcrumb and header)','Free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/web_services.pref (+11 lines)
Lines 35-40 Web services: Link Here
35
                  1: Enable
35
                  1: Enable
36
                  0: "Disable"
36
                  0: "Disable"
37
            - "the /public namespace of the API."
37
            - "the /public namespace of the API."
38
        -
39
            - Use 
40
            - pref: RESTAPIRenewalBranch
41
              choices:
42
                  apiuserbranch: "the branch of the api user"
43
                  itemhomebranch: "the item's home library"
44
                  patronhomebranch: "the patron's home library"
45
                  checkoutbranch: "the library the item was checked out from"
46
                  none: "NULL"
47
                  apirenew: "'APIRenew'"
48
            - as branchcode to store in the statistics table.
38
    OAI-PMH:
49
    OAI-PMH:
39
        -
50
        -
40
            - pref: OAI-PMH
51
            - pref: OAI-PMH
(-)a/t/db_dependent/Koha/Item.t (-2 / +29 lines)
Lines 1019-1025 subtest 'deletion' => sub { Link Here
1019
};
1019
};
1020
1020
1021
subtest 'renewal_branchcode' => sub {
1021
subtest 'renewal_branchcode' => sub {
1022
    plan tests => 13;
1022
    plan tests => 25;
1023
1023
1024
    $schema->storage->txn_begin;
1024
    $schema->storage->txn_begin;
1025
1025
Lines 1063-1068 subtest 'renewal_branchcode' => sub { Link Here
1063
    is( $item->renewal_branchcode, $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item");
1063
    is( $item->renewal_branchcode, $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item");
1064
    is( $item->renewal_branchcode({branch=>'MANATEE'}), $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item even if branch passed");
1064
    is( $item->renewal_branchcode({branch=>'MANATEE'}), $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item even if branch passed");
1065
1065
1066
    C4::Context->interface( 'api' );
1067
1068
    t::lib::Mocks::mock_preference('RESTAPIRenewalBranch', undef);
1069
    is( $item->renewal_branchcode, 'APIRenew', "If interface api and RESTAPIRenewalBranch undef, we get APIRenew");
1070
    is( $item->renewal_branchcode({branch=>'COW'}), 'APIRenew', "If interface api and RESTAPIRenewalBranch undef, we get APIRenew even if branch passed");
1071
1072
    t::lib::Mocks::mock_preference('RESTAPIRenewalBranch', 'none');
1073
    is( $item->renewal_branchcode, '', "If interface api and RESTAPIRenewalBranch is none, we get blank string");
1074
    is( $item->renewal_branchcode({branch=>'COW'}), '', "If interface api and RESTAPIRenewalBranch is none, we get blank string even if branch passed");
1075
1076
    t::lib::Mocks::mock_preference('RESTAPIRenewalBranch', 'checkoutbranch');
1077
    is( $item->renewal_branchcode, $checkout->branchcode, "If interface api and RESTAPIRenewalBranch set to checkoutbranch, we get branch of checkout");
1078
    is( $item->renewal_branchcode({branch=>'MONKEY'}), $checkout->branchcode, "If interface api and RESTAPIRenewalBranch set to checkoutbranch, we get branch of checkout even if branch passed");
1079
1080
    t::lib::Mocks::mock_preference('RESTAPIRenewalBranch','patronhomebranch');
1081
    is( $item->renewal_branchcode, $checkout->patron->branchcode, "If interface api and RESTAPIRenewalBranch set to patronbranch, we get branch of patron");
1082
    is( $item->renewal_branchcode({branch=>'TURKEY'}), $checkout->patron->branchcode, "If interface api and RESTAPIRenewalBranch set to patronbranch, we get branch of patron even if branch passed");
1083
1084
    t::lib::Mocks::mock_preference('RESTAPIRenewalBranch','itemhomebranch');
1085
    is( $item->renewal_branchcode, $item->homebranch, "If interface api and RESTAPIRenewalBranch set to itemhomebranch, we get homebranch of item");
1086
    is( $item->renewal_branchcode({branch=>'MANATEE'}), $item->homebranch, "If interface api and RESTAPIRenewalBranch set to itemhomebranch, we get homebranch of item even if branch passed");
1087
1088
    t::lib::Mocks::mock_userenv({ branchcode => $branch->branchcode });
1089
    t::lib::Mocks::mock_preference('RESTAPIRenewalBranch','apiuserbranch');
1090
    is( $item->renewal_branchcode, $branch->branchcode, "If interface api and RESTAPIRenewalBranch set to apiuserbranch, we get branch from userenv");
1091
    is( $item->renewal_branchcode({branch=>'MANATEE'}), $branch->branchcode, "If interface api and RESTAPIRenewalBranch set to apiuserbranch, we get branch from userenv even if branch passed");
1092
    C4::Context->set_userenv(51, 'userid4tests', undef, 'firstname', 'surname', undef, undef, 0, undef, undef, undef ); #mock userenv doesn't let us set null branch
1093
1066
    $schema->storage->txn_rollback;
1094
    $schema->storage->txn_rollback;
1067
};
1095
};
1068
1096
1069
- 

Return to bug 35386