Bugzilla – Attachment 61570 Details for
Bug 13757
Make patron attributes editable in the opac if set to 'editable in OPAC'
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13757: Make K::P::Modifications->pending return K::P::Attribute
Bug-13757-Make-KPModifications-pending-return-KPAt.patch (text/plain), 6.58 KB, created by
Jonathan Druart
on 2017-03-23 15:59:37 UTC
(
hide
)
Description:
Bug 13757: Make K::P::Modifications->pending return K::P::Attribute
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-03-23 15:59:37 UTC
Size:
6.58 KB
patch
obsolete
>From 3197c526a56d7d47770e28cb62dad861f123230e Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 3 Feb 2017 15:22:37 -0300 >Subject: [PATCH] Bug 13757: Make K::P::Modifications->pending return > K::P::Attribute > >This patch makes Koha::Patron::Modifications->pending return >Koha::Patron:Attribute objects. They are not stored on the DB but only >live in memory on runtime. > >members-update.pl is the only place this is used, and this way we have >all we need for better rendering the UI. > >Tests are added for the changed API. > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > Koha/Patron/Modifications.pm | 15 ++++++++++- > t/db_dependent/Koha/Patron/Modifications.t | 41 +++++++++++++++++++++++++++--- > 2 files changed, 51 insertions(+), 5 deletions(-) > >diff --git a/Koha/Patron/Modifications.pm b/Koha/Patron/Modifications.pm >index 3ecef11..403b955 100644 >--- a/Koha/Patron/Modifications.pm >+++ b/Koha/Patron/Modifications.pm >@@ -26,6 +26,7 @@ use Modern::Perl; > > use C4::Context; > >+use Koha::Patron::Attribute; > use Koha::Patron::Modification; > > use JSON; >@@ -96,7 +97,19 @@ sub pending { > while ( my $row = $sth->fetchrow_hashref() ) { > foreach my $key ( keys %$row ) { > if ( defined $row->{$key} && $key eq 'extended_attributes' ) { >- $row->{$key} = from_json($row->{$key}); >+ my $attributes = decode_json( $row->{$key} ); >+ my @pending_attributes; >+ foreach my $attr ( @{$attributes} ) { >+ push @pending_attributes, >+ Koha::Patron::Attribute->new( >+ { borrowernumber => $row->{borrowernumber}, >+ code => $attr->{code}, >+ attribute => $attr->{value} >+ } >+ ); >+ } >+ >+ $row->{$key} = \@pending_attributes; > } > delete $row->{$key} unless defined $row->{$key}; > } >diff --git a/t/db_dependent/Koha/Patron/Modifications.t b/t/db_dependent/Koha/Patron/Modifications.t >index 3ea8aee..8a3c94c 100755 >--- a/t/db_dependent/Koha/Patron/Modifications.t >+++ b/t/db_dependent/Koha/Patron/Modifications.t >@@ -29,6 +29,7 @@ use C4::Context; > use C4::Members; > use C4::Members::Attributes qw( GetBorrowerAttributes ); > use Koha::Patrons; >+use Koha::Patron::Attribute; > > BEGIN { > use_ok('Koha::Patron::Modification'); >@@ -253,13 +254,16 @@ subtest 'approve tests' => sub { > > subtest 'pending_count() and pending() tests' => sub { > >- plan tests => 7; >+ plan tests => 16; > > $schema->storage->txn_begin; > > Koha::Patron::Modifications->search->delete; > my $library_1 = $builder->build( { source => 'Branch' } )->{branchcode}; > my $library_2 = $builder->build( { source => 'Branch' } )->{branchcode}; >+ $builder->build({ source => 'BorrowerAttributeType', value => { code => 'CODE_1' } }); >+ $builder->build({ source => 'BorrowerAttributeType', value => { code => 'CODE_2', repeatable => 1 } }); >+ > my $patron_1 > = $builder->build( > { source => 'Borrower', value => { branchcode => $library_1 } } ) >@@ -276,12 +280,15 @@ subtest 'pending_count() and pending() tests' => sub { > my $verification_token_2 = md5_hex( time().{}.rand().{}.$$ ); > my $verification_token_3 = md5_hex( time().{}.rand().{}.$$ ); > >+ Koha::Patron::Attribute->new({ borrowernumber => $patron_1, code => 'CODE_1', attribute => 'hello' } )->store(); >+ Koha::Patron::Attribute->new({ borrowernumber => $patron_2, code => 'CODE_2', attribute => 'bye' } )->store(); > > my $modification_1 = Koha::Patron::Modification->new( > { borrowernumber => $patron_1, > surname => 'Hall', > firstname => 'Kyle', >- verification_token => $verification_token_1 >+ verification_token => $verification_token_1, >+ extended_attributes => '[{"code":"CODE_1","value":""}]' > } > )->store(); > >@@ -292,13 +299,14 @@ subtest 'pending_count() and pending() tests' => sub { > { borrowernumber => $patron_2, > surname => 'Smith', > firstname => 'Sandy', >- verification_token => $verification_token_2 >+ verification_token => $verification_token_2, >+ extended_attributes => '[{"code":"CODE_2","value":"chau"},{"code":"CODE_2","value":"ciao"}]' > } > )->store(); > > my $modification_3 = Koha::Patron::Modification->new( > { borrowernumber => $patron_3, >- surname => 'Smith', >+ surname => 'Smithy', > firstname => 'Sandy', > verification_token => $verification_token_3 > } >@@ -307,6 +315,31 @@ subtest 'pending_count() and pending() tests' => sub { > is( Koha::Patron::Modifications->pending_count, > 3, 'pending_count() correctly returns 3' ); > >+ my $pending = Koha::Patron::Modifications->pending(); >+ is( scalar @{$pending}, 3, 'pending() returns an array with 3 elements' ); >+ >+ my @filtered_modifications = grep { $_->{borrowernumber} eq $patron_1 } @{$pending}; >+ my $p1_pm = $filtered_modifications[0]; >+ my $p1_pm_attribute_1 = $p1_pm->{extended_attributes}->[0]; >+ >+ is( scalar @{$p1_pm->{extended_attributes}}, 1, 'patron 1 has modification has one pending attribute modification' ); >+ is( ref($p1_pm_attribute_1), 'Koha::Patron::Attribute', 'patron modification has single attribute object' ); >+ is( $p1_pm_attribute_1->attribute, '', 'patron 1 has an empty value for the attribute' ); >+ >+ @filtered_modifications = grep { $_->{borrowernumber} eq $patron_2 } @{$pending}; >+ my $p2_pm = $filtered_modifications[0]; >+ >+ is( scalar @{$p2_pm->{extended_attributes}}, 2 , 'patron 2 has 2 attribute modifications' ); >+ >+ my $p2_pm_attribute_1 = $p2_pm->{extended_attributes}->[0]; >+ my $p2_pm_attribute_2 = $p2_pm->{extended_attributes}->[1]; >+ >+ is( ref($p2_pm_attribute_1), 'Koha::Patron::Attribute', 'patron modification has single attribute object' ); >+ is( ref($p2_pm_attribute_2), 'Koha::Patron::Attribute', 'patron modification has single attribute object' ); >+ >+ is( $p2_pm_attribute_1->attribute, 'chau', 'patron modification has the right attribute change' ); >+ is( $p2_pm_attribute_2->attribute, 'ciao', 'patron modification has the right attribute change' ); >+ > is( Koha::Patron::Modifications->pending_count($library_1), > 1, 'pending_count() correctly returns 1 if filtered by library' ); > >-- >2.9.3
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13757
:
42254
|
42626
|
42627
|
47625
|
48040
|
48041
|
48042
|
48043
|
48379
|
48380
|
48381
|
48382
|
56924
|
56925
|
56926
|
56927
|
56928
|
56929
|
57041
|
57042
|
57043
|
57044
|
57045
|
57046
|
58252
|
58253
|
58254
|
58255
|
58351
|
58352
|
58353
|
58354
|
58355
|
58356
|
58357
|
58428
|
58429
|
58581
|
58703
|
58706
|
58707
|
58708
|
58709
|
58710
|
58711
|
58712
|
58713
|
58714
|
58715
|
59376
|
59737
|
59738
|
59739
|
59813
|
59896
|
59897
|
59898
|
60359
|
60360
|
61132
|
61133
|
61134
|
61135
|
61136
|
61137
|
61138
|
61139
|
61140
|
61141
|
61142
|
61143
|
61144
|
61145
|
61146
|
61147
|
61148
|
61149
|
61150
|
61492
|
61493
|
61555
|
61556
|
61557
|
61558
|
61559
|
61560
|
61561
|
61562
|
61563
|
61564
|
61565
|
61566
|
61567
|
61568
|
61569
| 61570 |
61571
|
61572
|
61573
|
61574
|
61575