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

(-)a/Koha/REST/V1/Authorities.pm (+37 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Mojo::Base 'Mojolicious::Controller';
20
use Mojo::Base 'Mojolicious::Controller';
21
21
22
use Koha::Authorities;
22
use Koha::Authorities;
23
use C4::AuthoritiesMarc qw( DelAuthority );
23
24
24
use List::MoreUtils qw( any );
25
use List::MoreUtils qw( any );
25
use MARC::Record::MiJ;
26
use MARC::Record::MiJ;
Lines 99-102 sub get { Link Here
99
    };
100
    };
100
}
101
}
101
102
103
=head3 delete
104
105
Controller function that handles deleting an authority object
106
107
=cut
108
109
sub delete {
110
    my $c = shift->openapi->valid_input or return;
111
112
    my $authority = Koha::Authorities->find( { authid => $c->validation->param('authority_id') } );
113
114
    if ( not defined $authority ) {
115
        return $c->render(
116
            status  => 404,
117
            openapi => { error => "Object not found" }
118
        );
119
    }
120
121
    return try {
122
        my $error = DelAuthority( { authid => $authority->authid } );
123
124
        if ($error) {
125
            return $c->render(
126
                status  => 409,
127
                openapi => { error => $error }
128
            );
129
        }
130
        else {
131
            return $c->render( status => 204, openapi => "" );
132
        }
133
    }
134
    catch {
135
        $c->unhandled_exception($_);
136
    };
137
}
138
102
1;
139
1;
(-)a/api/v1/swagger/paths/authorities.yaml (+42 lines)
Lines 50-52 Link Here
50
    x-koha-authorization:
50
    x-koha-authorization:
51
      permissions:
51
      permissions:
52
        catalogue: "1"
52
        catalogue: "1"
53
  delete:
54
    x-mojo-to: Authorities#delete
55
    operationId: deleteAuthority
56
    tags:
57
      - authorities
58
    summary: Delete authority
59
    parameters:
60
      - $ref: "../swagger.yaml#/parameters/authority_id_pp"
61
    produces:
62
      - application/json
63
    responses:
64
      "204":
65
        description: Authority deleted
66
        schema:
67
          type: string
68
      "401":
69
        description: Authentication required
70
        schema:
71
          $ref: "../swagger.yaml#/definitions/error"
72
      "403":
73
        description: Access forbidden
74
        schema:
75
          $ref: "../swagger.yaml#/definitions/error"
76
      "404":
77
        description: Biblio not found
78
        schema:
79
          $ref: "../swagger.yaml#/definitions/error"
80
      "409":
81
        description: Unable to perform action on biblio
82
        schema:
83
          $ref: "../swagger.yaml#/definitions/error"
84
      "500":
85
        description: Internal error
86
        schema:
87
          $ref: "../swagger.yaml#/definitions/error"
88
      "503":
89
        description: Under maintenance
90
        schema:
91
          $ref: "../swagger.yaml#/definitions/error"
92
    x-koha-authorization:
93
      permissions:
94
        editcatalogue: edit_catalogue
(-)a/t/db_dependent/api/v1/authorities.t (-2 / +53 lines)
Lines 20-26 use Modern::Perl; Link Here
20
use utf8;
20
use utf8;
21
use Encode;
21
use Encode;
22
22
23
use Test::More tests => 1;
23
use Test::More tests => 2;
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Mojo;
25
use Test::Mojo;
26
use Test::Warn;
26
use Test::Warn;
Lines 108-112 subtest 'get() tests' => sub { Link Here
108
      ->status_is(404)
108
      ->status_is(404)
109
      ->json_is( '/error', 'Object not found.' );
109
      ->json_is( '/error', 'Object not found.' );
110
110
111
    $schema->storage->txn_rollback;
112
};
113
114
subtest 'delete() tests' => sub {
115
116
    plan tests => 7;
117
118
    $schema->storage->txn_begin;
119
120
    my $patron = $builder->build_object(
121
        {
122
            class => 'Koha::Patrons',
123
            value => { flags => 0 } # no permissions
124
        }
125
    );
126
    my $password = 'thePassword123';
127
    $patron->set_password( { password => $password, skip_validation => 1 } );
128
    my $userid = $patron->userid;
129
130
    my $authority = $builder->build_object({ 'class' => 'Koha::Authorities', value => {
131
      marcxml => q|<?xml version="1.0" encoding="UTF-8"?>
132
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd">
133
    <controlfield tag="001">1001</controlfield>
134
    <datafield tag="110" ind1=" " ind2=" ">
135
        <subfield code="9">102</subfield>
136
        <subfield code="a">My Corporation</subfield>
137
    </datafield>
138
</record>|
139
    } });
140
141
    $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid)
142
      ->status_is(403, 'Not enough permissions makes it return the right code');
143
144
    # Add permissions
145
    $builder->build(
146
        {
147
            source => 'UserPermission',
148
            value  => {
149
                borrowernumber => $patron->borrowernumber,
150
                module_bit     => 9,
151
                code           => 'edit_catalogue'
152
            }
153
        }
154
    );
155
156
    $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid)
157
      ->status_is(204, 'SWAGGER3.2.4')
158
      ->content_is('', 'SWAGGER3.3.4');
159
160
    $t->delete_ok("//$userid:$password@/api/v1/authorities/".$authority->authid)
161
      ->status_is(404);
162
111
    $schema->storage->txn_rollback;
163
    $schema->storage->txn_rollback;
112
};
164
};
113
- 

Return to bug 31793