Bug 8326

Summary: Allow patron attributes to be made repeatable after initial creation
Product: Koha Reporter: Nicole C. Engard <nengard>
Component: PatronsAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P5 - low CC: david, fridolin.somers, gmcharlt, jonathan.druart, kyle.m.hall
Version: MainKeywords: Manual
Hardware: All   
OS: All   
URL: cgi-bin/koha/admin/patron-attr-types.pl?op=edit_attribute_type&code=DL
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
This enhancement lets you modify the attributes "repeatable" and "unique identifier" for patron attribute types. Before this change it was not possible to modify these after they were initially set. Now you can modify patron attribute types, depending on the existing values recorded: - repeatable: can make repeatable if it wasn't before; can make not repeatable once any repeatable values are removed - unique identifier: if unique is set you can't add the same value to other patrons; you can't make an existing attribute unique until you edit all the existing values recorded for patrons and make them unique
Version(s) released in:
21.05.00
Circulation function:
Bug Depends on: 20443    
Bug Blocks:    
Attachments: Bug 8326: Make repeatable and unique_id modifiable when editing patron attribute type
Bug 8326: Make repeatable and unique_id modifiable when editing patron attribute type
Bug 8326: Make repeatable and unique_id modifiable when editing patron attribute type
Bug 8326: Make repeatable and unique_id modifiable when editing patron attribute type
Bug 8326: Add aria-disabled to li's
Bug 8326: Add tooltips
Bug 8326: Make repeatable and unique_id modifiable when editing patron attribute type
Bug 8326: Add aria-disabled to li's
Bug 8326: Add tooltips

Description Nicole C. Engard 2012-06-27 13:25:36 UTC
I understand not letting people edit attribute codes or the fact that it's a unique identifier after it has been saved, but I see no reason why an attribute can't be made repeatable retroactively. I think this value should be editable - at least from 'not repeatable' to 'repeatable' since it might cause problems going from 'repeatable' to 'not repeatable'.
Comment 1 Jonathan Druart 2018-07-18 13:36:02 UTC
If bug 20443 is integrated rapidly I will have a look at fixing this bug.
Comment 2 Jonathan Druart 2020-05-07 14:59:07 UTC Comment hidden (obsolete)
Comment 3 David Nind 2020-10-03 22:55:29 UTC
Hi Jonathan.

For step 3 I can remove the repeatable flag, but get this error trace message (I also get this when the attributes were setup before applying the patch where there are patrons using it):

The property 'repeatable' cannot be changed, some patron attributes are using it that way. at /usr/share/perl5/Exception/Class/Base.pm line 88

    in Exception::Class::Base::throw at /usr/share/perl5/Exception/Class/Base.pm line 88

       85: 
       86:     $proto->rethrow if ref $proto;
       87: 
       88:     die $proto->new(@_);
       89: }
       90: 
       91: sub rethrow {

    Show function arguments
    in Koha::Patron::Attribute::Type::check_repeatables at /kohadevbox/koha/Koha/Patron/Attribute/Type.pm line 85

       82:         }
       83:     )->count;
       84: 
       85:     Koha::Exceptions::Patron::Attribute::Type::CannotChangeProperty->throw(
       86:         property => 'repeatable' )
       87:       if $count;

For step 5 I can remove the unique flag.

David
Comment 4 Jonathan Druart 2021-02-02 10:02:09 UTC Comment hidden (obsolete)
Comment 5 Jonathan Druart 2021-02-02 10:04:55 UTC
Created attachment 116194 [details] [review]
Bug 8326: Make repeatable and unique_id modifiable when editing patron attribute type

This patch add the ability to modify the attribute "repeatable" and
"unique_id" for a patron's attribute type.
Prior to this patch it was not possible, to keep data integrity.

When editing an attr type, the controller will check is the value can be
modified, depending on the existing patron's attributes.

Test plan:
0/ Setup
Create 1 patron attribute PA1 that can be repeatable
Create 1 patron attribute PA2 that does not have the unique restriction
Create 1 patron attribute PA3 that cannot be repeatable and does not
have the unique restriction

1/
Edit them and confirm that you can modify the repeatable and unique
restrictions

2/ Restore values from 0.
Create a patron P1 with several PA1, PA2=42 and whatever in PA3

3/ Edit PA1 => you cannot remove the repeatable flag but can still
remove the unique

4/ Create a patron P2 with PA2=42

5/ Edit PA2 => you cannot add the unique flag

