Bug 33940 - Move get_cardnumber_length and checkcardnumber to Koha
Summary: Move get_cardnumber_length and checkcardnumber to Koha
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement
Assignee: Jonathan Druart
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 16846 34338 34414
  Show dependency treegraph
 
Reported: 2023-06-07 13:36 UTC by Jonathan Druart
Modified: 2024-07-04 20:37 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.11.00
Circulation function:


Attachments
Bug 33940: Move C4::Members cardnumber sub to Koha::Policy::Patrons::Cardnumber (27.41 KB, patch)
2023-06-07 13:49 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33940: Move C4::Members cardnumber sub to Koha::Policy::Patrons::Cardnumber (27.42 KB, patch)
2023-07-21 08:21 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 33940: Consider NULL as valid (1.84 KB, patch)
2023-07-21 08:48 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33940: Move C4::Members cardnumber sub to Koha::Policy::Patrons::Cardnumber (27.47 KB, patch)
2023-07-21 09:42 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 33940: Consider NULL as valid (1.93 KB, patch)
2023-07-21 09:42 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 33940: (QA follow-up) Remove obsolete length of 20 (1.17 KB, patch)
2023-07-21 09:45 UTC, Marcel de Rooy
Details | Diff | Splinter Review
Bug 33940: Fix selfreg (1.11 KB, patch)
2023-07-21 09:56 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33940: Fix messages we sent to templates (2.53 KB, patch)
2023-07-21 10:03 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33940: Fix what we send to memberentry (1.05 KB, patch)
2023-07-21 10:08 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33940: Move C4::Members cardnumber sub to Koha::Policy::Patrons::Cardnumber (27.74 KB, patch)
2023-07-21 10:10 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33940: Consider NULL as valid (1.89 KB, patch)
2023-07-21 10:10 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33940: (QA follow-up) Remove obsolete length of 20 (1.14 KB, patch)
2023-07-21 10:10 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 33940: Move C4::Members cardnumber sub to Koha::Policy::Patrons::Cardnumber (27.79 KB, patch)
2023-09-15 14:42 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 33940: Consider NULL as valid (1.95 KB, patch)
2023-09-15 14:42 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review
Bug 33940: (QA follow-up) Remove obsolete length of 20 (1.19 KB, patch)
2023-09-15 14:42 UTC, Tomás Cohen Arazi (tcohen)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2023-06-07 13:36:50 UTC
C4::Members::get_cardnumber_length and C4::Members::checkcardnumber must be moved to the Koha namespace
Comment 1 Jonathan Druart 2023-06-07 13:49:38 UTC
Created attachment 152109 [details] [review]
Bug 33940: Move C4::Members cardnumber sub to Koha::Policy::Patrons::Cardnumber

Test plan:
The idea here is to confirm this patch does not introduce regression.
For that you will play with the CardnumberLength syspref and create a
new user, modify an existing one, and check that the UI does not let you
modify an invalid cardnumber.
The onboarding process and the patron import tool will also have to be tested
Comment 2 Jonathan Druart 2023-06-07 13:55:34 UTC
Actually you will need to edit the DOM of the patron edit page, to remove the min and max length on the cardnumber's input. Otherwise the form will be validate client-side and you won't reach the changes made by this patch.
Comment 3 Marcel de Rooy 2023-07-21 07:59:52 UTC
Will add tiny rebase for bug 33937
Comment 4 Marcel de Rooy 2023-07-21 08:00:00 UTC
 OK     C4/Members.pm

 WARN   Koha/Patrons/Import.pm
   WARN   tidiness
                The file is less tidy than before (bad/messy lines before: 199, now: 201)

 OK     Koha/Policy/Patrons/Cardnumber.pm

 WARN   installer/onboarding.pl
   WARN   tidiness
                The file is less tidy than before (bad/messy lines before: 60, now: 61)

 OK     members/memberentry.pl

 WARN   opac/opac-memberentry.pl
   WARN   tidiness
                The file is less tidy than before (bad/messy lines before: 167, now: 169)

 OK     t/Members/cardnumber.t

 WARN   t/db_dependent/Koha/Policy/Patrons/Cardnumber.t
   WARN   tidiness
                The file is less tidy than before (bad/messy lines before: 0, now: 45)

 OK     t/db_dependent/Members.t
Comment 5 Marcel de Rooy 2023-07-21 08:00:30 UTC
Wont add tidy stuff :)
Comment 6 Marcel de Rooy 2023-07-21 08:21:17 UTC
-    # If cardnumber is null, we assume they're allowed.
-    return 0 unless defined $cardnumber;

