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

(-)a/Koha/REST/V1/Biblios.pm (-6 / +69 lines)
Lines 22-27 use Mojo::Base 'Mojolicious::Controller'; Link Here
22
use Koha::Biblios;
22
use Koha::Biblios;
23
use Koha::Ratings;
23
use Koha::Ratings;
24
use Koha::RecordProcessor;
24
use Koha::RecordProcessor;
25
use Koha::SearchEngine::Search;
25
use C4::Biblio qw( DelBiblio AddBiblio ModBiblio );
26
use C4::Biblio qw( DelBiblio AddBiblio ModBiblio );
26
use C4::Search qw( FindDuplicate );
27
use C4::Search qw( FindDuplicate );
27
28
Lines 144-149 sub delete { Link Here
144
    };
145
    };
145
}
146
}
146
147
148
=head3 get_biblios_public
149
150
Controller function that handles retrieving biblios by querying the database
151
via the searchengine that's currently in use. Use the q_ccl query paramater.
152
153
=cut
154
155
sub get_biblios_public {
156
157
    my $c = shift->openapi->valid_input or return;
158
159
    my $searcher = Koha::SearchEngine::Search->new( { index => 'biblios' } );
160
    my $query    = $c->validation->param('q_ccl');
161
162
    my ( $error, $results, $total_hits ) = $searcher->simple_search_compat( $query, 0, undef );
163
164
    if ( !$total_hits ) {
165
        return $c->render(
166
            status  => 404,
167
            openapi => { error => 'Nothing found.' }
168
        );
169
    }
170
171
    return try {
172
173
        my $patron                = $c->stash('koha.user');
174
        my $is_public             = $c->stash('is_public');
175
        my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems');
176
	    my $searchengine          = C4::Context->preference('SearchEngine');
177
178
	    my @biblionumbers
179
            = $searchengine eq 'Zebra'
180
            ? map { MARC::Record->new_from_xml( $_, 'UTF-8' )->field('999')->subfield('c') } $results->@*
181
            : map { $_->field('999')->subfield('c') } $results->@*;
182
        my @biblios               = map { Koha::Biblios->find( { biblionumber => $_ } ) } @biblionumbers;
183
        my @records               = map {
184
            next if ( $is_public
185
            && !( $patron && $patron->category->override_hidden_items )
186
                && $_->hidden_in_opac( { rules => $opachiddenitems_rules } ) );
187
            $_->metadata->record;
188
        } @biblios;
189
190
        $c->respond_to(
191
            mij => {
192
                status => 200,
193
                format => 'mij',
194
                data   => '[' . ( join ',', map { $_->to_mij } @records ) . ']',
195
            },
196
            any => {
197
                status  => 406,
198
                openapi => [ 'application/marc-in-json', ]
199
            }
200
        );
201
    }
202
    catch {
203
        $c->unhandled_exception($_);
204
    };
205
}
206
147
=head3 get_public
207
=head3 get_public
148
208
149
Controller function that handles retrieving a single biblio object
209
Controller function that handles retrieving a single biblio object
Lines 190-202 sub get_public { Link Here
190
250
191
        my $marcflavour = C4::Context->preference("marcflavour");
251
        my $marcflavour = C4::Context->preference("marcflavour");
192
252
193
        my $record_processor = Koha::RecordProcessor->new({
253
        my $record_processor = Koha::RecordProcessor->new(
194
            filters => 'ViewPolicy',
254
            {
195
            options => {
255
                filters => 'ViewPolicy',
196
                interface => 'opac',
256
                options => {
197
                frameworkcode => $biblio->frameworkcode
257
                    interface     => 'opac',
258
                    frameworkcode => $biblio->frameworkcode
259
                }
198
            }
260
            }
199
        });
261
        );
262
200
        # Apply framework's filtering to MARC::Record object
263
        # Apply framework's filtering to MARC::Record object
201
        $record_processor->process($record);
264
        $record_processor->process($record);
202
265
(-)a/api/v1/swagger/paths/biblios.yaml (+46 lines)
Lines 454-459 Link Here
454
    x-koha-authorization:
454
    x-koha-authorization:
455
      permissions:
455
      permissions:
456
        reserveforothers: place_holds
456
        reserveforothers: place_holds
457
"/public/biblios":
458
  get:
459
    x-mojo-to: Biblios#get_biblios_public
460
    operationId: getBibliosPublic
461
    tags:
462
      - biblios
463
    summary: Get biblios (public)
464
    parameters:
465
      - $ref: "../swagger.yaml#/parameters/q_ccl"
466
    produces:
467
      - application/marc-in-json
468
    responses:
469
      "200":
470
        description: List of biblios
471
        schema:
472
          type: array
473
      "401":
474
        description: Authentication required
475
        schema:
476
          $ref: "../swagger.yaml#/definitions/error"
477
      "403":
478
        description: Access forbidden
479
        schema:
480
          $ref: "../swagger.yaml#/definitions/error"
481
      "404":
482
        description: Biblio not found
483
        schema:
484
          $ref: "../swagger.yaml#/definitions/error"
485
      "406":
486
        description: Not acceptable
487
        schema:
488
          type: array
489
          description: Accepted content-types
490
          items:
491
            type: string
492
      "500":
493
        description: |
494
          Internal server error. Possible `error_code` attribute values:
495
496
          * `internal_server_error`
497
        schema:
498
          $ref: "../swagger.yaml#/definitions/error"
499
      "503":
500
        description: Under maintenance
501
        schema:
502
          $ref: "../swagger.yaml#/definitions/error"
457
"/public/biblios/{biblio_id}":
503
"/public/biblios/{biblio_id}":
458
  get:
504
  get:
459
    x-mojo-to: Biblios#get_public
505
    x-mojo-to: Biblios#get_public
(-)a/api/v1/swagger/swagger.yaml (+8 lines)
Lines 289-294 paths: Link Here
289
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password"
289
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password"
290
  "/patrons/{patron_id}/password/expiration_date":
290
  "/patrons/{patron_id}/password/expiration_date":
291
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
291
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
292
  "/public/biblios":
293
    $ref: "./paths/biblios.yaml#/~1public~1biblios"
292
  "/public/biblios/{biblio_id}":
294
  "/public/biblios/{biblio_id}":
293
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}"
295
    $ref: "./paths/biblios.yaml#/~1public~1biblios~1{biblio_id}"
