@@ -, +, @@ is modified * 1 for patrons' data (anonymized_borrowers) * 1 for transactions (anonymized_transactions) * 1 for patrons' attributes (anonymized_borrower_attributes) * syspref Pseudonymization to turn on/off the whole feature * syspref PseudonymizationPatronFields to list the informations of the patrons to sync * syspref PseudonymizationTransactionFields to list the informations of the transactions to copy * DB column borrower_attribute_types.keep_for_anonymized that is a boolean to enable/disable the copy of a given patron's attribute type. % htpasswd -bnBC 10 "" password | tr -d ':\n' | sed 's/$2y/$2a/' it should be something like: $2a$10$PfdrEBdRcL2MZlEtKueyLegxI6zg735jD07GRnc1bt.N/ZYMvBAB2 --- Koha/Anonymized/Patron.pm | 82 ++++++++++++++++++++++++++++++++++++++++++++++ Koha/Anonymized/Patrons.pm | 64 ++++++++++++++++++++++++++++++++++++ Koha/Patron.pm | 14 +++++++- 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 Koha/Anonymized/Patron.pm create mode 100644 Koha/Anonymized/Patrons.pm --- a/Koha/Anonymized/Patron.pm +++ a/Koha/Anonymized/Patron.pm @@ -0,0 +1,82 @@ +package Koha::Anonymized::Patron; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; +use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Anonymized::Patron - Koha Anonymized::Patron Object class + +=head1 API + +=head2 Class methods + +=head3 new + +=cut + +sub get_hash { + my ( $class, $borrowernumber) = @_; + return bcrypt($borrowernumber, C4::Context->config('key')); +} + + +sub new_from_patron { + my ( $class, $patron ) = @_; + + my $self = $class->SUPER::new({ + hashed_borrowernumber => $class->get_hash($patron->borrowernumber), + }); + + $self->update_from_patron($patron); + return $self; +} + +sub update_from_patron { + my ( $self, $patron ) = @_; + + my @fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || ''; + my $values = + { map { $_ => $patron->$_ } @fields_to_copy }; + + $values->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?) + $values->{categorycode} = $patron->categorycode; + + $values->{has_cardnumber} = $patron->cardnumber ? 1 : 0; + + $self->set($values); + return $self; +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'AnonymizedBorrower'; +} + +1; --- a/Koha/Anonymized/Patrons.pm +++ a/Koha/Anonymized/Patrons.pm @@ -0,0 +1,64 @@ +package Koha::Anonymized::Patrons; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; +use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64); + +use Koha::Database; + +use Koha::Anonymized::Patron; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Anonymized::Patrons - Koha Anonymized Patron Object set class + +=head1 API + +=cut + +sub find_from_borrowernumber { + my ($class, $borrowernumber) = @_; + my $hash = $class->get_hash($borrowernumber); + return $class->find($hash); +} +sub get_hash { + my ( $class, $borrowernumber) = @_; + return bcrypt($borrowernumber, C4::Context->config('key')); +} + + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'AnonymizedBorrower'; +} + +sub object_class { + return 'Koha::Anonymized::Patron'; +} + +1; --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -28,6 +28,7 @@ use Text::Unaccent qw( unac_string ); use C4::Context; use C4::Log; use Koha::Account; +use Koha::Anonymized::Patrons; use Koha::AuthUtils; use Koha::Checkouts; use Koha::Club::Enrollments; @@ -186,6 +187,8 @@ sub store { $self->fixup_cardnumber; } + my $in_storage = $self->in_storage; + unless( $self->category->in_storage ) { Koha::Exceptions::Object::FKConstraint->throw( broken_fk => 'categorycode', @@ -199,7 +202,7 @@ sub store { $self->surname( uc($self->surname) ) if C4::Context->preference("uppercasesurnames"); - unless ( $self->in_storage ) { #AddMember + unless ( $in_storage ) { #AddMember # Generate a valid userid/login if needed $self->generate_userid @@ -338,6 +341,15 @@ sub store { # Final store $self = $self->SUPER::store; } + + if ( C4::Context->preference('Pseudonymization') ) { + unless ( $in_storage ) { + Koha::Anonymized::Patron->new_from_patron($self)->store; + } else { + Koha::Anonymized::Patrons->find_from_borrowernumber($self->borrowernumber)->update_from_patron($self)->store; + } + } + } ); return $self; --