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

(-)a/Koha/REST/V1/Suggestions.pm (-6 / +12 lines)
Lines 28-33 use Koha::Suggestions; Link Here
28
28
29
use Koha::ItemTypes;
29
use Koha::ItemTypes;
30
use Koha::Libraries;
30
use Koha::Libraries;
31
use List::MoreUtils qw/any/;
31
32
32
use Try::Tiny;
33
use Try::Tiny;
33
34
Lines 173-180 sub _validate_body { Link Here
173
        }
174
        }
174
175
175
        foreach my $param ( keys %{ $body } ) {
176
        foreach my $param ( keys %{ $body } ) {
176
            unless (/^$param$/ ~~ @allowed_fields) {
177
            unless (any { /^$param$/ } @allowed_fields) {
177
                # Ouch ! Some mandatory field is missing!
178
                # Ouch ! User trying to edit field he has no rights to edit!
178
                my $verb = 'specified ';
179
                my $verb = 'specified ';
179
                return $c->render( status => 403 , openapi => {
180
                return $c->render( status => 403 , openapi => {
180
				error => 'You ' . $verb . $param . ', but allowed fields are only ' . join(', ', @allowed_fields)}
181
				error => 'You ' . $verb . $param . ', but allowed fields are only ' . join(', ', @allowed_fields)}
Lines 183-191 sub _validate_body { Link Here
183
        }
184
        }
184
    }
185
    }
185
186
187
    # Set user's branchcode if not specified (after validation input, because user does not
188
    # necessarily have rights to choose a branchcode)
189
    if ( not exists $body->{branchcode} ) {
190
	    $body->{branchcode} = C4::Context->userenv->{branch};
191
    }
186
192
187
    # Is suggester anonymous?
193
    # Is suggester anonymous?
188
    my $is_anonymous = not (defined $body->{suggestedby} and
194
    my $is_anonymous = not (exists $body->{suggestedby} and
189
        $body->{suggestedby} ne '' and
195
        $body->{suggestedby} ne '' and
190
        $body->{suggestedby} ne C4::Context->preference('AnonymousPatron'));
196
        $body->{suggestedby} ne C4::Context->preference('AnonymousPatron'));
191
197
Lines 215-235 sub _validate_body { Link Here
215
    if ( exists $body->{itemtype} ) {
221
    if ( exists $body->{itemtype} ) {
216
        my @item_types = map {$_->unblessed->{itemtype}} Koha::ItemTypes->search;
222
        my @item_types = map {$_->unblessed->{itemtype}} Koha::ItemTypes->search;
217
        return $c->render( status => 400 , openapi => {error => 'itemtype must be one of ' . join(', ', @item_types)} )
223
        return $c->render( status => 400 , openapi => {error => 'itemtype must be one of ' . join(', ', @item_types)} )
218
        unless /^$body->{itemtype}$/ ~~ @item_types;
224
	unless grep(/^$body->{itemtype}$/, @item_types);
219
    }
225
    }
220
226
221
    # Check branchcode is valid
227
    # Check branchcode is valid
222
    if ( exists $body->{branchcode} ) {
228
    if ( exists $body->{branchcode} ) {
223
        my @branch_codes = map {$_->unblessed->{branchcode}} Koha::Libraries->search;
229
        my @branch_codes = map {$_->unblessed->{branchcode}} Koha::Libraries->search;
224
        return $c->render( status => 400 , openapi => {error => 'branchcode must be one of ' . join(', ', @branch_codes)} )
230
        return $c->render( status => 400 , openapi => {error => 'branchcode must be one of ' . join(', ', @branch_codes)} )
225
        unless /^$body->{branchcode}$/ ~~ @branch_codes;
231
	unless grep(/^$body->{branchcode}$/, @branch_codes);
226
    }
232
    }
227
233
228
    # Check patron reason is valid
234
    # Check patron reason is valid
229
    if ( exists $body->{patronreason} ) {
235
    if ( exists $body->{patronreason} ) {
230
        my @authorized_values = map { $_->{authorised_value} } @{ C4::Koha::GetAuthorisedValues('OPAC_SUG') };
236
        my @authorized_values = map { $_->{authorised_value} } @{ C4::Koha::GetAuthorisedValues('OPAC_SUG') };
231
        return $c->render( status => 400, openapi => {error => 'patronreason must be one of ' . join(', ', @authorized_values)} )
237
        return $c->render( status => 400, openapi => {error => 'patronreason must be one of ' . join(', ', @authorized_values)} )
232
        unless /^$body->{patronreason}$/ ~~ @authorized_values;
238
	unless grep(/^$body->{patronreason}$/, @authorized_values);
233
    }
239
    }
234
240
235
    # Check suggestedby patron exists
241
    # Check suggestedby patron exists
(-)a/api/v1/swagger/definitions/suggestion.json (-6 / +4 lines)
Lines 6-16 Link Here
6
      "description": "unique identifier assigned automatically by Koha"
6
      "description": "unique identifier assigned automatically by Koha"
7
    },
7
    },
8
    "suggestedby": {
8
    "suggestedby": {
9
      "type": "string",
9
      "type": ["string", "null"],
10
      "description": "patron_id for the person making the suggestion, foreign key linking to the borrowers table"
10
      "description": "patron_id for the person making the suggestion, foreign key linking to the borrowers table"
11
    },
11
    },
12
    "suggesteddate": {
12
    "suggesteddate": {
13
      "type": "string",
13
      "type": ["string", "null"],
14
      "description": "the suggestion was submitted"
14
      "description": "the suggestion was submitted"
15
    },
15
    },
16
    "managedby": {
16
    "managedby": {
Lines 70-76 Link Here
70
      "description": "volume description"
70
      "description": "volume description"
71
    },
71
    },
72
    "publicationyear": {
72
    "publicationyear": {
73
      "type": "string",
73
      "type": ["string", "null"],
74
      "description": "year of publication"
74
      "description": "year of publication"
75
    },
75
    },
76
    "place": {
76
    "place": {
Lines 126-131 Link Here
126
      "description": "suggested total cost (price*quantity updated for currency)"
126
      "description": "suggested total cost (price*quantity updated for currency)"
127
    }
127
    }
128
  },
128
  },
129
  "additionalProperties": false,
129
  "additionalProperties": false
130
  "required": ["title"]
131
}
130
}
132
- 

Return to bug 17314