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 124-130 sub register { Link Here
124
                }
126
                }
125
            );
127
            );
126
128
127
            return $objects->to_api({ embed => $embed });
129
            return $objects->to_api({ embed => $embed, public => $is_public });
128
        }
130
        }
129
    );
131
    );
130
}
132
}
(-)a/t/db_dependent/Koha/REST/Plugin/Objects.t (-3 / +39 lines)
Lines 64-71 get '/biblios' => sub { Link Here
64
    $c->render( status => 200, json => {count => scalar(@$biblios), biblios => $biblios} );
64
    $c->render( status => 200, json => {count => scalar(@$biblios), biblios => $biblios} );
65
};
65
};
66
66
67
get '/items/:item_id_1/:item_id_2' => sub {
68
69
    my $c = shift;
70
71
    # Emulate a public route by stashing the is_public value
72
    $c->stash( 'is_public' => 1 );
73
74
    my $item_id_1 = $c->param('item_id_1');
75
    my $item_id_2 = $c->param('item_id_2');
76
77
    my $items_rs = Koha::Items->search({ itemnumber => [ $item_id_1, $item_id_2 ] });
78
    my $items    = $c->objects->search( $items_rs );
79
80
    $c->render(
81
        status => 200,
82
        json   => $items
83
    );
84
};
85
67
# The tests
86
# The tests
68
use Test::More tests => 10;
87
use Test::More tests => 11;
69
use Test::Mojo;
88
use Test::Mojo;
70
89
71
use t::lib::Mocks;
90
use t::lib::Mocks;
Lines 412-415 subtest 'object.search helper order by embedded columns' => sub { Link Here
412
      ->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second');
431
      ->json_is('/biblios/1/biblio_id' => $biblio1->biblionumber, 'Biblio 1 should be second');
413
432
414
    $schema->storage->txn_begin;
433
    $schema->storage->txn_begin;
415
}
434
};
435
436
subtest 'objects.search helper, public requests' => sub {
437
438
    plan tests => 3;
439
440
    $schema->storage->txn_begin;
441
442
    my $item_1 = $builder->build_sample_item;
443
    my $item_2 = $builder->build_sample_item;
444
445
    my $t = Test::Mojo->new;
446
447
    $t->get_ok( '/items/'.$item_1->id.'/'.$item_2->id )
448
      ->json_is('/0' => $item_1->to_api({ public => 1 }), 'Public representation of $item_1 is retrieved')
449
      ->json_is('/1' => $item_2->to_api({ public => 1 }), 'Public representation of $item_2 is retrieved');
450
451
    $schema->storage->txn_rollback;
452
};
416
- 

Return to bug 27358