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

(-)a/Koha/Patron/Allowlist.pm (+54 lines)
Line 0 Link Here
1
package Koha::Patron::Allowlist;
2
3
use Modern::Perl;
4
5
=head1 NAME
6
7
Koha::Patron::Allowlist - Allowlist implementation for Koha::Patron 
8
9
=head1 API
10
11
=head2 Class Methods
12
13
=head3 new
14
15
=cut
16
17
sub new {
18
    my ($class, $args) = @_;
19
    $args = {} unless defined $args;
20
    my $self = bless ($args, $class);
21
	$self->{ui_fields} = $self->_get_ui_fields() unless $self->{ui_fields};
22
    return $self;
23
}
24
25
=head3 apply
26
27
Apply an allowlist to input data
28
29
=cut
30
31
sub apply {
32
    my ( $self, $params ) = @_;
33
	my $blocked = {};
34
	my $ui_fields = $self->{ui_fields};
35
    if ($ui_fields && ref $ui_fields eq 'HASH'){
36
        my $input = $params->{input};
37
        if ( $input && ref $input eq 'HASH' ){
38
            my @keys = keys %$input;
39
            foreach my $key (@keys){
40
                if ( ! $ui_fields->{ $key } ){
41
                    #NOTE: We capture the deleted data so that it can be used for logging purposes
42
                    $blocked->{$key} = delete $input->{ $key };
43
                }
44
            }
45
        }
46
    }
47
    return $blocked;
48
}
49
50
sub _get_ui_fields {
51
	return undef;
52
}
53
54
1;
(-)a/Koha/Patron/Allowlist/Public.pm (+65 lines)
Line 0 Link Here
1
package Koha::Patron::Allowlist::Public;
2
3
use parent 'Koha::Patron::Allowlist';
4
5
sub _get_ui_fields {
6
    my $ui_fields = {
7
        'cardnumber' => 1,
8
        'surname' => 1,
9
        'firstname' => 1,
10
        'title' => 1,
11
        'othernames' => 1,
12
        'initials' => 1,
13
        'streetnumber' => 1,
14
        'streettype' => 1,
15
        'address' => 1,
16
        'address2' => 1,
17
        'city' => 1,
18
        'state' => 1,
19
        'zipcode' => 1,
20
        'country' => 1,
21
        'email' => 1,
22
        'phone' => 1,
23
        'mobile' => 1,
24
        'fax' => 1,
25
        'emailpro' => 1,
26
        'phonepro' => 1,
27
        'B_streetnumber' => 1,
28
        'B_streettype' => 1,
29
        'B_address' => 1,
30
        'B_address2' => 1,
31
        'B_city' => 1,
32
        'B_state' => 1,
33
        'B_zipcode' => 1,
34
        'B_country' => 1,
35
        'B_email' => 1,
36
        'B_phone' => 1,
37
        'dateofbirth' => 1,
38
        'dateenrolled' => undef,
39
        'dateexpiry' => undef,
40
        'branchcode' => 1,
41
        'categorycode' => 1,
42
        'contactname' => 1,
43
        'contactfirstname' => 1,
44
        'borrowernotes' => undef,
45
        'sex' => 1,
46
        'password' => 1,
47
        'userid' => 1,
48
        'opacnote' => undef,
49
        'contactnote' => 1,
50
        'altcontactfirstname' => 1,
51
        'altcontactsurname' => 1,
52
        'altcontactaddress1' => 1,
53
        'altcontactaddress2' => 1,
54
        'altcontactaddress3' => 1,
55
        'altcontactstate' => 1,
56
        'altcontactzipcode' => 1,
57
        'altcontactcountry' => 1,
58
        'altcontactphone' => 1,
59
        'smsalertnumber' => 1,
60
        'primary_contact_method' => 1,
61
    };
62
    return $ui_fields;
63
}
64
65
1;
(-)a/Koha/Patron/Allowlist/Staff.pm (+70 lines)
Line 0 Link Here
1
package Koha::Patron::Allowlist::Staff;
2
3
use parent 'Koha::Patron::Allowlist';
4
5
sub _get_ui_fields {
6
    my $ui_fields = {
7
        'cardnumber' => 1,
8
        'surname' => 1,
9
        'firstname' => 1,
10
        'title' => 1,
11
        'othernames' => 1,
12
        'initials' => 1,
13
        'streetnumber' => 1,
14
        'streettype' => 1,
15
        'address' => 1,
16
        'address2' => 1,
17
        'city' => 1,
18
        'state' => 1,
19
        'zipcode' => 1,
20
        'country' => 1,
21
        'email' => 1,
22
        'phone' => 1,
23
        'mobile' => 1,
24
        'fax' => 1,
25
        'emailpro' => 1,
26
        'phonepro' => 1,
27
        'B_streetnumber' => 1,
28
        'B_streettype' => 1,
29
        'B_address' => 1,
30
        'B_address2' => 1,
31
        'B_city' => 1,
32
        'B_state' => 1,
33
        'B_zipcode' => 1,
34
        'B_country' => 1,
35
        'B_email' => 1,
36
        'B_phone' => 1,
37
        'dateofbirth' => 1,
38
        'dateenrolled' => 1,
39
        'dateexpiry' => 1,
40
        'branchcode' => 1,
41
        'categorycode' => 1,
42
        'contactname' => 1,
43
        'contactfirstname' => 1,
44
        'borrowernotes' => 1,
45
        'sex' => 1,
46
        'password' => 1,
47
        'userid' => 1,
48
        'opacnote' => 1,
49
        'contactnote' => 1,
50
        'altcontactfirstname' => 1,
51
        'altcontactsurname' => 1,
52
        'altcontactaddress1' => 1,
53
        'altcontactaddress2' => 1,
54
        'altcontactaddress3' => 1,
55
        'altcontactstate' => 1,
56
        'altcontactzipcode' => 1,
57
        'altcontactcountry' => 1,
58
        'altcontactphone' => 1,
59
        'smsalertnumber' => 1,
60
        'primary_contact_method' => 1,
61
        'autorenew_checkouts' => 1,
62
        'sort1' => 1,
63
        'sort2' => 1,
64
        'gonenoaddress' => 1,
65
        'lost' => 1,
66
    };
67
    return $ui_fields;
68
}
69
70
1;
(-)a/members/memberentry.pl (+6 lines)
Lines 46-51 use Koha::Patron::HouseboundRoles; Link Here
46
use Koha::Token;
46
use Koha::Token;
47
use Email::Valid;
47
use Email::Valid;
48
use Koha::SMS::Providers;
48
use Koha::SMS::Providers;
49
use Koha::Patron::Allowlist::Staff;
50
51
my $ui_allowlist = Koha::Patron::Allowlist::Staff->new();
52
49
53
50
my $input = CGI->new;
54
my $input = CGI->new;
51
my %data;
55
my %data;
Lines 429-434 if ( defined $sms ) { Link Here
429
    $newdata{smsalertnumber} = $sms;
433
    $newdata{smsalertnumber} = $sms;
430
}
434
}
431
435
436
$ui_allowlist->apply({ input => \%newdata });
437
432
###  Error checks should happen before this line.
438
###  Error checks should happen before this line.
433
$nok = $nok || scalar(@errors);
439
$nok = $nok || scalar(@errors);
434
if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
440
if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){
(-)a/opac/opac-memberentry.pl (-1 / +11 lines)
Lines 45-50 use Koha::Patron::Modifications; Link Here
45
use Koha::Patron::Categories;
45
use Koha::Patron::Categories;
46
use Koha::Token;
46
use Koha::Token;
47
use Koha::AuthorisedValues;
47
use Koha::AuthorisedValues;
48
49
use Koha::Patron::Allowlist::Public;
50
51
my $ui_allowlist = Koha::Patron::Allowlist::Public->new();
52
48
my $cgi = CGI->new;
53
my $cgi = CGI->new;
49
my $dbh = C4::Context->dbh;
54
my $dbh = C4::Context->dbh;
50
55
Lines 127-133 if ( $action eq 'create' ) { Link Here
127
132
128
    my @empty_mandatory_fields = (CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) );
133
    my @empty_mandatory_fields = (CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) );
