Bugzilla – Attachment 163531 Details for
Bug 31791
Add the ability to lock records to prevent modification through the Koha staff interface
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31791: Add Koha::Biblio->can_be_edited
Bug-31791-Add-KohaBiblio-canbeedited.patch (text/plain), 3.85 KB, created by
Tomás Cohen Arazi (tcohen)
on 2024-03-20 14:28:07 UTC
(
hide
)
Description:
Bug 31791: Add Koha::Biblio->can_be_edited
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2024-03-20 14:28:07 UTC
Size:
3.85 KB
patch
obsolete
>From 1c7802fc82356951935a50a08b4ff1cd3dede357 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 2 Feb 2024 16:23:42 -0300 >Subject: [PATCH] Bug 31791: Add Koha::Biblio->can_be_edited > >Sponsored-by: ByWater Solutions >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Biblio.pm | 18 +++++++++++ > t/db_dependent/Koha/Biblio.t | 62 +++++++++++++++++++++++++++++++++++- > 2 files changed, 79 insertions(+), 1 deletion(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 771af6c1676..75216bd5232 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -224,7 +224,25 @@ sub can_article_request { > return q{}; > } > >+=head3 can_be_edited > >+ if ( $biblio->can_be_edited( $patron ) ) { ... } >+ >+Returns a boolean denoting whether the passed I<$patron> meets the required >+conditions to manually edit the record. >+ >+=cut >+ >+sub can_be_edited { >+ my ( $self, $patron ) = @_; >+ >+ Koha::Exceptions::MissingParameter->throw( error => "The patron parameter is missing or invalid" ) >+ unless $patron && ref($patron) eq 'Koha::Patron'; >+ >+ return ( >+ ( $self->metadata->source_allows_editing && $patron->has_permission( { editcatalogue => 'edit_catalogue' } ) ) >+ || $patron->has_permission( { editcatalogue => 'edit_locked_records' } ) ) ? 1 : 0; >+} > > =head3 check_booking > >diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t >index d6cd9995d43..a91832f90e6 100755 >--- a/t/db_dependent/Koha/Biblio.t >+++ b/t/db_dependent/Koha/Biblio.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 36; >+use Test::More tests => 37; > use Test::Exception; > use Test::Warn; > >@@ -1549,6 +1549,66 @@ subtest 'opac_summary_html' => sub { > ); > }; > >+subtest 'can_be_edited() tests' => sub { >+ >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } ); >+ my $biblio = $builder->build_sample_biblio; >+ >+ my $source_allows_editing = 1; >+ >+ my $mock_metadata = Test::MockModule->new('Koha::Biblio::Metadata'); >+ $mock_metadata->mock( 'source_allows_editing', sub { return $source_allows_editing; } ); >+ >+ ok( !$biblio->can_be_edited($patron), "Patron needs 'edit_catalog' subpermission" ); >+ >+ # Add editcatalogue => edit_catalog subpermission >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $patron->id, >+ module_bit => 9, # editcatalogue >+ code => 'edit_catalogue', >+ }, >+ } >+ ); >+ >+ ok( $biblio->can_be_edited($patron), "Patron with 'edit_catalogue' can edit" ); >+ >+ # Mock the record source doesn't allow direct editing >+ $source_allows_editing = 0; >+ ok( !$biblio->can_be_edited($patron), "Patron needs 'edit_locked_record' subpermission for locked records" ); >+ >+ # Add editcatalogue => edit_catalog subpermission >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $patron->id, >+ module_bit => 9, # editcatalogue >+ code => 'edit_locked_records', >+ }, >+ } >+ ); >+ ok( $biblio->can_be_edited($patron), "Patron needs 'edit_locked_record' subpermission for locked records" ); >+ >+ throws_ok { $biblio->can_be_edited() } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown on missing parameter'; >+ >+ my $potato = 'Potato'; >+ >+ throws_ok { $biblio->can_be_edited($potato) } >+ 'Koha::Exceptions::MissingParameter', >+ 'Exception thrown if parameter not a Koha::Patron reference'; >+ >+ $schema->storage->txn_rollback; >+}; >+ > sub component_record1 { > my $marc = MARC::Record->new; > $marc->append_fields( >-- >2.44.0
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 31791
:
163371
|
163372
|
163373
|
163374
|
163375
|
163376
|
163377
|
163378
|
163405
|
163408
|
163410
|
163411
|
163413
|
163414
|
163415
|
163416
|
163426
|
163427
|
163428
|
163429
|
163430
|
163431
|
163432
|
163433
|
163434
|
163531
|
163532
|
163533
|
163534
|
163535
|
163536
|
163537
|
163538
|
163539
|
163545
|
164193
|
164194
|
164195
|
164196
|
164197
|
164696
|
164697
|
164698
|
164699
|
164700
|
164701
|
164702
|
164703
|
164704
|
164705
|
165044
|
165045
|
165046
|
165047
|
165048
|
165049
|
165050
|
165051
|
165052
|
165053
|
165697