Play a bit more with the different combinaisons and confirm that it
works as advertised.
Comment 6 Jonathan Druart 2021-02-02 10:05:05 UTC
Sorry David, I completely forgot this patch.
There were some bugs indeed!
I've improved the test plan a bit, hope it makes more sense now.
Comment 7 David Nind 2021-02-03 20:07:06 UTC
Created attachment 116294 [details] [review]
Bug 8326: Make repeatable and unique_id modifiable when editing patron attribute type

This patch add the ability to modify the attribute "repeatable" and
"unique_id" for a patron's attribute type.
Prior to this patch it was not possible, to keep data integrity.

When editing an attr type, the controller will check is the value can be
modified, depending on the existing patron's attributes.

Test plan:
0/ Setup
Create 1 patron attribute PA1 that can be repeatable
Create 1 patron attribute PA2 that does not have the unique restriction
Create 1 patron attribute PA3 that cannot be repeatable and does not
have the unique restriction

1/
Edit them and confirm that you can modify the repeatable and unique
restrictions

2/ Restore values from 0.
Create a patron P1 with several PA1, PA2=42 and whatever in PA3

3/ Edit PA1 => you cannot remove the repeatable flag but can still
remove the unique

4/ Create a patron P2 with PA2=42

5/ Edit PA2 => you cannot add the unique flag

Play a bit more with the different combinaisons and confirm that it
works as advertised.

Signed-off-by: David Nind <david@davidnind.com>
Comment 8 David Nind 2021-02-03 20:17:29 UTC
(In reply to Jonathan Druart from comment #6)
> Sorry David, I completely forgot this patch.
> There were some bugs indeed!
> I've improved the test plan a bit, hope it makes more sense now.

Thanks Jonathan!

The logic all seems to work for me:

- For the unique flag:
  . if unique is set, you can't add the same value to other patrons
  . if not set and multiple patrons with the same value, you can't make it unique until you make the values unique for all patrons

- For the repeatable flag:
  . you can't unset it until any repeatable values are removed from patrons
  . you can set it as repeatable if it wasn't repeatable before

David
Comment 9 Katrin Fischer 2021-02-07 13:25:45 UTC
Afaikt this works quite nicely. I have 2 enhancement requests:

1) The "Editable in OPAC" shows greyed out when self registration is used. Can we use the same style if the unique and repeatable cannot be changed? This would increase visibility and consistency.

2) Could we add a tooltip that explains that existing data prevents the change? I think this could be helpful.

I'd really like 1), 2) is a wish list item :)
Comment 10 Jonathan Druart 2021-02-08 10:06:33 UTC
Created attachment 116483 [details] [review]
Bug 8326: Add aria-disabled to li's

To have the same display of "Editable in OPAC"
Comment 11 Jonathan Druart 2021-02-08 10:06:36 UTC
Created attachment 116484 [details] [review]
Bug 8326: Add tooltips
Comment 12 Katrin Fischer 2021-02-14 14:42:44 UTC
Created attachment 116857 [details] [review]
Bug 8326: Make repeatable and unique_id modifiable when editing patron attribute type

This patch add the ability to modify the attribute "repeatable" and
"unique_id" for a patron's attribute type.
Prior to this patch it was not possible, to keep data integrity.

When editing an attr type, the controller will check is the value can be
modified, depending on the existing patron's attributes.

Test plan:
0/ Setup
Create 1 patron attribute PA1 that can be repeatable
Create 1 patron attribute PA2 that does not have the unique restriction
Create 1 patron attribute PA3 that cannot be repeatable and does not
have the unique restriction

1/
Edit them and confirm that you can modify the repeatable and unique
restrictions

2/ Restore values from 0.
Create a patron P1 with several PA1, PA2=42 and whatever in PA3

3/ Edit PA1 => you cannot remove the repeatable flag but can still
remove the unique

4/ Create a patron P2 with PA2=42

5/ Edit PA2 => you cannot add the unique flag

Play a bit more with the different combinaisons and confirm that it
works as advertised.

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 13 Katrin Fischer 2021-02-14 14:42:48 UTC
Created attachment 116858 [details] [review]
Bug 8326: Add aria-disabled to li's

To have the same display of "Editable in OPAC"

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 14 Katrin Fischer 2021-02-14 14:42:52 UTC
Created attachment 116859 [details] [review]
Bug 8326: Add tooltips

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 15 Jonathan Druart 2021-02-15 11:08:22 UTC
Pushed to master for 21.05, thanks to everybody involved!
Comment 16 Fridolin Somers 2021-02-19 15:30:33 UTC
Enhancement not pushed to 20.11.x

Awesome enhancement :D