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

(-)a/api/v1/swagger/definitions.json (+3 lines)
Lines 65-70 Link Here
65
  "patron_balance": {
65
  "patron_balance": {
66
    "$ref": "definitions/patron_balance.json"
66
    "$ref": "definitions/patron_balance.json"
67
  },
67
  },
68
  "patron_export": {
69
    "$ref": "definitions/patron_export.json"
70
  },
68
  "quote": {
71
  "quote": {
69
    "$ref": "definitions/quote.json"
72
    "$ref": "definitions/quote.json"
70
  },
73
  },
(-)a/api/v1/swagger/definitions/patron_export.json (+198 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "Accountline": {
5
      "type": "array"
6
    },
7
    "Accountline": {
8
      "type": "array"
9
    },
10
    "AdvancedEditorMacro": {
11
      "type": "array"
12
    },
13
    "Alert": {
14
      "type": "array"
15
    },
16
    "ApiKey": {
17
      "type": "array"
18
    },
19
    "Aqbasketuser": {
20
      "type": "array"
21
    },
22
    "Aqbudgetborrower": {
23
      "type": "array"
24
    },
25
    "AqorderUser": {
26
      "type": "array"
27
    },
28
    "Aqorder": {
29
      "type": "array"
30
    },
31
    "ArticleRequest": {
32
      "type": "array"
33
    },
34
    "Borrower": {
35
      "type": "object"
36
    },
37
    "BorrowerAttribute": {
38
      "type": "array"
39
    },
40
    "BorrowerDebarment": {
41
      "type": "array"
42
    },
43
    "BorrowerFile": {
44
      "type": "array"
45
    },
46
    "BorrowerMessagePreference": {
47
      "type": "array"
48
    },
49
    "BorrowerRelationship": {
50
      "type": "array"
51
    },
52
    "BorrowerRelationship": {
53
      "type": "array"
54
    },
55
    "CashRegisterAction": {
56
      "type": "array"
57
    },
58
    "ClubEnrollment": {
59
      "type": "array"
60
    },
61
    "ClubHoldsToPatronHold": {
62
      "type": "array"
63
    },
64
    "CourseInstructor": {
65
      "type": "array"
66
    },
67
    "CreatorBatch": {
68
      "type": "array"
69
    },
70
    "Discharge": {
71
      "type": "array"
72
    },
73
    "HoldFillTarget": {
74
      "type": "array"
75
    },
76
    "HouseboundProfile": {
77
      "type": "array"
78
    },
79
    "HouseboundRole": {
80
      "type": "array"
81
    },
82
    "HouseboundVisit": {
83
      "type": "array"
84
    },
85
    "HouseboundVisit": {
86
      "type": "array"
87
    },
88
    "Illcomment": {
89
      "type": "array"
90
    },
91
    "Illrequest": {
92
      "type": "array"
93
    },
94
    "Issue": {
95
      "type": "array"
96
    },
97
    "Issue": {
98
      "type": "array"
99
    },
100
    "ItemsLastBorrower": {
101
      "type": "array"
102
    },
103
    "MessageQueue": {
104
      "type": "array"
105
    },
106
    "Message": {
107
      "type": "array"
108
    },
109
    "Message": {
110
      "type": "array"
111
    },
112
    "OldIssue": {
113
      "type": "array"
114
    },
115
    "OldIssue": {
116
      "type": "array"
117
    },
118
    "OldReserve": {
119
      "type": "array"
120
    },
121
    "OpacNews": {
122
      "type": "array"
123
    },
124
    "PatronConsent": {
125
      "type": "array"
126
    },
127
    "PatronListPatron": {
128
      "type": "array"
129
    },
130
    "PatronList": {
131
      "type": "array"
132
    },
133
    "Patronimage": {
134
      "type": "array"
135
    },
136
    "ProblemReport": {
137
      "type": "array"
138
    },
139
    "Rating": {
140
      "type": "array"
141
    },
142
    "Reserve": {
143
      "type": "array"
144
    },
145
    "ReturnClaim": {
146
      "type": "array"
147
    },
148
    "ReturnClaim": {
149
      "type": "array"
150
    },
151
    "ReturnClaim": {
152
      "type": "array"
153
    },
154
    "ReturnClaim": {
155
      "type": "array"
156
    },
157
    "Review": {
158
      "type": "array"
159
    },
160
    "Subscriptionroutinglist": {
161
      "type": "array"
162
    },
163
    "Suggestion": {
164
      "type": "array"
165
    },
166
    "Suggestion": {
167
      "type": "array"
168
    },
169
    "Suggestion": {
170
      "type": "array"
171
    },
172
    "Suggestion": {
173
      "type": "array"
174
    },
175
    "Suggestion": {
176
      "type": "array"
177
    },
178
    "TagAll": {
179
      "type": "array"
180
    },
181
    "TagsApproval": {
182
      "type": "array"
183
    },
184
    "UserPermission": {
185
      "type": "array"
186
    },
187
    "Virtualshelfcontent": {
188
      "type": "array"
189
    },
190
    "Virtualshelfshare": {
191
      "type": "array"
192
    },
193
    "Virtualshelve": {
194
      "type": "array"
195
    }
196
  },
