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

(-)a/Koha/REST/V1/Biblios.pm (-3 / +16 lines)
Lines 26-31 use Koha::RecordProcessor; Link Here
26
use C4::Biblio qw( DelBiblio AddBiblio ModBiblio );
26
use C4::Biblio qw( DelBiblio AddBiblio ModBiblio );
27
use C4::Search qw( FindDuplicate );
27
use C4::Search qw( FindDuplicate );
28
28
29
use C4::Auth qw( haspermission );
29
use C4::Barcodes::ValueBuilder;
30
use C4::Barcodes::ValueBuilder;
30
use C4::Context;
31
use C4::Context;
31
32
Lines 709-714 sub add { Link Here
709
        my $flavour = $headers->header('x-record-schema');
710
        my $flavour = $headers->header('x-record-schema');
710
        $flavour //= C4::Context->preference('marcflavour');
711
        $flavour //= C4::Context->preference('marcflavour');
711
712
713
        my $record_source_id = $headers->header('x-record-source-id');
714
715
        if ($record_source_id) {
716
717
            # We've been passed a record source. Verify they are allowed to
718
            unless ( haspermission( $c->stash('koha.user')->userid, { editcatalogue => 'set_record_sources' } ) ) {
719
                return $c->render(
720
                    status  => 403,
721
                    openapi => { error => 'You do not have permission to set the record source' }
722
                );
723
            }
724
        }
725
712
        my $record;
726
        my $record;
713
727
714
        my $frameworkcode = $headers->header('x-framework-id');
728
        my $frameworkcode = $headers->header('x-framework-id');
Lines 746-757 sub add { Link Here
746
            }
760
            }
747
        ) unless !$duplicatebiblionumber || $confirm_not_duplicate;
761
        ) unless !$duplicatebiblionumber || $confirm_not_duplicate;
748
762
749
        my ( $biblionumber, $oldbibitemnum );
763
        my ( $biblio_id ) = AddBiblio( $record, $frameworkcode, { record_source_id => $record_source_id } );
750
            ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode );
751
764
752
        $c->render(
765
        $c->render(
753
            status  => 200,
766
            status  => 200,
754
            openapi => { id => $biblionumber }
767
            openapi => { id => $biblio_id }
755
        );
768
        );
756
    }
769
    }
757
    catch {
770
    catch {
(-)a/api/v1/swagger/paths/biblios.yaml (+1 lines)
Lines 22-27 Link Here
22
      - $ref: "../swagger.yaml#/parameters/framework_id_header"
22
      - $ref: "../swagger.yaml#/parameters/framework_id_header"
23
      - $ref: "../swagger.yaml#/parameters/marc_schema_header"
23
      - $ref: "../swagger.yaml#/parameters/marc_schema_header"
24
      - $ref: "../swagger.yaml#/parameters/confirm_not_duplicate_header"
24
      - $ref: "../swagger.yaml#/parameters/confirm_not_duplicate_header"
25
      - $ref: "../swagger.yaml#/parameters/record_source_id_header"
25
    produces:
26
    produces:
26
      - application/json
27
      - application/json
27
    responses:
28
    responses:
(-)a/api/v1/swagger/swagger.yaml (+6 lines)
Lines 847-852 parameters: Link Here
847
    name: quote_id
847
    name: quote_id
848
    required: true
848
    required: true
849
    type: integer
849
    type: integer
850
  record_source_id_header:
851
    description: Internal record source identifier.
852
    name: x-record-source-id
853
    in: header
854
    required: false
855
    type: string
850
  request_id_header:
856
  request_id_header:
851
    description: Request id header
857
    description: Request id header
852
    in: header
858
    in: header
(-)a/t/db_dependent/api/v1/biblios.t (-2 / +35 lines)
Lines 857-863 subtest 'set_rating() tests' => sub { Link Here
857
857
858
subtest 'post() tests' => sub {
858
subtest 'post() tests' => sub {
859
859
860
    plan tests => 13;
860
    plan tests => 14;
861
861
862
    $schema->storage->txn_begin;
862
    $schema->storage->txn_begin;
863
863
Lines 1280-1285 subtest 'post() tests' => sub { Link Here
1280
      ->status_is(200)
1280
      ->status_is(200)
1281
      ->json_has('/id');
1281
      ->json_has('/id');
1282
1282
1283
    subtest 'x-record-source-id header tests' => sub {
1284
1285
        plan tests => 5;
1286
1287
        my $record_source =
1288
            $builder->build_object( { class => 'Koha::RecordSources', value => { can_be_edited => 0 } } );
1289
1290
        $t->post_ok(
1291
            "//$userid:$password@/api/v1/biblios" => {
1292
                'Content-Type'       => 'application/marc', 'x-framework-id' => $frameworkcode,
1293
                'x-record-source-id' => $record_source->id
1294
            } => $marc
1295
        )->status_is(403)->json_is( '/error' => 'You do not have permission to set the record source' );
1296
1297
        # Add required subpermission
1298
        $builder->build(
1299
            {
1300
                source => 'UserPermission',
1301
                value  => {
1302
                    borrowernumber => $patron->id,
1303
                    module_bit     => 9,
1304
                    code           => 'set_record_sources'
1305
                }
1306
            }
1307
        );
1308
1309
        $t->post_ok(
1310
            "//$userid:$password@/api/v1/biblios" => {
1311
                'Content-Type'       => 'application/marc', 'x-framework-id' => $frameworkcode,
1312
                'x-record-source-id' => $record_source->id
1313
            } => $marc
1314
        )->status_is(200);
1315
    };
1316
1283
    $schema->storage->txn_rollback;
1317
    $schema->storage->txn_rollback;
1284
};
1318
};
1285
1319
1286
- 

Return to bug 31791