294
  "/public/biblios/{biblio_id}/items":
296
  "/public/biblios/{biblio_id}/items":
Lines 571-576 parameters: Link Here
571
    required: false
573
    required: false
572
    schema:
574
    schema:
573
      type: object
575
      type: object
576
  q_ccl:
577
    description: CCL query sent as a query parameter
578
    in: query
579
    name: q_ccl
580
    required: false
581
    type: string
574
  q_header:
582
  q_header:
575
    description: Query filter sent as a request header
583
    description: Query filter sent as a request header
576
    in: header
584
    in: header
(-)a/t/db_dependent/api/v1/biblios.t (-2 / +56 lines)
Lines 20-26 use Modern::Perl; Link Here
20
use utf8;
20
use utf8;
21
use Encode;
21
use Encode;
22
22
23
use Test::More tests => 11;
23
use Test::More tests => 12;
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Mojo;
25
use Test::Mojo;
26
use Test::Warn;
26
use Test::Warn;
Lines 127-132 subtest 'get() tests' => sub { Link Here
127
    $schema->storage->txn_rollback;
127
    $schema->storage->txn_rollback;
128
};
128
};
129
129
130
subtest 'get_biblios_public() tests' => sub {
131
132
    plan tests => 5;
133
134
    $schema->storage->txn_begin;
135
136
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
137
    my $patron = $builder->build_object(
138
        {
139
            class => 'Koha::Patrons',
140
            value => {
141
                flags        => undef, # opac user
142
                categorycode => $category->categorycode
143
            }
144
        }
145
    );
146
147
    my $password = 'thePassword123';
148
    $patron->set_password( { password => $password, skip_validation => 1 } );
149
    $patron->discard_changes;
150
    my $userid = $patron->userid;
151
152
    # Make sure author in shown in the OPAC
153
    my $subfields = Koha::MarcSubfieldStructures->search({ tagfield => '100' });
154
    while ( my $subfield = $subfields->next ) {
155
        $subfield->set({ hidden => -1 })->store;
156
    }
157
    Koha::Caches->get_instance()->flush_all;
158
159
    $t->get_ok( "//$userid:$password@/api/v1/public/biblios" . q{?q_ccl=test}
160
                => { Accept => 'application/weird+format' } )
161
      ->status_is(400);
162
163
    $t->get_ok( "//$userid:$password@/api/v1/public/biblios" . q{?q_ccl=test}
164
                 => { Accept => 'application/marc-in-json' } )
165
      ->status_is(200);
166
167
    subtest 'anonymous access' => sub {
168
169
       plan tests => 4;
170
171
        $t->get_ok( "/api/v1/public/biblios" . q{?q_ccl=test}
172
                    => { Accept => 'application/weird+format' } )
173
          ->status_is(400);
174
175
        $t->get_ok( "/api/v1/public/biblios" . q{?q_ccl=test}
176
                    => { Accept => 'application/marc-in-json' } )
177
          ->status_is(200);
178
179
    };
180
181
    $schema->storage->txn_rollback;
182
183
};
184
130
subtest 'get_items() tests' => sub {
185
subtest 'get_items() tests' => sub {
131
186
132
    plan tests => 8;
187
    plan tests => 8;
133
- 

Return to bug 25870