|
Lines 38-43
use List::MoreUtils qw( any );
Link Here
|
| 38 |
|
38 |
|
| 39 |
use Koha::Logger; |
39 |
use Koha::Logger; |
| 40 |
use Koha::Auth::Identity::Providers; |
40 |
use Koha::Auth::Identity::Providers; |
|
|
41 |
use Koha::Patron::Attribute; |
| 42 |
use Koha::Patron::Attributes; |
| 41 |
|
43 |
|
| 42 |
# Check that shib config is not malformed |
44 |
# Check that shib config is not malformed |
| 43 |
|
45 |
|
|
Lines 99-105
sub checkpw_shib {
Link Here
|
| 99 |
my $config = _get_shib_config(); |
101 |
my $config = _get_shib_config(); |
| 100 |
|
102 |
|
| 101 |
# Does the given shibboleth attribute value ($match) match a valid koha user ? |
103 |
# Does the given shibboleth attribute value ($match) match a valid koha user ? |
| 102 |
my $borrowers = Koha::Patrons->search( { $config->{matchpoint} => $match } ); |
104 |
my $borrowers; |
|
|
105 |
if ( $config->{matchpoint} =~ /^patron_attribute:(.+)$/ ) { |
| 106 |
my $code = $1; |
| 107 |
$borrowers = Koha::Patrons->search( |
| 108 |
{ 'borrower_attributes.code' => $code, 'borrower_attributes.attribute' => $match }, |
| 109 |
{ join => 'borrower_attributes' } |
| 110 |
); |
| 111 |
} else { |
| 112 |
$borrowers = Koha::Patrons->search( { $config->{matchpoint} => $match } ); |
| 113 |
} |
| 103 |
if ( $borrowers->count > 1 ) { |
114 |
if ( $borrowers->count > 1 ) { |
| 104 |
|
115 |
|
| 105 |
# If we have more than 1 borrower the matchpoint is not unique |
116 |
# If we have more than 1 borrower the matchpoint is not unique |
|
Lines 129-145
sub checkpw_shib {
Link Here
|
| 129 |
sub _autocreate { |
140 |
sub _autocreate { |
| 130 |
my ( $config, $match ) = @_; |
141 |
my ( $config, $match ) = @_; |
| 131 |
|
142 |
|
| 132 |
my %borrower = ( $config->{matchpoint} => $match ); |
143 |
my ( %borrower, %patron_attrs ); |
|
|
144 |
|
| 145 |
if ( $config->{matchpoint} =~ /^patron_attribute:(.+)$/ ) { |
| 146 |
$patron_attrs{$1} = $match; |
| 147 |
} else { |
| 148 |
$borrower{ $config->{matchpoint} } = $match; |
| 149 |
} |
| 133 |
|
150 |
|
| 134 |
while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) { |
151 |
while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) { |
| 135 |
if ( C4::Context->psgi_env ) { |
152 |
my $value = |
| 136 |
$borrower{$key} = ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) || $entry->{'content'} || ''; |
153 |
C4::Context->psgi_env |
|
|
154 |
? ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) || $entry->{'content'} || '' |
| 155 |
: ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || ''; |
| 156 |
if ( $key =~ /^patron_attribute:(.+)$/ ) { |
| 157 |
$patron_attrs{$1} = $value; |
| 137 |
} else { |
158 |
} else { |
| 138 |
$borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || ''; |
159 |
$borrower{$key} = $value; |
| 139 |
} |
160 |
} |
| 140 |
} |
161 |
} |
| 141 |
|
162 |
|
| 142 |
my $patron = Koha::Patron->new( \%borrower )->store; |
163 |
my $patron = Koha::Patron->new( \%borrower )->store; |
|
|
164 |
|
| 165 |
for my $code ( keys %patron_attrs ) { |
| 166 |
Koha::Patron::Attribute->new( |
| 167 |
{ borrowernumber => $patron->borrowernumber, code => $code, attribute => $patron_attrs{$code} } )->store; |
| 168 |
} |
| 143 |
$patron->discard_changes; |
169 |
$patron->discard_changes; |
| 144 |
|
170 |
|
| 145 |
C4::Members::Messaging::SetMessagingPreferencesFromDefaults( |
171 |
C4::Members::Messaging::SetMessagingPreferencesFromDefaults( |
|
Lines 184-200
sub _autocreate {
Link Here
|
| 184 |
|
210 |
|
| 185 |
sub _sync { |
211 |
sub _sync { |
| 186 |
my ( $borrowernumber, $config, $match ) = @_; |
212 |
my ( $borrowernumber, $config, $match ) = @_; |
| 187 |
my %borrower; |
213 |
my ( %borrower, %patron_attrs ); |
| 188 |
$borrower{'borrowernumber'} = $borrowernumber; |
214 |
$borrower{'borrowernumber'} = $borrowernumber; |
| 189 |
while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) { |
215 |
while ( my ( $key, $entry ) = each %{ $config->{'mapping'} } ) { |
| 190 |
if ( C4::Context->psgi_env ) { |
216 |
my $value = |
| 191 |
$borrower{$key} = ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) || $entry->{'content'} || ''; |
217 |
C4::Context->psgi_env |
|
|
218 |
? ( $entry->{'is'} && $ENV{ "HTTP_" . uc( $entry->{'is'} ) } ) || $entry->{'content'} || '' |
| 219 |
: ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || ''; |
| 220 |
if ( $key =~ /^patron_attribute:(.+)$/ ) { |
| 221 |
$patron_attrs{$1} = $value; |
| 192 |
} else { |
222 |
} else { |
| 193 |
$borrower{$key} = ( $entry->{'is'} && $ENV{ $entry->{'is'} } ) || $entry->{'content'} || ''; |
223 |
$borrower{$key} = $value; |
| 194 |
} |
224 |
} |
| 195 |
} |
225 |
} |
| 196 |
my $patron = Koha::Patrons->find($borrowernumber); |
226 |
my $patron = Koha::Patrons->find($borrowernumber); |
| 197 |
$patron->set( \%borrower )->store; |
227 |
$patron->set( \%borrower )->store; |
|
|
228 |
for my $code ( keys %patron_attrs ) { |
| 229 |
my $existing = Koha::Patron::Attributes->search( { borrowernumber => $borrowernumber, code => $code } ); |
| 230 |
$existing->delete; |
| 231 |
Koha::Patron::Attribute->new( |
| 232 |
{ borrowernumber => $borrowernumber, code => $code, attribute => $patron_attrs{$code} } )->store; |
| 233 |
} |
| 198 |
} |
234 |
} |
| 199 |
|
235 |
|
| 200 |
sub _get_uri { |
236 |
sub _get_uri { |