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 (-28 / +59 lines)
Lines 22-29 use Modern::Perl; Link Here
22
use C4::Context;
22
use C4::Context;
23
use C4::Members;
23
use C4::Members;
24
use C4::Members::AttributeTypes;
24
use C4::Members::AttributeTypes;
25
use Koha::Database;
26
use t::lib::TestBuilder;
25
27
26
use Test::More tests => 60;
28
use Test::More tests => 57;
27
29
28
use_ok('C4::Members::Attributes');
30
use_ok('C4::Members::Attributes');
29
31
Lines 31-58 my $dbh = C4::Context->dbh; Link Here
31
$dbh->{AutoCommit} = 0;
33
$dbh->{AutoCommit} = 0;
32
$dbh->{RaiseError} = 1;
34
$dbh->{RaiseError} = 1;
33
35
36
my $builder = t::lib::TestBuilder->new;
37
34
$dbh->do(q|DELETE FROM issues|);
38
$dbh->do(q|DELETE FROM issues|);
35
$dbh->do(q|DELETE FROM borrowers|);
39
$dbh->do(q|DELETE FROM borrowers|);
36
$dbh->do(q|DELETE FROM borrower_attributes|);
40
$dbh->do(q|DELETE FROM borrower_attributes|);
37
$dbh->do(q|DELETE FROM borrower_attribute_types|);
41
$dbh->do(q|DELETE FROM borrower_attribute_types|);
38
42
my $library = $builder->build({
39
my $borrowernumber = AddMember(
43
    source => 'Branch',
40
    firstname =>  'my firstname',
44
});
41
    surname => 'my surname',
45
42
    categorycode => 'S',
46
my $patron = $builder->build(
43
    branchcode => 'CPL',
47
    {   source => 'Borrower',
48
        value  => {
49
            firstname    => 'my firstname',
50
            surname      => 'my surname',
51
            categorycode => 'S',
52
            branchcode => $library->{branchcode},
53
        }
54
    }
44
);
55
);
45
56
C4::Context->_new_userenv('DUMMY SESSION');
57
C4::Context->set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', $library->{branchcode}, 'My Library', 0);
58
my $borrowernumber = $patron->{borrowernumber};
46
59
47
my $attribute_type1 = C4::Members::AttributeTypes->new('my code1', 'my description1');
60
my $attribute_type1 = C4::Members::AttributeTypes->new('my code1', 'my description1');
48
$attribute_type1->unique_id(1);
61
$attribute_type1->unique_id(1);
49
my $attribute_type2 = C4::Members::AttributeTypes->new('my code2', 'my description2');
50
$attribute_type2->opac_display(1);
51
$attribute_type2->staff_searchable(1);
52
53
my $attribute_types = C4::Members::Attributes::GetAttributes();
62
my $attribute_types = C4::Members::Attributes::GetAttributes();
54
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types' );
63
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types' );
55
56
$attribute_type1->store();
64
$attribute_type1->store();
57
$attribute_types = C4::Members::Attributes::GetAttributes();
65
$attribute_types = C4::Members::Attributes::GetAttributes();
58
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types' );
66
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types' );
Lines 60-65 is( $attribute_types->[0], $attribute_type1->code(), 'GetAttributes returns the Link Here
60
$attribute_types = C4::Members::Attributes::GetAttributes(1);
68
$attribute_types = C4::Members::Attributes::GetAttributes(1);
61
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
69
is( @$attribute_types, 0, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
62
70
71
my $attribute_type2 = C4::Members::AttributeTypes->new('my code2', 'my description2');
72
$attribute_type2->opac_display(1);
73
$attribute_type2->staff_searchable(1);
63
$attribute_type2->store();
74
$attribute_type2->store();
64
$attribute_types = C4::Members::Attributes::GetAttributes();
75
$attribute_types = C4::Members::Attributes::GetAttributes();
65
is( @$attribute_types, 2, 'GetAttributes returns the correct number of attribute types' );
76
is( @$attribute_types, 2, 'GetAttributes returns the correct number of attribute types' );
Lines 67-72 is( $attribute_types->[1], $attribute_type2->code(), 'GetAttributes returns the Link Here
67
$attribute_types = C4::Members::Attributes::GetAttributes(1);
78
$attribute_types = C4::Members::Attributes::GetAttributes(1);
68
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
79
is( @$attribute_types, 1, 'GetAttributes returns the correct number of attribute types with the filter opac_only' );
69
80
81
my $new_library = $builder->build( { source => 'Branch' } );
82
my $attribute_type_limited = C4::Members::AttributeTypes->new('my code3', 'my description3');
83
$attribute_type_limited->branches([ $new_library->{branchcode} ]);
84
$attribute_type_limited->store;
70
85
71
my $borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
86
my $borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
72
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
87
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
Lines 83-88 my $attributes = [ Link Here
83
        value => 'my attribute2',
98
        value => 'my attribute2',
84
        code => $attribute_type2->code(),
99
        code => $attribute_type2->code(),
85
        password => 'my password2',
100
        password => 'my password2',
101
    },
102
    {
103
        value => 'my attribute limited',
104
        code => $attribute_type_limited->code(),
86
    }
105
    }
87
];
106
];
88
107
Lines 99-105 is( $set_borrower_attributes, 1, 'SetBorrowerAttributes returns the success code Link Here
99
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
118
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes();
100
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
119
is( @$borrower_attributes, 0, 'GetBorrowerAttributes without the borrower number returns an empty array' );
101
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
120
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
102
is( @$borrower_attributes, 2, 'GetBorrowerAttributes returns the correct number of borrower attributes' );
121
is( @$borrower_attributes, 3, 'GetBorrowerAttributes returns the correct number of borrower attributes' );
103
is( $borrower_attributes->[0]->{code}, $attributes->[0]->{code}, 'SetBorrowerAttributes stores the correct code correctly' );
122
is( $borrower_attributes->[0]->{code}, $attributes->[0]->{code}, 'SetBorrowerAttributes stores the correct code correctly' );
104
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'SetBorrowerAttributes stores the field description correctly' );
123
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'SetBorrowerAttributes stores the field description correctly' );
105
is( $borrower_attributes->[0]->{value}, $attributes->[0]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
124
is( $borrower_attributes->[0]->{value}, $attributes->[0]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
Lines 108-121 is( $borrower_attributes->[1]->{code}, $attributes->[1]->{code}, 'SetBorrowerAtt Link Here
108
is( $borrower_attributes->[1]->{description}, $attribute_type2->description(), 'SetBorrowerAttributes stores the field description correctly' );
127
is( $borrower_attributes->[1]->{description}, $attribute_type2->description(), 'SetBorrowerAttributes stores the field description correctly' );
109
is( $borrower_attributes->[1]->{value}, $attributes->[1]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
128
is( $borrower_attributes->[1]->{value}, $attributes->[1]->{value}, 'SetBorrowerAttributes stores the field value correctly' );
110
is( $borrower_attributes->[1]->{password}, $attributes->[1]->{password}, 'SetBorrowerAttributes stores the field password correctly' );
129
is( $borrower_attributes->[1]->{password}, $attributes->[1]->{password}, 'SetBorrowerAttributes stores the field password correctly' );
130
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
131
is( @$borrower_attributes, 3, 'GetBorrowerAttributes returns the correct number of borrower attributes' );
111
132
112
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, 1);
133
$attributes = [
113
is( @$borrower_attributes, 1, 'GetBorrowerAttributes returns the correct number of borrower attributes with the filter opac_only' );
134
    {
114
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'GetBorrowerAttributes returns the correct code' );
135
        value => 'my attribute1',
115
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'GetBorrowerAttributes returns the correct description' );
136
        code => $attribute_type1->code(),
116
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'GetBorrowerAttributes returns the correct value' );
137
        password => 'my password1',
117
is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'GetBorrowerAttributes returns the correct password' );
138
    },
