Bug 31791: Add Koha::Biblio->can_be_edited
Sponsored-by: ByWater Solutions Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
048eb5fa95
commit
e8595f9d62
2 changed files with 79 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue