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

(-)a/Koha/REST/V1/Biblios.pm (-1 / +97 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Koha::Biblios;
22
use Koha::Biblios;
23
use Koha::RecordProcessor;
23
use C4::Biblio qw(DelBiblio);
24
use C4::Biblio qw(DelBiblio);
24
25
25
use MARC::Record::MiJ;
26
use MARC::Record::MiJ;
Lines 154-157 sub delete { Link Here
154
    };
155
    };
155
}
156
}
156
157
158
=head3 get_public
159
160
Controller function that handles retrieving a single biblio object
161
162
=cut
163
164
sub get_public {
165
    my $c = shift->openapi->valid_input or return;
166
167
    my $biblio = Koha::Biblios->find(
168
        { biblionumber => $c->validation->param('biblio_id') },
169
        { prefetch     => ['metadata'] } );
170
171
    unless ($biblio) {
172
        return $c->render(
173
            status  => 404,
174
            openapi => {
175
                error => "Object not found."
176
            }
177
        );
178
    }
179
180
    return try {
181
182
        my $record = $biblio->metadata->record;
183
184
        my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems');
185
        my $patron = $c->stash('koha.user');
186
187
        # Check if the biblio should be hidden for unprivileged access
188
        # unless there's a logged in user, and there's an exception for it's
189
        # category
190
        unless ( $patron and $patron->category->override_hidden_items ) {
191
            if ( $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) )
192
            {
193
                return $c->render(
194
                    status  => 404,
195
                    openapi => {
196
                        error => "Object not found."
197
                    }
198
                );
199
            }
200
        }
201
202
        my $marcflavour = C4::Context->preference("marcflavour");
203
204
        my $record_processor = Koha::RecordProcessor->new({
205
            filters => 'ViewPolicy',
206
            options => {
207
                interface => 'opac',
208
                frameworkcode => $biblio->frameworkcode
209
            }
210
        });
211
        # Apply framework's filtering to MARC::Record object
212
        $record_processor->process($record);
213
214
        $c->respond_to(
215
            marcxml => {
216
                status => 200,
217
                format => 'marcxml',
218
                text   => $record->as_xml_record
219
            },
220
            mij => {
221
                status => 200,
222
                format => 'mij',
223
                text   => $record->to_mij
224
            },
225
            marc => {
226
                status => 200,
227
                format => 'marc',
228
                text   => $record->as_usmarc
229
            },
230
            txt => {
231
                status => 200,
232
                format => 'text/plain',
233
                text   => $record->as_formatted
234
            },
235
            any => {
236
                status  => 406,
237
                openapi => [
238
                    "application/marcxml+xml",
239
                    "application/marc-in-json",
240
                    "application/marc",
241
                    "text/plain"
242
                ]
243
            }
244
        );
245
    }
246
    catch {
247
        return $c->render(
248
            status  => 500,
249
            openapi => { error => "Something went wrong, check the logs ($_)" }
250
        );
251
    };
252
}
253
157
1;
254
1;
158
- 

Return to bug 24909