Bugzilla – Attachment 117948 Details for
Bug 27857
Koha::Patron->extended_attributes skips checks
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27857: Add handling for globally mandatory attributes
Bug-27857-Add-handling-for-globally-mandatory-attr.patch (text/plain), 3.61 KB, created by
David Nind
on 2021-03-08 18:51:37 UTC
(
hide
)
Description:
Bug 27857: Add handling for globally mandatory attributes
Filename:
MIME Type:
Creator:
David Nind
Created:
2021-03-08 18:51:37 UTC
Size:
3.61 KB
patch
obsolete
>From 69b617fc58eed52dd3759fbfe76ba01bce1dd46d Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 8 Mar 2021 17:24:28 +0000 >Subject: [PATCH] Bug 27857: Add handling for globally mandatory attributes > >This patch adds handling for globally mandatory extended attributes and >the corresponding unit tests. > >Signed-off-by: David Nind <david@davidnind.com> >--- > Koha/Patron.pm | 19 +++++++++++++++++++ > t/db_dependent/Koha/Patron.t | 38 +++++++++++++++++++++++++++++++++++++- > 2 files changed, 56 insertions(+), 1 deletion(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 2d484beae7..1160084ca6 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -1561,8 +1561,27 @@ sub extended_attributes { > $self->extended_attributes->filter_by_branch_limitations->delete; > > # Insert the new ones >+ my $new_types = {}; > for my $attribute (@$attributes) { > $self->add_extended_attribute($attribute); >+ $new_types->{$attribute->{code}} = 1; >+ } >+ >+ # Check globally mandatory types >+ my @required_attribute_types = >+ Koha::Patron::Attribute::Types->search( >+ { >+ mandatory => 1, >+ 'borrower_attribute_types_branches.b_branchcode' => >+ undef >+ }, >+ { join => 'borrower_attribute_types_branches' } >+ )->get_column('class'); >+ for my $type ( @required_attribute_types ) { >+ Koha::Exceptions::Object::FKConstraint->throw( >+ broken_fk => "$type", >+ value => "$type", >+ ) if !$new_types->{$type}; > } > } > ); >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index f5f33e0d8a..98b079f4c3 100755 >--- a/t/db_dependent/Koha/Patron.t >+++ b/t/db_dependent/Koha/Patron.t >@@ -369,7 +369,7 @@ subtest 'is_superlibrarian() tests' => sub { > > subtest 'extended_attributes' => sub { > >- plan tests => 14; >+ plan tests => 15; > > my $schema = Koha::Database->new->schema; > $schema->storage->txn_begin; >@@ -614,5 +614,41 @@ subtest 'extended_attributes' => sub { > is( $patron->extended_attributes->count, 0, 'Extended attributes storing rolled back' ); > }; > >+ subtest 'globally mandatory attributes tests' => sub { >+ >+ plan tests => 3; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ my $attribute_type_1 = $builder->build_object( >+ { >+ class => 'Koha::Patron::Attribute::Types', >+ value => { mandatory => 1 } >+ } >+ ); >+ >+ my $attribute_type_2 = $builder->build_object( >+ { >+ class => 'Koha::Patron::Attribute::Types', >+ value => { mandatory => 0 } >+ } >+ ); >+ >+ is( $patron->extended_attributes->count, 0, 'Patron has no extended attributes' ); >+ >+ throws_ok >+ { >+ $patron->extended_attributes( >+ [ >+ { code => $attribute_type_2->code, attribute => 'b' } >+ ] >+ ); >+ } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'Exception thrown on missing mandatory attribute type'; >+ >+ is( $patron->extended_attributes->count, 0, 'Extended attributes storing rolled back' ); >+ }; >+ > $schema->storage->txn_rollback; > }; >-- >2.11.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 27857
:
117709
|
117710
|
117711
|
117938
|
117945
|
117946
|
117947
|
117948
|
117953
|
117954
|
117955
|
117956
|
117957
|
119009
|
119038
|
119040
|
119443
|
119937
|
119938