197
  "additionalProperties": false
198
}
(-)a/api/v1/swagger/paths.json (+6 lines)
Lines 104-109 Link Here
104
  "/patrons/{patron_id}/account/credits": {
104
  "/patrons/{patron_id}/account/credits": {
105
    "$ref": "paths/patrons_account.json#/~1patrons~1{patron_id}~1account~1credits"
105
    "$ref": "paths/patrons_account.json#/~1patrons~1{patron_id}~1account~1credits"
106
  },
106
  },
107
  "/patrons/{patron_id}/export": {
108
    "$ref": "paths/patrons_export.json#/~1patrons~1{patron_id}~1export"
109
  },
107
  "/patrons/{patron_id}/password": {
110
  "/patrons/{patron_id}/password": {
108
    "$ref": "paths/patrons_password.json#/~1patrons~1{patron_id}~1password"
111
    "$ref": "paths/patrons_password.json#/~1patrons~1{patron_id}~1password"
109
  },
112
  },
Lines 128-133 Link Here
128
  "/public/biblios/{biblio_id}": {
131
  "/public/biblios/{biblio_id}": {
129
    "$ref": "paths/biblios.json#/~1public~1biblios~1{biblio_id}"
132
    "$ref": "paths/biblios.json#/~1public~1biblios~1{biblio_id}"
130
  },
133
  },
134
  "/public/patrons/{patron_id}/export": {
135
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1export"
136
  },
131
  "/public/patrons/{patron_id}/password": {
137
  "/public/patrons/{patron_id}/password": {
132
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1password"
138
    "$ref": "paths/public_patrons.json#/~1public~1patrons~1{patron_id}~1password"
133
  },
139
  },
