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

(-)a/C4/Auth_with_ldap.pm (-1 / +1 lines)
Lines 223-229 sub checkpw_ldap { Link Here
223
                warn "ERROR_extended_unique_id_failed $attr->{code} $attr->{value}";
223
                warn "ERROR_extended_unique_id_failed $attr->{code} $attr->{value}";
224
            }
224
            }
225
        }
225
        }
226
        C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, \@unique_attr);
226
        C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, \@unique_attr, 'no_branch_limit');
227
    }
227
    }
228
return(1, $cardnumber, $userid);
228
return(1, $cardnumber, $userid);
229
}
229
}
(-)a/C4/Members/Attributes.pm (-3 / +36 lines)
Lines 71-77 marked for OPAC display are returned. Link Here
71
sub GetBorrowerAttributes {
71
sub GetBorrowerAttributes {
72
    my $borrowernumber = shift;
72
    my $borrowernumber = shift;
73
    my $opac_only = @_ ? shift : 0;
73
    my $opac_only = @_ ? shift : 0;
74
    my $branch_limit = @_ ? shift : 0;
75
74
76
    my $dbh = C4::Context->dbh();
75
    my $dbh = C4::Context->dbh();
77
    my $query = "SELECT code, description, attribute, lib, password, display_checkout, category_code, class
76
    my $query = "SELECT code, description, attribute, lib, password, display_checkout, category_code, class
Lines 218-227 replacing any that existed previously. Link Here
218
sub SetBorrowerAttributes {
217
sub SetBorrowerAttributes {
219
    my $borrowernumber = shift;
218
    my $borrowernumber = shift;
220
    my $attr_list = shift;
219
    my $attr_list = shift;
220
    my $no_branch_limit = shift // 0;
221
221
222
    my $dbh = C4::Context->dbh;
222
    my $dbh = C4::Context->dbh;
223
    my $delsth = $dbh->prepare("DELETE FROM borrower_attributes WHERE borrowernumber = ?");
223
224
    $delsth->execute($borrowernumber);
224
    DeleteBorrowerAttributes( $borrowernumber, $no_branch_limit );
225
225
226
    my $sth = $dbh->prepare("INSERT INTO borrower_attributes (borrowernumber, code, attribute, password)
226
    my $sth = $dbh->prepare("INSERT INTO borrower_attributes (borrowernumber, code, attribute, password)
227
                             VALUES (?, ?, ?, ?)");
227
                             VALUES (?, ?, ?, ?)");
Lines 236-241 sub SetBorrowerAttributes { Link Here
236
    return 1; # borrower attributes successfully set
236
    return 1; # borrower attributes successfully set
237
}
237
}
238
238
239
=head2 DeleteBorrowerAttributes
240
241
  DeleteBorrowerAttributes($borrowernumber);
242
243
Delete borrower attributes for the patron identified by C<$borrowernumber>.
244
245
=cut
246
247
sub DeleteBorrowerAttributes {
248
    my $borrowernumber = shift;
249
    my $no_branch_limit = @_ ? shift : 0;
250
    my $branch_limit = $no_branch_limit
251
        ? 0
252
        : C4::Context->userenv ? C4::Context->userenv->{"branch"} : 0;
253
254
    my $dbh = C4::Context->dbh;
255
    my $query = q{
256
        DELETE borrower_attributes FROM borrower_attributes
257
        };
258
259
    $query .= $branch_limit
260
        ? q{
261
            LEFT JOIN borrower_attribute_types_branches ON bat_code = code
262
            WHERE b_branchcode = ? OR b_branchcode IS NULL
263
                AND borrowernumber = ?
264
        }
265
        : q{
266
            WHERE borrowernumber = ?
267
        };
268
269
    $dbh->do( $query, undef, $branch_limit ? $branch_limit : (), $borrowernumber );
270
}
271
239
=head2 DeleteBorrowerAttribute
272
=head2 DeleteBorrowerAttribute
240
273
241
  DeleteBorrowerAttribute($borrowernumber, $attribute);
274
  DeleteBorrowerAttribute($borrowernumber, $attribute);
(-)a/members/nl-search.pl (-1 / +1 lines)
Lines 140-146 if ( $op && $op eq 'search' ) { Link Here
140
        # Add extended patron attributes
140
        # Add extended patron attributes
141
        SetBorrowerAttributes($borrowernumber, [
141
        SetBorrowerAttributes($borrowernumber, [
142
            { code => 'fnr', value => $cgi->param('fnr_hash') },
142
            { code => 'fnr', value => $cgi->param('fnr_hash') },
143
        ] );
143
        ], 'no_branch_limit' );
144
        # Override the default sync data created by AddMember
144
        # Override the default sync data created by AddMember
145
        my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({
145
        my $borrowersync = Koha::Database->new->schema->resultset('BorrowerSync')->find({
146
            'synctype'       => 'norwegianpatrondb',
146
            'synctype'       => 'norwegianpatrondb',
(-)a/t/db_dependent/Members_Attributes.t (-26 / +53 lines)
Lines 23-30 use C4::Context; Link Here
23
use C4::Members;
23
use C4::Members;
24
use C4::Members::AttributeTypes;
24
use C4::Members::AttributeTypes;
25
use Koha::Database;
25
use Koha::Database;
26
use t::lib::TestBuilder;
26
27
27
use Test::More tests => 60;
28
use Test::More tests => 57;
28
29
29
use t::lib::TestBuilder;
30
use t::lib::TestBuilder;
30
31
Lines 40-66 $dbh->do(q|DELETE FROM issues|); Link Here
40
$dbh->do(q|DELETE FROM borrowers|);
41
$dbh->do(q|DELETE FROM borrowers|);
41
$dbh->do(q|DELETE FROM borrower_attributes|);
42
$dbh->do(q|DELETE FROM borrower_attributes|);
42
$dbh->do(q|DELETE FROM borrower_attribute_types|);
43
$dbh->do(q|DELETE FROM borrower_attribute_types|);
43
44
my $library = $builder->build({
44
my $library = $builder->build({
45
    source => 'Branch',
45
    source => 'Branch',
46
});
46
});
47
my $borrowernumber = AddMember(
48
    firstname =>  'my firstname',
49
    surname => 'my surname',
50
    categorycode => 'S',
51
    branchcode => $library->{branchcode},
52
);
53
47
48
my $patron = $builder->build(
49
    {   source => 'Borrower',
50
        value  => {
51
            firstname    => 'my firstname',
52
            surname      => 'my surname',
53
            categorycode => 'S',
54
            branchcode => $library->{branchcode},
55
        }
56
    }
57
);
58
C4::Context->_new_userenv('DUMMY SESSION');
59
C4::Context->set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', $library->{branchcode}, 'My Library', 0);
60
my $borrowernumber = $patron->{borrowernumber};
54
61
55
my $attribute_type1 = C4::Members::AttributeTypes->new('my code1', 'my description1');
62
my $attribute_type1 = C4::Members::AttributeTypes->new('my code1', 'my description1');
56
$attribute_type1->unique_id(1);
63
$attribute_type1->unique_id(1);
57
my $attribute_type2 = C4::Members::AttributeTypes->new('my code2', 'my description2');
58
$attribute_type2->opac_display(1);
59
$attribute_type2->staff_searchable(1);
60
61
my $attribute_types = C4::Members::Attributes::GetAttributes();
64
my $attribute_types = C4::Members::Attributes::GetAttributes();
62
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types' );
65
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types' );
63
64
$attribute_type1->store();
66
$attribute_type1->store();
65
$attribute_types = C4::Members::Attributes::GetAttributes();
67
$attribute_types = C4::Members::Attributes::GetAttributes();
66
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types' );
68
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types' );
Lines 68-73 is( $attribute_types->[0], $attribute_type1->code(), 'GetAttributes returns the Link Here
68
$attribute_types = C4::Members::Attributes::GetAttributes(1);
70
$attribute_types = C4::Members::Attributes::GetAttributes(1);
69
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
71
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
70
72
73
my $attribute_type2 = C4::Members::AttributeTypes->new('my code2', 'my description2');
74
$attribute_type2->opac_display(1);
75
$attribute_type2->staff_searchable(1);
71
$attribute_type2->store();
76
$attribute_type2->store();
72
$attribute_types = C4::Members::Attributes::GetAttributes();
77
$attribute_types = C4::Members::Attributes::GetAttributes();
73
is( @$attribute_types, 2, 'GetAttributes returns the correct number of attribute types' );
78
is( @$attribute_types, 2, 'GetAttributes returns the correct number of attribute types' );
Lines 75-80 is( $attribute_types->[1], $attribute_type2->code(), 'GetAttributes returns the Link Here
75
$attribute_types = C4::Members::Attributes::GetAttributes(1);
80
$attribute_types = C4::Members::Attributes::GetAttributes(1);
76
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
81
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
77
82
83
my $new_library = $builder->build( { source => 'Branch' } );
84
my $attribute_type_limited = C4::Members::AttributeTypes->new('my code3', 'my description3');
85
$attribute_type_limited->branches([ $new_library->{branchcode} ]);
86
$attribute_type_limited->store;
78
87
79
my $borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
88
my $borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
80
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
89
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
Lines 91-96 my $attributes = [ Link Here
91
        value => 'my attribute2',
100
        value => 'my attribute2',
92
        code => $attribute_type2->code(),
101
        code => $attribute_type2->code(),
93
        password => 'my password2',
102
        password => 'my password2',
103
    },
104
    {
105
        value => 'my attribute limited',
106
        code => $attribute_type_limited->code(),
94
    }
107
    }
95
];
108
];
96
109
Lines 107-113 is( $set_borrower_attributes, 1, 'SetBorrowerAttributes returns the success code Link Here
107
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
120
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
108
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
121
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
109
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
122
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
110
is( @$borrower_attributes, 2, 'GetBorrowerAttributes returns the correct number of borrower attributes' );
123
is( @$borrower_attributes, 3, 'GetBorrowerAttributes returns the correct number of borrower attributes' );
111
is( $borrower_attributes->[0]->{code}, $attributes->[0]->{code}, 'SetBorrowerAttributes stores the correct code correctly' );
124
is( $borrower_attributes->[0]->{code}, $attributes->[0]->{code}, 'SetBorrowerAttributes stores the correct code correctly' );
112
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'SetBorrowerAttributes stores the field description correctly' );
125
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'SetBorrowerAttributes stores the field description correctly' );
113
is( $borrower_attributes->[0]->{value}, $attributes->[0]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
126
is( $borrower_attributes->[0]->{value}, $attributes->[0]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
Lines 116-129 is( $borrower_attributes->[1]->{code}, $attributes->[1]->{code}, 'SetBorrowerAtt Link Here
116
is( $borrower_attributes->[1]->{description}, $attribute_type2->description(), 'SetBorrowerAttributes stores the field description correctly' );
129
is( $borrower_attributes->[1]->{description}, $attribute_type2->description(), 'SetBorrowerAttributes stores the field description correctly' );
117
is( $borrower_attributes->[1]->{value}, $attributes->[1]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
130
is( $borrower_attributes->[1]->{value}, $attributes->[1]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
118
is( $borrower_attributes->[1]->{password}, $attributes->[1]->{password}, 'SetBorrowerAttributes stores the field password correctly' );
131
is( $borrower_attributes->[1]->{password}, $attributes->[1]->{password}, 'SetBorrowerAttributes stores the field password correctly' );
132
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
133
is( @$borrower_attributes, 3, 'GetBorrowerAttributes returns the correct number of borrower attributes' );
119
134
120
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, 1);
135
$attributes = [
121
is( @$borrower_attributes, 1, 'GetBorrowerAttributes returns the correct number of borrower attributes with the filter opac_only' );
136
    {
122
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'GetBorrowerAttributes returns the correct code' );
137
        value => 'my attribute1',
123
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'GetBorrowerAttributes returns the correct description' );
138
        code => $attribute_type1->code(),
124
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'GetBorrowerAttributes returns the correct value' );
139
        password => 'my password1',
125
is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'GetBorrowerAttributes returns the correct password' );
140
    },
141
    {
142
        value => 'my attribute2',
143
        code => $attribute_type2->code(),
144
        password => 'my password2',
145
    }
146
];
147
C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $attributes);
148
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
149
is( @$borrower_attributes, 3, 'SetBorrowerAttributes should not have removed the attributes limited to another branch' );
126
150
151
# TODO This is not implemented yet
152
#$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, undef, 'branch_limited');
153
#is( @$borrower_attributes, 2, 'GetBorrowerAttributes returns the correct number of borrower attributes filtered on library' );
127
154
128
my $attribute_value = C4::Members::Attributes::GetBorrowerAttributeValue();
155
my $attribute_value = C4::Members::Attributes::GetBorrowerAttributeValue();
129
is( $attribute_value, undef, 'GetBorrowerAttributeValue without arguments returns undef' );
156
is( $attribute_value, undef, 'GetBorrowerAttributeValue without arguments returns undef' );
Lines 147-153 my $attribute = { Link Here
147
};
174
};
148
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute);
175
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute);
149
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
176
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
150
is( @$borrower_attributes, 2, 'UpdateBorrowerAttribute does not change the number of borrower attributes' );
177
is( @$borrower_attributes, 3, 'UpdateBorrowerAttribute does not change the number of borrower attributes' );
151
is( $borrower_attributes->[0]->{code}, $attribute->{code}, 'UpdateBorrowerAttribute updates the field code correctly' );
178
is( $borrower_attributes->[0]->{code}, $attribute->{code}, 'UpdateBorrowerAttribute updates the field code correctly' );
152
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'UpdateBorrowerAttribute updates the field description correctly' );
179
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'UpdateBorrowerAttribute updates the field description correctly' );
153
is( $borrower_attributes->[0]->{value}, $attribute->{attribute}, 'UpdateBorrowerAttribute updates the field value correctly' );
180
is( $borrower_attributes->[0]->{value}, $attribute->{attribute}, 'UpdateBorrowerAttribute updates the field value correctly' );
Lines 185-201 for my $attr( split(' ', $attributes->[1]->{value}) ) { Link Here
185
212
186
C4::Members::Attributes::DeleteBorrowerAttribute();
213
C4::Members::Attributes::DeleteBorrowerAttribute();
187
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
214
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
188
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute without arguments deletes nothing' );
215
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without arguments deletes nothing' );
189
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber);
216
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber);
190
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
217
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
191
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute without the attribute deletes nothing' );
218
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without the attribute deletes nothing' );
192
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute);
219
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute);
193
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
220
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
194
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' );
221
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' );
195
222
196
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute);
223
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute);
197
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
224
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
198
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' );
225
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute deletes a borrower attribute' );
199
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry');
226
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry');
200
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry');
227
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry');
201
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry');
228
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry');
Lines 203-206 is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'Delete Link Here
203
230
204
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]);
231
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]);
205
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
232
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
206
is( @$borrower_attributes, 0, 'DeleteBorrowerAttribute deletes a borrower attribute' );
233
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' );
(-)a/tools/import_borrowers.pl (-2 / +1 lines)
Lines 308-314 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
308
                    my $old_attributes = GetBorrowerAttributes($borrowernumber);
308
                    my $old_attributes = GetBorrowerAttributes($borrowernumber);
309
                    $patron_attributes = extended_attributes_merge($old_attributes, $patron_attributes);  #TODO: expose repeatable options in template
309
                    $patron_attributes = extended_attributes_merge($old_attributes, $patron_attributes);  #TODO: expose repeatable options in template
310
                }
310
                }
311
                push @errors, {unknown_error => 1} unless SetBorrowerAttributes($borrower{'borrowernumber'}, $patron_attributes);
311
                push @errors, {unknown_error => 1} unless SetBorrowerAttributes($borrower{'borrowernumber'}, $patron_attributes, 'no_branch_limit' );
312
            }
312
            }
313
            $overwritten++;
313
            $overwritten++;
314
            $template->param('lastoverwritten'=>$borrower{'surname'}.' / '.$borrowernumber);
314
            $template->param('lastoverwritten'=>$borrower{'surname'}.' / '.$borrowernumber);
315
- 

Return to bug 15163