+    return Koha::Result::Boolean->new(0)->add_message( { message => "is_empty" } )
+        unless defined $cardnumber;

The former routine returned 0 meaning OK.
The new routine returns 0 meaning false.
You are changing behavior. Mabye I just dont wanna use cardnumber.

Not sure if it is needed to make a distinction here btw between null and empty string.
Currently, message => "is_empty" should read is_undefined.

We miss tests for this situation.
Comment 7 Marcel de Rooy 2023-07-21 08:21:47 UTC
Created attachment 153758 [details] [review]
Bug 33940: Move C4::Members cardnumber sub to Koha::Policy::Patrons::Cardnumber

Test plan:
The idea here is to confirm this patch does not introduce regression.
For that you will play with the CardnumberLength syspref and create a
new user, modify an existing one, and check that the UI does not let you
modify an invalid cardnumber.
The onboarding process and the patron import tool will also have to be tested
Comment 8 Jonathan Druart 2023-07-21 08:30:50 UTC
(In reply to Marcel de Rooy from comment #6)
> -    # If cardnumber is null, we assume they're allowed.
> -    return 0 unless defined $cardnumber;
> 
> +    return Koha::Result::Boolean->new(0)->add_message( { message =>
> "is_empty" } )
> +        unless defined $cardnumber;
> 
> The former routine returned 0 meaning OK.
> The new routine returns 0 meaning false.
> You are changing behavior. Mabye I just dont wanna use cardnumber.

I don't understand the problem. I am also changing if with unless...

-        if ( my $error_code = checkcardnumber($cardnumber) ) {
+        unless ( $is_cardnumber_valid ) {

> Not sure if it is needed to make a distinction here btw between null and
> empty string.
> Currently, message => "is_empty" should read is_undefined.
> 
> We miss tests for this situation.

empty string will be caught by invalid_length
unless defined (returning is_empty)

Rereading the code:
-    # If cardnumber is null, we assume they're allowed.
-    return 0 unless defined $cardnumber;

+    return Koha::Result::Boolean->new(0)->add_message( { message => "is_empty" } )
+        unless defined $cardnumber;

So there might be a change in behaviour here.
Comment 9 Marcel de Rooy 2023-07-21 08:42:19 UTC
Adding field length to comments is dangerous

+    my ( $min, $max ) = ( 0, $field_size );    # borrowers.cardnumber is a nullable varchar(20)

Pref and DB:
Maximum cannot be bigger than the database field size of 32.
Comment 10 Jonathan Druart 2023-07-21 08:48:16 UTC
Created attachment 153759 [details] [review]
Bug 33940: Consider NULL as valid
Comment 11 Jonathan Druart 2023-07-21 08:49:29 UTC
(In reply to Marcel de Rooy from comment #9)
> Adding field length to comments is dangerous
> 
> +    my ( $min, $max ) = ( 0, $field_size );    # borrowers.cardnumber is a
> nullable varchar(20)
> 
> Pref and DB:
> Maximum cannot be bigger than the database field size of 32.

This is not an addition. This has been moved from existing code.
Comment 12 Marcel de Rooy 2023-07-21 08:51:14 UTC
Testing experience:

Have a borrower with empty card number (NULL in db).
Set length pref to 1.
Edit borrower. See the message should be 1.
Save.
It accepts the empty cardnumber.
Comment 13 Marcel de Rooy 2023-07-21 08:51:42 UTC
(In reply to Jonathan Druart from comment #11)
> (In reply to Marcel de Rooy from comment #9)
> > Adding field length to comments is dangerous
> > 
> > +    my ( $min, $max ) = ( 0, $field_size );    # borrowers.cardnumber is a
> > nullable varchar(20)
> > 
> > Pref and DB:
> > Maximum cannot be bigger than the database field size of 32.
> 
> This is not an addition. This has been moved from existing code.

I know. But it is not true anymore.
Comment 14 Marcel de Rooy 2023-07-21 08:58:21 UTC
(In reply to Marcel de Rooy from comment #12)
> Testing experience:
> 
> Have a borrower with empty card number (NULL in db).
> Set length pref to 1.
> Edit borrower. See the message should be 1.
> Save.
> It accepts the empty cardnumber.

Still valid. Allows saving a space too. But fields remains NULL.
Comment 15 Marcel de Rooy 2023-07-21 09:06:42 UTC
(In reply to Marcel de Rooy from comment #14)
> (In reply to Marcel de Rooy from comment #12)
> > Testing experience:
> > 
> > Have a borrower with empty card number (NULL in db).
> > Set length pref to 1.
> > Edit borrower. See the message should be 1.
> > Save.
> > It accepts the empty cardnumber.
> 
> Still valid. Allows saving a space too. But fields remains NULL.

But it needs a weird combination of sysprefs. Could be a separate bug..
Comment 16 Marcel de Rooy 2023-07-21 09:42:49 UTC
Created attachment 153763 [details] [review]
Bug 33940: Move C4::Members cardnumber sub to Koha::Policy::Patrons::Cardnumber

Test plan:
The idea here is to confirm this patch does not introduce regression.
For that you will play with the CardnumberLength syspref and create a
new user, modify an existing one, and check that the UI does not let you
modify an invalid cardnumber.
The onboarding process and the patron import tool will also have to be tested

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 17 Marcel de Rooy 2023-07-21 09:42:52 UTC
Created attachment 153764 [details] [review]
Bug 33940: Consider NULL as valid

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 18 Marcel de Rooy 2023-07-21 09:45:32 UTC
Created attachment 153766 [details] [review]
Bug 33940: (QA follow-up) Remove obsolete length of 20

Currently 32. Could be 43 tomorrow :)

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 19 Jonathan Druart 2023-07-21 09:56:13 UTC
Created attachment 153768 [details] [review]
Bug 33940: Fix selfreg

please squash with first patch
Comment 20 Marcel de Rooy 2023-07-21 09:58:48 UTC
(In reply to Jonathan Druart from comment #19)
> Created attachment 153768 [details] [review] [review]
> Bug 33940: Fix selfreg
> 
> please squash with first patch

Good catch.
Comment 21 Jonathan Druart 2023-07-21 10:03:29 UTC
Created attachment 153769 [details] [review]
Bug 33940: Fix messages we sent to templates

please squash with the first patch
Comment 22 Jonathan Druart 2023-07-21 10:06:33 UTC
Hum, found too many things here.
Comment 23 Jonathan Druart 2023-07-21 10:08:56 UTC
Created attachment 153770 [details] [review]
Bug 33940: Fix what we send to memberentry
Comment 24 Jonathan Druart 2023-07-21 10:10:18 UTC
Created attachment 153771 [details] [review]
Bug 33940: Move C4::Members cardnumber sub to Koha::Policy::Patrons::Cardnumber

Test plan:
The idea here is to confirm this patch does not introduce regression.
For that you will play with the CardnumberLength syspref and create a
new user, modify an existing one, and check that the UI does not let you
modify an invalid cardnumber.
The onboarding process and the patron import tool will also have to be tested

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Bug 33940: Fix selfreg

please squash with first patch

Bug 33940: Fix messages we sent to templates

please squash with the first patch

Bug 33940: Fix what we send to memberentry
Comment 25 Jonathan Druart 2023-07-21 10:10:21 UTC
Created attachment 153772 [details] [review]
Bug 33940: Consider NULL as valid

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 26 Jonathan Druart 2023-07-21 10:10:24 UTC
Created attachment 153773 [details] [review]
Bug 33940: (QA follow-up) Remove obsolete length of 20

Currently 32. Could be 43 tomorrow :)

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 27 Tomás Cohen Arazi (tcohen) 2023-09-15 14:42:05 UTC
Created attachment 155687 [details] [review]
Bug 33940: Move C4::Members cardnumber sub to Koha::Policy::Patrons::Cardnumber

Test plan:
The idea here is to confirm this patch does not introduce regression.
For that you will play with the CardnumberLength syspref and create a
new user, modify an existing one, and check that the UI does not let you
modify an invalid cardnumber.
The onboarding process and the patron import tool will also have to be tested

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Bug 33940: Fix selfreg

please squash with first patch

Bug 33940: Fix messages we sent to templates

please squash with the first patch

Bug 33940: Fix what we send to memberentry

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 28 Tomás Cohen Arazi (tcohen) 2023-09-15 14:42:08 UTC
Created attachment 155688 [details] [review]
Bug 33940: Consider NULL as valid

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 29 Tomás Cohen Arazi (tcohen) 2023-09-15 14:42:12 UTC
Created attachment 155689 [details] [review]
Bug 33940: (QA follow-up) Remove obsolete length of 20

Currently 32. Could be 43 tomorrow :)

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 30 Tomás Cohen Arazi (tcohen) 2023-09-15 14:58:34 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 31 Fridolin Somers 2023-09-18 07:33:13 UTC
Enhancement not pushed to 23.05.x