Bugzilla – Attachment 104102 Details for
Bug 17355
Authorised value categories cannot be deleted
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17355: Override delete methods
Bug-17355-Override-delete-methods.patch (text/plain), 3.74 KB, created by
Victor Grousset/tuxayo
on 2020-05-01 14:22:13 UTC
(
hide
)
Description:
Bug 17355: Override delete methods
Filename:
MIME Type:
Creator:
Victor Grousset/tuxayo
Created:
2020-05-01 14:22:13 UTC
Size:
3.74 KB
patch
obsolete
>From 8bee07c58bf547caa2079a2b38376a37bb075eee Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 28 Apr 2020 11:23:02 +0200 >Subject: [PATCH] Bug 17355: Override delete methods > >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >--- > Koha/AuthorisedValueCategories.pm | 20 ++++++++++++++++++++ > Koha/AuthorisedValueCategory.pm | 15 +++++++++++++++ > t/db_dependent/AuthorisedValues.t | 27 +++++++++++++++++++++++++-- > 3 files changed, 60 insertions(+), 2 deletions(-) > >diff --git a/Koha/AuthorisedValueCategories.pm b/Koha/AuthorisedValueCategories.pm >index afe6692a25..2d36352c88 100644 >--- a/Koha/AuthorisedValueCategories.pm >+++ b/Koha/AuthorisedValueCategories.pm >@@ -20,6 +20,7 @@ use Modern::Perl; > use Carp; > > use Koha::Database; >+use Koha::Exceptions::CannotDeleteDefault; > > use Koha::AuthorisedValueCategory; > >@@ -35,6 +36,25 @@ Koha::AuthorisedValueCategories - Koha AuthorisedValueCategory Object set class > > =cut > >+=head3 delete >+ >+Overridden delete method to prevent system default deletions >+ >+=cut >+ >+sub delete { >+ my ($self) = @_; >+ >+ my @set = $self->as_list; >+ for my $type (@set) { >+ if ( $type->is_system ) { >+ Koha::Exceptions::CannotDeleteDefault->throw; >+ } >+ } >+ >+ return $self->SUPER::delete; >+} >+ > =head3 type > > =cut >diff --git a/Koha/AuthorisedValueCategory.pm b/Koha/AuthorisedValueCategory.pm >index 14eb91db25..d2c196dadf 100644 >--- a/Koha/AuthorisedValueCategory.pm >+++ b/Koha/AuthorisedValueCategory.pm >@@ -20,6 +20,7 @@ use Modern::Perl; > use Carp; > > use Koha::Database; >+use Koha::Exceptions::CannotDeleteDefault; > > use base qw(Koha::Object); > >@@ -33,6 +34,20 @@ Koha::AuthorisedValueCategory - Koha AuthorisedValueCategory Object class > > =cut > >+=head3 delete >+ >+Overridden delete method to prevent system default deletions >+ >+=cut >+ >+sub delete { >+ my ($self) = @_; >+ >+ Koha::Exceptions::CannotDeleteDefault->throw if $self->is_system; >+ >+ return $self->SUPER::delete; >+} >+ > =head3 type > > =cut >diff --git a/t/db_dependent/AuthorisedValues.t b/t/db_dependent/AuthorisedValues.t >index d16d282731..860e97baef 100644 >--- a/t/db_dependent/AuthorisedValues.t >+++ b/t/db_dependent/AuthorisedValues.t >@@ -1,7 +1,8 @@ > #!/usr/bin/perl > > use Modern::Perl; >-use Test::More tests => 15; >+use Test::More tests => 17; >+use Try::Tiny; > > use t::lib::TestBuilder; > >@@ -20,7 +21,7 @@ Koha::AuthorisedValues->delete; > Koha::AuthorisedValueCategories->delete; > > # insert >-Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store; >+Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing', is_system => 1 })->store; > Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store; > Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store; > my $av1 = Koha::AuthorisedValue->new( >@@ -84,6 +85,28 @@ ok( $av2->id(), 'AV 2 is inserted' ); > ok( $av3->id(), 'AV 3 is inserted' ); > ok( $av4->id(), 'AV 4 is inserted' ); > >+{ # delete is_system AV categories >+ try { >+ Koha::AuthorisedValueCategories->find('av_for_testing')->delete >+ } >+ catch { >+ ok( >+ $_->isa('Koha::Exceptions::CannotDeleteDefault'), >+ 'A system AV category cannot be deleted' >+ ); >+ }; >+ >+ try { >+ Koha::AuthorisedValueCategories->search->delete >+ } >+ catch { >+ ok( >+ $_->isa('Koha::Exceptions::CannotDeleteDefault'), >+ 'system AV categories cannot be deleted' >+ ); >+ }; >+} >+ > is( $av3->opac_description, 'opac display value 3', 'Got correction opac description if lib_opac is set' ); > $av3->lib_opac(''); > is( $av3->opac_description, 'display value 3', 'Got correction opac description if lib_opac is *not* set' ); >-- >2.26.2
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 17355
:
64102
|
65782
|
65869
|
65870
|
66022
|
66023
|
66024
|
103833
|
103834
|
103835
|
103836
|
103837
|
103838
|
104099
|
104100
|
104101
|
104102
|
104103
|
104104
|
104117
|
104118
|
104119
|
104120
|
104121
|
104122
|
104123
|
104352
|
104539