129
    my $invalidformfields = CheckForInvalidFields(\%borrower);
134
    my $invalidformfields = CheckForInvalidFields(\%borrower);
135
    my $consent_dt = delete $borrower{gdpr_proc_consent};
130
    delete $borrower{'password2'};
136
    delete $borrower{'password2'};
137
138
    $ui_allowlist->apply({ input => \%borrower });
139
131
    my $cardnumber_error_code;
140
    my $cardnumber_error_code;
132
    if ( !grep { $_ eq 'cardnumber' } @empty_mandatory_fields ) {
141
    if ( !grep { $_ eq 'cardnumber' } @empty_mandatory_fields ) {
133
        # No point in checking the cardnumber if it's missing and mandatory, it'll just generate a
142
        # No point in checking the cardnumber if it's missing and mandatory, it'll just generate a
Lines 218-224 if ( $action eq 'create' ) { Link Here
218
            );
227
            );
219
228
220
            $borrower{password}         ||= Koha::AuthUtils::generate_password(Koha::Patron::Categories->find($borrower{categorycode}));
229
            $borrower{password}         ||= Koha::AuthUtils::generate_password(Koha::Patron::Categories->find($borrower{categorycode}));
221
            my $consent_dt = delete $borrower{gdpr_proc_consent};
222
            my $patron = Koha::Patron->new( \%borrower )->store;
230
            my $patron = Koha::Patron->new( \%borrower )->store;
223
            Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $consent_dt;
231
            Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $consent_dt;
224
            if ( $patron ) {
232
            if ( $patron ) {
Lines 266-271 elsif ( $action eq 'update' ) { Link Here
266
    # Send back the data to the template
274
    # Send back the data to the template
267
    %borrower = ( %$borrower, %borrower );
275
    %borrower = ( %$borrower, %borrower );
268
276
277
    $ui_allowlist->apply({ input => \%borrower });
278
269
    if (@empty_mandatory_fields || @$invalidformfields) {
279
    if (@empty_mandatory_fields || @$invalidformfields) {
270
        $template->param(
280
        $template->param(
271
            empty_mandatory_fields => \@empty_mandatory_fields,
281
            empty_mandatory_fields => \@empty_mandatory_fields,
(-)a/t/Koha/Patron/Allowlist.t (-1 / +48 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 => 4;
21
22
use Test::MockModule;
23
use Test::Exception;
24
25
use t::lib::Mocks;
26
27
use_ok('Koha::Patron::Allowlist::Staff');
28
use_ok('Koha::Patron::Allowlist::Public');
29
30
subtest 'Staff Allowlist' => sub {
31
    plan tests => 3;
32
    my $input = { firstname => 'test firstname', surname => 'test surname', flags => '1' };
33
    my $allowlist = Koha::Patron::Allowlist::Staff->new();
34
    $allowlist->apply({ input => $input, });
35
    ok( $input->{firstname} eq 'test firstname', 'firstname preserved' );
36
    ok( $input->{surname} eq 'test surname', 'surname preserved' );
37
    is( $input->{flags}, undef, 'flags filtered' );
38
};
39
40
subtest 'Public Allowlist' => sub {
41
    plan tests => 3;
42
    my $input = { firstname => 'test firstname', surname => 'test surname', flags => '1' };
43
    my $allowlist = Koha::Patron::Allowlist::Public->new();
44
    $allowlist->apply({ input => $input, });
45
    ok( $input->{firstname} eq 'test firstname', 'firstname preserved' );
46
    ok( $input->{surname} eq 'test surname', 'surname preserved' );
47
    is( $input->{flags}, undef, 'flags filtered' );
48
};

Return to bug 28929