139
    {
140
        value => 'my attribute2',
141
        code => $attribute_type2->code(),
142
        password => 'my password2',
143
    }
144
];
145
C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $attributes);
146
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
147
is( @$borrower_attributes, 3, 'SetBorrowerAttributes should not have removed the attributes limited to another branch' );
118
148
149
# TODO This is not implemented yet
150
#$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber, undef, 'branch_limited');
151
#is( @$borrower_attributes, 2, 'GetBorrowerAttributes returns the correct number of borrower attributes filtered on library' );
119
152
120
my $attribute_value = C4::Members::Attributes::GetBorrowerAttributeValue();
153
my $attribute_value = C4::Members::Attributes::GetBorrowerAttributeValue();
121
is( $attribute_value, undef, 'GetBorrowerAttributeValue without arguments returns undef' );
154
is( $attribute_value, undef, 'GetBorrowerAttributeValue without arguments returns undef' );
Lines 139-145 my $attribute = { Link Here
139
};
172
};
140
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute);
173
C4::Members::Attributes::UpdateBorrowerAttribute($borrowernumber, $attribute);
141
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
174
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
142
is( @$borrower_attributes, 2, 'UpdateBorrowerAttribute does not change the number of borrower attributes' );
175
is( @$borrower_attributes, 3, 'UpdateBorrowerAttribute does not change the number of borrower attributes' );
143
is( $borrower_attributes->[0]->{code}, $attribute->{code}, 'UpdateBorrowerAttribute updates the field code correctly' );
176
is( $borrower_attributes->[0]->{code}, $attribute->{code}, 'UpdateBorrowerAttribute updates the field code correctly' );
144
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'UpdateBorrowerAttribute updates the field description correctly' );
177
is( $borrower_attributes->[0]->{description}, $attribute_type1->description(), 'UpdateBorrowerAttribute updates the field description correctly' );
145
is( $borrower_attributes->[0]->{value}, $attribute->{attribute}, 'UpdateBorrowerAttribute updates the field value correctly' );
178
is( $borrower_attributes->[0]->{value}, $attribute->{attribute}, 'UpdateBorrowerAttribute updates the field value correctly' );
Lines 177-193 for my $attr( split(' ', $attributes->[1]->{value}) ) { Link Here
177
210
178
C4::Members::Attributes::DeleteBorrowerAttribute();
211
C4::Members::Attributes::DeleteBorrowerAttribute();
179
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
212
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
180
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute without arguments deletes nothing' );
213
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without arguments deletes nothing' );
181
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber);
214
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber);
182
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
215
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
183
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute without the attribute deletes nothing' );
216
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute without the attribute deletes nothing' );
184
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute);
217
C4::Members::Attributes::DeleteBorrowerAttribute(undef, $attribute);
185
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
218
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
186
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' );
219
is( @$borrower_attributes, 3, 'DeleteBorrowerAttribute with a undef borrower number deletes nothing' );
187
220
188
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute);
221
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attribute);
189
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
222
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
190
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' );
223
is( @$borrower_attributes, 2, 'DeleteBorrowerAttribute deletes a borrower attribute' );
191
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry');
224
is( $borrower_attributes->[0]->{code}, $attributes->[1]->{code}, 'DeleteBorrowerAttribute deletes the correct entry');
192
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry');
225
is( $borrower_attributes->[0]->{description}, $attribute_type2->description(), 'DeleteBorrowerAttribute deletes the correct entry');
193
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry');
226
is( $borrower_attributes->[0]->{value}, $attributes->[1]->{value}, 'DeleteBorrowerAttribute deletes the correct entry');
Lines 195-200 is( $borrower_attributes->[0]->{password}, $attributes->[1]->{password}, 'Delete Link Here
195
228
196
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]);
229
C4::Members::Attributes::DeleteBorrowerAttribute($borrowernumber, $attributes->[1]);
197
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
230
$borrower_attributes = C4::Members::Attributes::GetBorrowerAttributes($borrowernumber);
198
is( @$borrower_attributes, 0, 'DeleteBorrowerAttribute deletes a borrower attribute' );
231
is( @$borrower_attributes, 1, 'DeleteBorrowerAttribute deletes a borrower attribute' );
199
200
$dbh->rollback;
(-)a/tools/import_borrowers.pl (-2 / +1 lines)
Lines 311-317 if ( $uploadborrowers && length($uploadborrowers) > 0 ) { Link Here
311
                    my $old_attributes = GetBorrowerAttributes($borrowernumber);
311
                    my $old_attributes = GetBorrowerAttributes($borrowernumber);
312
                    $patron_attributes = extended_attributes_merge($old_attributes, $patron_attributes);  #TODO: expose repeatable options in template
312
                    $patron_attributes = extended_attributes_merge($old_attributes, $patron_attributes);  #TODO: expose repeatable options in template
313
                }
313
                }
314
                push @errors, {unknown_error => 1} unless SetBorrowerAttributes($borrower{'borrowernumber'}, $patron_attributes);
314
                push @errors, {unknown_error => 1} unless SetBorrowerAttributes($borrower{'borrowernumber'}, $patron_attributes, 'no_branch_limit' );
315
            }
315
            }
316
            $overwritten++;
316
            $overwritten++;
317
            $template->param('lastoverwritten'=>$borrower{'surname'}.' / '.$borrowernumber);
317
            $template->param('lastoverwritten'=>$borrower{'surname'}.' / '.$borrowernumber);
318
- 

Return to bug 15163