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

(-)a/Koha/Anonymized/Patron.pm (+82 lines)
Line 0 Link Here
1
package Koha::Anonymized::Patron;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
22
23
use Koha::Database;
24
25
use base qw(Koha::Object);
26
27
=head1 NAME
28
29
Koha::Anonymized::Patron - Koha Anonymized::Patron Object class
30
31
=head1 API
32
33
=head2 Class methods
34
35
=head3 new
36
37
=cut
38
39
sub get_hash {
40
    my ( $class, $borrowernumber) = @_;
41
    return bcrypt($borrowernumber, C4::Context->config('key'));
42
}
43
44
45
sub new_from_patron {
46
    my ( $class, $patron ) = @_;
47
48
    my $self = $class->SUPER::new({
49
        hashed_borrowernumber => $class->get_hash($patron->borrowernumber),
50
    });
51
52
    $self->update_from_patron($patron);
53
    return $self;
54
}
55
56
sub update_from_patron {
57
    my ( $self, $patron ) = @_;
58
59
    my @fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || '';
60
    my $values =
61
      { map { $_ => $patron->$_ } @fields_to_copy };
62
63
    $values->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?)
64
    $values->{categorycode} = $patron->categorycode;
65
66
    $values->{has_cardnumber} = $patron->cardnumber ? 1 : 0;
67
68
    $self->set($values);
69
    return $self;
70
}
71
72
=head2 Internal methods
73
74
=head3 _type
75
76
=cut
77
78
sub _type {
79
    return 'AnonymizedBorrower';
80
}
81
82
1;
(-)a/Koha/Anonymized/Patrons.pm (+64 lines)
Line 0 Link Here
1
package Koha::Anonymized::Patrons;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
22
23
use Koha::Database;
24
25
use Koha::Anonymized::Patron;
26
27
use base qw(Koha::Objects);
28
29
=head1 NAME
30
31
Koha::Anonymized::Patrons - Koha Anonymized Patron Object set class
32
33
=head1 API
34
35
=cut
36
37
sub find_from_borrowernumber {
38
    my ($class, $borrowernumber) = @_;
39
    my $hash = $class->get_hash($borrowernumber);
40
    return $class->find($hash);
41
}
42
sub get_hash {
43
    my ( $class, $borrowernumber) = @_;
44
    return bcrypt($borrowernumber, C4::Context->config('key'));
45
}
46
47
48
=head2 Class Methods
49
50
=cut
51
52
=head3 type
53
54
=cut
55
56
sub _type {
57
    return 'AnonymizedBorrower';
58
}
59
60
sub object_class {
61
    return 'Koha::Anonymized::Patron';
62
}
63
64
1;
(-)a/Koha/Patron.pm (-2 / +13 lines)
Lines 28-33 use Text::Unaccent qw( unac_string ); Link Here
28
use C4::Context;
28
use C4::Context;
29
use C4::Log;
29
use C4::Log;
30
use Koha::Account;
30
use Koha::Account;
31
use Koha::Anonymized::Patrons;
31
use Koha::AuthUtils;
32
use Koha::AuthUtils;
32
use Koha::Checkouts;
33
use Koha::Checkouts;
33
use Koha::Club::Enrollments;
34
use Koha::Club::Enrollments;
Lines 186-191 sub store { Link Here
186
                $self->fixup_cardnumber;
187
                $self->fixup_cardnumber;
187
            }
188
            }
188
189
190
            my $in_storage = $self->in_storage;
191
189
            unless( $self->category->in_storage ) {
192
            unless( $self->category->in_storage ) {
190
                Koha::Exceptions::Object::FKConstraint->throw(
193
                Koha::Exceptions::Object::FKConstraint->throw(
191
                    broken_fk => 'categorycode',
194
                    broken_fk => 'categorycode',
Lines 199-205 sub store { Link Here
199
            $self->surname( uc($self->surname) )
202
            $self->surname( uc($self->surname) )
200
                if C4::Context->preference("uppercasesurnames");
203
                if C4::Context->preference("uppercasesurnames");
201
204
202
            unless ( $self->in_storage ) {    #AddMember
205
            unless ( $in_storage ) {    #AddMember
203
206
204
                # Generate a valid userid/login if needed
207
                # Generate a valid userid/login if needed
205
                $self->generate_userid
208
                $self->generate_userid
Lines 338-343 sub store { Link Here
338
                # Final store
341
                # Final store
339
                $self = $self->SUPER::store;
342
                $self = $self->SUPER::store;
340
            }
343
            }
344
345
            if ( C4::Context->preference('Pseudonymization') ) {
346
                unless ( $in_storage ) {
347
                    Koha::Anonymized::Patron->new_from_patron($self)->store;
348
                } else {
349
                    Koha::Anonymized::Patrons->find_from_borrowernumber($self->borrowernumber)->update_from_patron($self)->store;
350
                }
351
            }
352
341
        }
353
        }
342
    );
354
    );
343
    return $self;
355
    return $self;
344
- 

Return to bug 24151