(-)a/api/v1/swagger/paths/patrons_export.json (+62 lines)
Line 0 Link Here
1
{
2
  "/patrons/{patron_id}/export": {
3
    "get": {
4
      "x-mojo-to": "Patrons::Export#get",
5
      "operationId": "getPatronExport",
6
      "tags": [
7
        "patron"
8
      ],
9
      "parameters": [
10
        {
11
          "$ref": "../parameters.json#/patron_id_pp"
12
        }
13
      ],
14
      "produces": [
15
        "application/json"
16
      ],
17
      "responses": {
18
        "200": {
19
          "description": "Patron's data export",
20
          "schema": {
21
            "$ref": "../definitions.json#/patron_export"
22
          }
23
        },
24
        "401": {
25
          "description": "Authentication required",
26
          "schema": {
27
            "$ref": "../definitions.json#/error"
28
          }
29
        },
30
        "403": {
31
          "description": "Access forbidden",
32
          "schema": {
33
            "$ref": "../definitions.json#/error"
34
          }
35
        },
36
        "404": {
37
          "description": "Patron not found",
38
          "schema": {
39
            "$ref": "../definitions.json#/error"
40
          }
41
        },
42
        "500": {
43
          "description": "Internal server error",
44
          "schema": {
45
            "$ref": "../definitions.json#/error"
46
          }
47
        },
48
        "503": {
49
          "description": "Under maintenance",
50
          "schema": {
51
            "$ref": "../definitions.json#/error"
52
          }
53
        }
54
      },
55
      "x-koha-authorization": {
56
        "permissions": {
57
          "borrowers": "edit_borrowers"
58
        }
59
      }
60
    }
61
  }
62
}
(-)a/api/v1/swagger/paths/public_patrons.json (-1 / +62 lines)
Lines 1-4 Link Here
1
{
1
{
2
    "/public/patrons/{patron_id}/export": {
3
      "get": {
4
        "x-mojo-to": "Patrons::Export#get_public",
5
        "operationId": "getPublicPatronExport",
6
        "tags": [
7
          "patron"
8
        ],
9
        "parameters": [
10
          {
11
            "$ref": "../parameters.json#/patron_id_pp"
12
          }
13
        ],
14
        "produces": [
15
          "application/json"
16
        ],
17
        "responses": {
18
          "200": {
19
            "description": "Patron's data export",
20
            "schema": {
21
              "$ref": "../definitions.json#/patron_export"
22
            }
23
          },
24
          "401": {
25
            "description": "Authentication required",
26
            "schema": {
27
              "$ref": "../definitions.json#/error"
28
            }
29
          },
30
          "403": {
31
            "description": "Access forbidden",
32
            "schema": {
33
              "$ref": "../definitions.json#/error"
34
            }
35
          },
36
          "404": {
37
            "description": "Patron not found",
38
            "schema": {
39
              "$ref": "../definitions.json#/error"
40
            }
41
          },
42
          "500": {
43
            "description": "Internal server error",
44
            "schema": {
45
              "$ref": "../definitions.json#/error"
46
            }
47
          },
48
          "503": {
49
            "description": "Under maintenance",
50
            "schema": {
51
              "$ref": "../definitions.json#/error"
52
            }
53
          }
54
        },
55
        "x-koha-authorization": {
56
          "permissions": {
57
            "borrowers": "edit_borrowers"
58
          },
59
          "allow-owner": true
60
        }
61
      }
62
    },
2
    "/public/patrons/{patron_id}/password": {
63
    "/public/patrons/{patron_id}/password": {
3
        "post": {
64
        "post": {
4
            "x-mojo-to": "Patrons::Password#set_public",
65
            "x-mojo-to": "Patrons::Password#set_public",
Lines 237-240 Link Here
237
            }
298
            }
238
        }
299
        }
239
    }
300
    }
240
}
301
}
(-)a/t/db_dependent/api/v1/patrons_export.t (-1 / +80 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 1;
21
22
use Test::Mojo;
23
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
26
27
my $schema  = Koha::Database->new->schema;
28
my $builder = t::lib::TestBuilder->new;
29
30
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
31
32
my $t = Test::Mojo->new('Koha::REST::V1');
33
34
subtest 'validate patrons_export OpenAPI definition' => sub {
35
36
    my @related_sources = _get_related_sources();
37
    plan tests => scalar @related_sources;
38
39
    $schema->storage->txn_begin;
40
41
    # Load OpenAPI schema
42
    my $validator = JSON::Validator::OpenAPI::Mojolicious->new;
43
    my $intradir = C4::Context->config('intranetdir');
44
    my $swagger_schema =  "$intradir/api/v1/swagger/swagger.json";
45
    my $api_spec = $validator->bundle(
46
        {
47
            replace => 1,
48
            schema => $swagger_schema
49
        }
50
    );
51
    # Get patron export properties
52
    my $objs = $api_spec->{definitions}->{patron_export}->{properties};
53
54
    # Test OpenAPI property existence for all related sources
55
    my $result_source = Koha::Patron->new->_result()->result_source;
56
    foreach my $rel ( _get_related_sources() ) {
57
        my $related_source = $schema->source($rel);
58
        ok(
59
           exists $objs->{$related_source->source_name},
60
                          $related_source->source_name
61
        );
62
    }
63
64
    $schema->storage->txn_rollback;
65
};
66
67
sub _get_related_sources {
68
    my $sources = {};
69
    my $res_source = Koha::Patron->new->_result()->result_source;
70
    foreach my $rel ( Koha::Patron->new->_result()->relationships() ) {
71
        my $related_source = $res_source->related_source($rel);
72
        my $info = $res_source->relationship_info( $rel );
73
        next if $info->{'attrs'}->{'is_depends_on'};
74
        next if $sources->{$related_source->source_name};
75
        $sources->{$related_source->source_name} = 1;
76
    }
77
    $sources->{'Borrower'} = 1; # add Borrower itself
78
    my @sorted = sort keys %$sources;
79
    return @sorted;
80
}

Return to bug 20028