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

(-)a/Koha/REST/Plugin/Objects.pm (-1 / +3 lines)
Lines 53-58 sub register { Link Here
53
53
54
            # Extract reserved params
54
            # Extract reserved params
55
            my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params($args);
55
            my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params($args);
56
            # Privileged reques?
57
            my $is_public = $c->stash('is_public');
56
            # Look for embeds
58
            # Look for embeds
57
            my $embed = $c->stash('koha.embed');
59
            my $embed = $c->stash('koha.embed');
58
60
Lines 138-144 sub register { Link Here
138
                });
140
                });
139
            }
141
            }
140
142
141
            return $objects->to_api({ embed => $embed });
143
            return $objects->to_api({ embed => $embed, public => $is_public });
142
        }
144
        }
143
    );
145
    );
144
}
146
}
(-)a/t/db_dependent/Koha/REST/Plugin/Objects.t (-3 / +38 lines)
Lines 75-83 get '/biblios' => sub { Link Here
75
    $c->render( status => 200, json => {count => scalar(@$biblios), biblios => $biblios} );
75
    $c->render( status => 200, json => {count => scalar(@$biblios), biblios => $biblios} );
76
};
76
};
77
77
78
get '/items/:item_id_1/:item_id_2' => sub {
79
80
    my $c = shift;
81
82
    # Emulate a public route by stashing the is_public value
83
    $c->stash( 'is_public' => 1 );
84
85
    my $item_id_1 = $c->param('item_id_1');
86
    my $item_id_2 = $c->param('item_id_2');
87
88
    my $items_rs = Koha::Items->search({ itemnumber => [ $item_id_1, $item_id_2 ] });
89
    my $items    = $c->objects->search( $items_rs );
90
91
    $c->render(
92
        status => 200,
93
        json   => $items
94
    );
95
};
78
96
79
# The tests
97
# The tests
80
use Test::More tests => 10;
98
use Test::More tests => 11;
81
use Test::Mojo;
99
use Test::Mojo;
82
100
83
use t::lib::Mocks;
101
use t::lib::Mocks;
Lines 423-426 subtest 'object.search helper order by embedded columns' => sub { Link Here
423
      ->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second');
441
      ->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second');
424
442
425
    $schema->storage->txn_begin;
443
    $schema->storage->txn_begin;
426
}
444
};
445
446
subtest 'objects.search helper, public requests' => sub {
447
448
    plan tests => 3;
449
450
    $schema->storage->txn_begin;
451
452
    my $item_1 = $builder->build_sample_item;
453
    my $item_2 = $builder->build_sample_item;
454
455
    my $t = Test::Mojo->new;
456
457
    $t->get_ok( '/items/'.$item_1->id.'/'.$item_2->id )
458
      ->json_is('/0' => $item_1->to_api({ public => 1 }), 'Public representation of $item_1 is retrieved')
459
      ->json_is('/1' => $item_2->to_api({ public => 1 }), 'Public representation of $item_2 is retrieved');
460
461
    $schema->storage->txn_rollback;
462
};
427
- 

Return to bug 27358