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

(-)a/Koha/REST/Plugin/Query.pm (-26 / +8 lines)
Lines 144-152 Generates the DBIC prefetch attribute based on embedded relations, and merges in Link Here
144
            my ( $c, $args ) = @_;
144
            my ( $c, $args ) = @_;
145
            my $attributes = $args->{attributes};
145
            my $attributes = $args->{attributes};
146
            my $result_set = $args->{result_set};
146
            my $result_set = $args->{result_set};
147
            my $embed = $c->stash('koha.embed');
147
            my $embed = defined($c->stash('koha.embed')) ? $c->stash('koha.embed') : $c->stash_embed;
148
148
 
149
            return unless defined $embed;
149
            return unless $embed;
150
150
151
            my @prefetches;
151
            my @prefetches;
152
            foreach my $key (sort keys(%{$embed})) {
152
            foreach my $key (sort keys(%{$embed})) {
Lines 229-269 Merges parameters from $q_params into $filtered_params. Link Here
229
229
230
=head3 stash_embed
230
=head3 stash_embed
231
231
232
    $c->stash_embed( $c->match->endpoint->pattern->defaults->{'openapi.op_spec'} );
232
    $c->stash_embed( );
233
233
234
=cut
234
=cut
235
235
236
    $app->helper(
236
    $app->helper(
237
        'stash_embed' => sub {
237
        'stash_embed' => sub {
238
238
239
            my ( $c, $args ) = @_;
239
            my ( $c ) = @_;
240
241
            my $spec = $args->{spec} // {};
242
243
            my $embed_spec;
244
            for my $param (@{$spec->{parameters}}) {
245
                next unless $param->{name} eq 'x-koha-embed';
246
                $embed_spec = $param->{items}->{enum};
247
            }
248
            my $embed_header = $c->req->headers->header('x-koha-embed');
240
            my $embed_header = $c->req->headers->header('x-koha-embed');
249
241
            if ($embed_header) {
250
            Koha::Exceptions::BadParameter->throw("Embedding objects is not allowed on this endpoint.")
251
                if $embed_header and !defined $embed_spec;
252
253
            if ( $embed_header ) {
254
                my $THE_embed = {};
242
                my $THE_embed = {};
255
                foreach my $embed_req ( split /\s*,\s*/, $embed_header ) {
243
                foreach my $embed_req ( split /\s*,\s*/, $embed_header ) {
256
                    my $matches = grep {lc $_ eq lc $embed_req} @{ $embed_spec };
244
                    _merge_embed( _parse_embed($embed_req), $THE_embed );
257
258
                    Koha::Exceptions::BadParameter->throw(
259
                        error => 'Embeding '.$embed_req. ' is not authorised. Check your x-koha-embed headers or remove it.'
260
                    ) unless $matches;
261
262
                    _merge_embed( _parse_embed($embed_req), $THE_embed);
263
                }
245
                }
264
246
265
                $c->stash( 'koha.embed' => $THE_embed )
247
                $c->stash( 'koha.embed' => $THE_embed )
266
                    if $THE_embed;
248
                  if $THE_embed;
267
            }
249
            }
268
250
269
            return $c;
251
            return $c;
(-)a/Koha/REST/V1/Auth.pm (-2 / +1 lines)
Lines 157-163 sub authenticate_api_request { Link Here
157
    # TODO: remove the latter 'openapi.op_spec' if minimum version is bumped to at least 1.17.
157
    # TODO: remove the latter 'openapi.op_spec' if minimum version is bumped to at least 1.17.
158
    my $spec = $c->openapi->spec || $c->match->endpoint->pattern->defaults->{'openapi.op_spec'};
158
    my $spec = $c->openapi->spec || $c->match->endpoint->pattern->defaults->{'openapi.op_spec'};
159
159
160
    $c->stash_embed({ spec => $spec });
160
    $c->stash_embed();
161
    $c->stash_overrides();
161
    $c->stash_overrides();
162
162
163
    my $cookie_auth = 0;
163
    my $cookie_auth = 0;
164
- 

Return to bug 30536