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

(-)a/Koha/Patron/Allowlist.pm (-2 / +6 lines)
Lines 25-31 sub new { Link Here
25
25
26
=head3 apply
26
=head3 apply
27
27
28
    my $ui_fields = Koha::Patron::Allowlist::Public->new->apply({ input => $hashref });
28
    my $ui_fields = Koha::Patron::Allowlist::Public->new->apply({ input => $hashref, additional_deny_list => [qw( list of fields )] });
29
29
30
Apply an allowlist to input data.
30
Apply an allowlist to input data.
31
31
Lines 34-44 Apply an allowlist to input data. Link Here
34
sub apply {
34
sub apply {
35
    my ( $self, $params ) = @_;
35
    my ( $self, $params ) = @_;
36
36
37
    my $input = $params->{input};
38
    my $additional_deny_list = $params->{additional_deny_list} || [];
39
37
    my $blocked = {};
40
    my $blocked = {};
38
    my $ui_fields = $self->{ui_fields};
41
    my $ui_fields = $self->{ui_fields};
39
    return unless $ui_fields and %$ui_fields;
42
    return unless $ui_fields and %$ui_fields;
40
43
41
    my $input = $params->{input};
44
    delete $ui_fields->{$_} for @$additional_deny_list;
45
42
    return unless $input  and %$input;
46
    return unless $input  and %$input;
43
47
44
    my @keys = keys %$input;
48
    my @keys = keys %$input;
(-)a/opac/opac-memberentry.pl (-2 / +4 lines)
Lines 135-141 if ( $action eq 'create' ) { Link Here
135
    my $consent_dt = delete $borrower{gdpr_proc_consent};
135
    my $consent_dt = delete $borrower{gdpr_proc_consent};
136
    delete $borrower{'password2'};
136
    delete $borrower{'password2'};
137
137
138
    $ui_allowlist->apply({ input => \%borrower });
138
    my @unwanted_fields = split( /\|/, C4::Context->preference('PatronSelfRegistrationBorrowerUnwantedField') || q|| );
139
    $ui_allowlist->apply({ input => \%borrower, additional_deny_list => \@unwanted_fields });
139
140
140
    my $cardnumber_error_code;
141
    my $cardnumber_error_code;
141
    if ( !grep { $_ eq 'cardnumber' } @empty_mandatory_fields ) {
142
    if ( !grep { $_ eq 'cardnumber' } @empty_mandatory_fields ) {
Lines 274-280 elsif ( $action eq 'update' ) { Link Here
274
    # Send back the data to the template
275
    # Send back the data to the template
275
    %borrower = ( %$borrower, %borrower );
276
    %borrower = ( %$borrower, %borrower );
276
277
277
    $ui_allowlist->apply({ input => \%borrower });
278
    my @unwanted_fields = split( /\|/, C4::Context->preference('PatronSelfModificationBorrowerUnwantedField') || q|| );
279
    $ui_allowlist->apply({ input => \%borrower, additional_deny_list => \@unwanted_fields });
278
280
279
    if (@empty_mandatory_fields || @$invalidformfields) {
281
    if (@empty_mandatory_fields || @$invalidformfields) {
280
        $template->param(
282
        $template->param(
(-)a/t/db_dependent/Koha/Patron/Allowlist.t (-2 / +39 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 6;
21
21
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Exception;
23
use Test::Exception;
Lines 64-66 subtest 'Public Allowlist' => sub { Link Here
64
    is( $input->{surname},  'test surname', 'surname preserved' );
64
    is( $input->{surname},  'test surname', 'surname preserved' );
65
    is( $input->{flags}, undef, 'flags filtered' );
65
    is( $input->{flags}, undef, 'flags filtered' );
66
};
66
};
67
- 
67
68
subtest 'additional_deny_list' => sub {
69
    plan tests => 10;
70
71
    my $input = { firstname => 'test firstname', surname => 'test surname' };
72
    my $allowlist = Koha::Patron::Allowlist::Public->new();
73
74
    $allowlist->apply({
75
        input => $input,
76
        additional_deny_list => [],
77
    });
78
79
    is( $input->{firstname}, 'test firstname', 'firstname preserved' );
80
    is( $input->{surname},   'test surname',   'surname filtered' );
81
    is( $input->{flags},     undef,            'flags filtered' );
82
83
    $allowlist->apply({
84
        input => $input,
85
        additional_deny_list => ['not_here'],
86
    });
87
88
    is( $input->{firstname}, 'test firstname', 'firstname preserved' );
89
    is( $input->{surname},   'test surname',   'surname filtered' );
90
    is( $input->{flags},     undef,            'flags filtered' );
91
92
    warning_like {
93
        $allowlist->apply({
94
            input => $input,
95
            additional_deny_list => ['surname'],
96
        });
97
    }
98
    qr{Forbidden - Tried to modify 'surname' with 'test surname' from};
99
100
    is( $input->{firstname}, 'test firstname', 'firstname preserved' );
101
    is( $input->{surname},   undef,            'surname filtered' );
102
    is( $input->{flags},     undef,            'flags filtered' );
103
104
};

Return to bug 28935