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

(-)a/Koha/REST/Plugin/Objects.pm (-1 / +3 lines)
Lines 91-96 for API rendering. Link Here
91
91
92
            # Extract reserved params
92
            # Extract reserved params
93
            my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params($args);
93
            my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params($args);
94
            # Privileged reques?
95
            my $is_public = $c->stash('is_public');
94
            # Look for embeds
96
            # Look for embeds
95
            my $embed = $c->stash('koha.embed');
97
            my $embed = $c->stash('koha.embed');
96
98
Lines 162-168 for API rendering. Link Here
162
                }
164
                }
163
            );
165
            );
164
166
165
            return $objects->to_api({ embed => $embed });
167
            return $objects->to_api({ embed => $embed, public => $is_public });
166
        }
168
        }
167
    );
169
    );
168
}
170
}
(-)a/t/db_dependent/Koha/REST/Plugin/Objects.t (-2 / +38 lines)
Lines 79-86 get '/biblios' => sub { Link Here
79
    $c->render( status => 200, json => {count => scalar(@$biblios), biblios => $biblios} );
79
    $c->render( status => 200, json => {count => scalar(@$biblios), biblios => $biblios} );
80
};
80
};
81
81
82
get '/items/:item_id_1/:item_id_2' => sub {
83
84
    my $c = shift;
85
86
    # Emulate a public route by stashing the is_public value
87
    $c->stash( 'is_public' => 1 );
88
89
    my $item_id_1 = $c->param('item_id_1');
90
    my $item_id_2 = $c->param('item_id_2');
91
92
    my $items_rs = Koha::Items->search({ itemnumber => [ $item_id_1, $item_id_2 ] });
93
    my $items    = $c->objects->search( $items_rs );
94
95
    $c->render(
96
        status => 200,
97
        json   => $items
98
    );
99
};
100
82
# The tests
101
# The tests
83
use Test::More tests => 12;
102
use Test::More tests => 13;
84
use Test::Mojo;
103
use Test::Mojo;
85
104
86
use t::lib::Mocks;
105
use t::lib::Mocks;
Lines 512-514 subtest 'objects.find helper, embed' => sub { Link Here
512
531
513
    $schema->storage->txn_rollback;
532
    $schema->storage->txn_rollback;
514
};
533
};
515
- 
534
535
subtest 'objects.search helper, public requests' => sub {
536
537
    plan tests => 3;
538
539
    $schema->storage->txn_begin;
540
541
    my $item_1 = $builder->build_sample_item;
542
    my $item_2 = $builder->build_sample_item;
543
544
    my $t = Test::Mojo->new;
545
546
    $t->get_ok( '/items/'.$item_1->id.'/'.$item_2->id )
547
      ->json_is('/0' => $item_1->to_api({ public => 1 }), 'Public representation of $item_1 is retrieved')
548
      ->json_is('/1' => $item_2->to_api({ public => 1 }), 'Public representation of $item_2 is retrieved');
549
550
    $schema->storage->txn_rollback;
551
};

Return to bug 27358