Bugzilla – Attachment 69763 Details for
Bug 16330
Add routes to add, update and delete patrons
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16330: Spot unchanged modification-request in Koha::Patron::Modification
Bug-16330-Spot-unchanged-modification-request-in-K.patch (text/plain), 5.23 KB, created by
Benjamin Rokseth
on 2017-12-13 08:30:39 UTC
(
hide
)
Description:
Bug 16330: Spot unchanged modification-request in Koha::Patron::Modification
Filename:
MIME Type:
Creator:
Benjamin Rokseth
Created:
2017-12-13 08:30:39 UTC
Size:
5.23 KB
patch
obsolete
>From c306dc05574518b4ea96a138b1a36e76d0e4a602 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@jns.fi> >Date: Mon, 22 May 2017 18:05:24 +0300 >Subject: [PATCH] Bug 16330: Spot unchanged modification-request in > Koha::Patron::Modification > >Throw Koha::Exceptions::NoChanges if attempting to create a modification request >without changing anything. > >This exception is caught in Patron REST API controller. > >Also, validate changes via Koha::Patron->_validate > >To test: >1. prove t/db_dependent/Koha/Patron/Modifications.t > >Signed-off-by: Benjamin Rokseth <benjamin.rokseth@kul.oslo.kommune.no> >--- > Koha/Patron/Modification.pm | 40 ++++++++++++++++++++++++++++++ > t/db_dependent/Koha/Patron/Modifications.t | 38 +++++++++++++++++++++++++--- > 2 files changed, 75 insertions(+), 3 deletions(-) > >diff --git a/Koha/Patron/Modification.pm b/Koha/Patron/Modification.pm >index 0fb1d0b..91b4bff 100644 >--- a/Koha/Patron/Modification.pm >+++ b/Koha/Patron/Modification.pm >@@ -1,6 +1,7 @@ > package Koha::Patron::Modification; > > # Copyright ByWater Solutions 2014 >+# Copyright Koha-Suomi Oy 2016 > # > # This file is part of Koha. > # >@@ -22,6 +23,9 @@ use Modern::Perl; > use Carp; > > use Koha::Database; >+use Koha::Exceptions; >+use Koha::Patrons; >+ > use Koha::Exceptions::Patron::Modification; > use Koha::Patron::Attribute; > use Koha::Patron::Attributes; >@@ -70,6 +74,42 @@ sub store { > }; > } > >+ my $patron = Koha::Patrons->find( $self->borrowernumber ); >+ if ( $patron ) { >+ my %columns = map { $_ => 1 } Koha::Patrons->columns; >+ >+ my $changes_made = 0; >+ foreach my $column ( keys %{$self->unblessed} ) { >+ if (exists $columns{$column}) { >+ if ($patron->$column ne $self->$column) { >+ $changes_made = 1; >+ last; >+ } >+ # Set the changes for patron without commiting - this will be used >+ # for validating the given parameters via Koha::Patron. >+ # Do not ->store the patron! >+ $patron->$column($self->$column); >+ } >+ } >+ my $extended_attributes = try { from_json( $self->extended_attributes ) }; >+ if (!$changes_made && $extended_attributes) { >+ my %codes = map { $_->{code} => $_->{value} } @{$extended_attributes}; >+ foreach my $code (keys %codes) { >+ delete $codes{$code} if Koha::Patron::Attributes->search({ >+ borrowernumber => $patron->borrowernumber, >+ code => $code, >+ attribute => $codes{$code} >+ })->count > 0; >+ } >+ $changes_made = 1 if keys %codes > 0; >+ } >+ Koha::Exceptions::NoChanges->throw( >+ error => "No changes have been made", >+ ) unless $changes_made; >+ # Validate changes via Koha::Patron >+ $patron->_validate; >+ } >+ > return $self->SUPER::store(); > } > >diff --git a/t/db_dependent/Koha/Patron/Modifications.t b/t/db_dependent/Koha/Patron/Modifications.t >index 53664f5..cc051a6 100755 >--- a/t/db_dependent/Koha/Patron/Modifications.t >+++ b/t/db_dependent/Koha/Patron/Modifications.t >@@ -85,7 +85,7 @@ subtest 'new() tests' => sub { > > subtest 'store( extended_attributes ) tests' => sub { > >- plan tests => 4; >+ plan tests => 6; > > $schema->storage->txn_begin; > >@@ -94,8 +94,14 @@ subtest 'store( extended_attributes ) tests' => sub { > my $patron > = $builder->build( { source => 'Borrower' } )->{borrowernumber}; > my $verification_token = md5_hex( time().{}.rand().{}.$$ ); >- my $valid_json_text = '[{"code":"CODE","value":"VALUE"}]'; >- my $invalid_json_text = '[{"code":"CODE";"value":"VALUE"}]'; >+ $builder->build( >+ { source => 'BorrowerAttributeType', value => { code => 'CODE_1' } } >+ ); >+ $builder->build( >+ { source => 'BorrowerAttributeType', value => { code => 'CODE_2' } } >+ ); >+ my $valid_json_text = '[{"code":"CODE_1","value":"VALUE"}]'; >+ my $invalid_json_text = '[{"code":"CODE_2";"value":"VALUE"}]'; > > Koha::Patron::Modification->new( > { verification_token => $verification_token, >@@ -130,6 +136,32 @@ subtest 'store( extended_attributes ) tests' => sub { > > is( $@, 'The passed extended_attributes is not valid JSON' ); > >+ Koha::Patrons->find($patron)->surname('Hall')->store; >+ throws_ok { >+ Koha::Patron::Modification->new( >+ { verification_token => $verification_token, >+ borrowernumber => $patron, >+ surname => 'Hall', >+ } >+ )->store(); >+ } >+ 'Koha::Exceptions::NoChanges', >+ 'Trying to create a modification request without changing anything' >+ .' raises exception'; >+ >+ $patron_modification->approve; >+ throws_ok { >+ Koha::Patron::Modification->new( >+ { verification_token => $verification_token, >+ borrowernumber => $patron, >+ extended_attributes => $valid_json_text, >+ } >+ )->store(); >+ } >+ 'Koha::Exceptions::NoChanges', >+ 'Trying to create a modification request without changing anything' >+ .' raises exception'; >+ > $schema->storage->txn_rollback; > }; > >-- >2.1.4
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 16330
:
50803
|
50889
|
51066
|
51131
|
51132
|
53216
|
53217
|
53820
|
54942
|
55147
|
56666
|
56667
|
56668
|
63646
|
63647
|
63649
|
63650
|
69546
|
69547
|
69548
|
69549
|
69550
|
69551
|
69752
|
69762
|
69763
|
69764
|
69765
|
69766
|
69767
|
69768
|
69787
|
70034
|
70035
|
70036
|
70037
|
70038
|
71667
|
71668
|
71669
|
71670
|
71671
|
71920
|
71921
|
71922
|
71923
|
71924
|
71925
|
71933
|
71934
|
71935
|
71936
|
71937
|
71938
|
73434