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 714-719 sub add { Link Here
714
        my $flavour = $headers->header('x-record-schema');
715
        my $flavour = $headers->header('x-record-schema');
715
        $flavour //= C4::Context->preference('marcflavour');
716
        $flavour //= C4::Context->preference('marcflavour');
716
717
718
        my $record_source_id = $headers->header('x-record-source-id');
719
720
        if ($record_source_id) {
721
722
            # We've been passed a record source. Verify they are allowed to
723
            unless ( haspermission( $c->stash('koha.user')->userid, { editcatalogue => 'set_record_sources' } ) ) {
724
                return $c->render(
725
                    status  => 403,
726
                    openapi => { error => 'You do not have permission to set the record source' }
727
                );
728
            }
729
        }
730
717
        my $record;
731
        my $record;
718
732
719
        my $frameworkcode = $headers->header('x-framework-id');
733
        my $frameworkcode = $headers->header('x-framework-id');
Lines 751-762 sub add { Link Here
751
            }
765
            }
752
        ) unless !$duplicatebiblionumber || $confirm_not_duplicate;
766
        ) unless !$duplicatebiblionumber || $confirm_not_duplicate;
753
767
754
        my ( $biblionumber, $oldbibitemnum );
768
        my ( $biblio_id ) = AddBiblio( $record, $frameworkcode, { record_source_id => $record_source_id } );
755
            ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode );
756
769
757
        $c->render(
770
        $c->render(
758
            status  => 200,
771
            status  => 200,
759
            openapi => { id => $biblionumber }
772
            openapi => { id => $biblio_id }
760
        );
773
        );
761
    }
774
    }
762
    catch {
775
    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