Bug 37742 - My virtual card error message not showing
Summary: My virtual card error message not showing
Status: Pushed to main
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor
Assignee: David Cook
QA Contact: Martin Renvoize (ashimema)
URL:
Keywords:
Depends on: 26777
Blocks:
  Show dependency treegraph
 
Reported: 2024-08-27 02:05 UTC by David Cook
Modified: 2024-10-25 13:38 UTC (History)
2 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
This fixes an error message shown for a patron's virtual card in the OPAC, where the patron's card number can't be converted to a Code39 barcode* (OPACVirtualCard system preference enabled, Your account > My virtual card). Previously the error message was "Error: ${errorMessage}", now it is "Error: Unable to generate barcode". * Code 39 barcodes can only contain digits, capital letters, spaces, and the symbols -.$/+%
Version(s) released in:
24.11.00
Circulation function:


Attachments
Bug 37742: Fix error display (1.84 KB, patch)
2024-08-27 03:52 UTC, David Cook
Details | Diff | Splinter Review
Bug 37742: Fix error display (2.12 KB, patch)
2024-08-28 23:51 UTC, David Cook
Details | Diff | Splinter Review
Bug 37742: Fix error display (2.17 KB, patch)
2024-09-06 22:57 UTC, David Nind
Details | Diff | Splinter Review
Bug 37742: Fix error display (2.23 KB, patch)
2024-10-25 12:35 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description David Cook 2024-08-27 02:05:32 UTC
If the patron barcode can't be converted into Code39, it should show an error message, but right now there's a coding error.

It just shows the following: Error: ${errorMessage}
Comment 1 David Cook 2024-08-27 02:12:20 UTC
If the translations can use template literals, then you could switch back to a template literal.

However, a better idea is to build the HTML using DOM objects. 

Something like...

let para = document.createElement('p');
let strong = document.createElement('strong');
strong.textContent = __("Error:");
let err_msg = document.createTextNode(errorMessage);
para.appendChild(strong);
para.appendChild(err_msg);
document.getElementById('barcode-container').appendChild(para);

--

I get that it's a lot longer to write, but it's a billion times safer than using innerHTML. 

Look at "Cross Site Scripting Prevention Cheat Sheet" by OWASP. Specifically "Safe Sinks".
Comment 2 David Cook 2024-08-27 02:13:00 UTC
I'll probably look at this after an upcoming meeting...
Comment 3 David Cook 2024-08-27 03:52:41 UTC
Created attachment 170744 [details] [review]
Bug 37742: Fix error display

This change fixes the display of the error message on "My virtual card"
on the OPAC.

Test plan:
0. Apply the patch and enable syspref "OPACVirtualCard"
1. Go to http://localhost:8081/cgi-bin/koha/members/memberentry.pl
?op=edit_form&destination=circ&borrowernumber=51
2. Add an asterisk (*) to the end of the card number
3. Go to http://localhost:8080/cgi-bin/koha/opac-virtual-card.pl
4. Note that the error message appears as follows:
Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%
Comment 4 Katrin Fischer 2024-08-27 05:18:11 UTC
I think you are correct about that we should not show a technical error to the user. But it might help debug library staff and I assume they would test this before keeping it active for public?
Comment 5 David Cook 2024-08-27 06:08:25 UTC
(In reply to Katrin Fischer from comment #4)
> I think you are correct about that we should not show a technical error to
> the user. But it might help debug library staff and I assume they would test
> this before keeping it active for public?

Perhaps we should have a patron barcode on the staff side too, and then they could troubleshoot it from that side instead?

The tough thing with something like this is that there can be a lot of variation in cardnumbers. It might work for a lot of borrowers but not all, and then only a minority are seeing the weirdness.
Comment 6 Katrin Fischer 2024-08-27 06:48:23 UTC
OK, so we need to decide here if we want to adapt the error to be generic or not.
Comment 7 Katrin Fischer 2024-08-27 08:24:47 UTC
(In reply to David Cook from comment #1)
> If the translations can use template literals, then you could switch back to
> a template literal.

What exactly is a template literal? 

AFAIK our tools can parse HTML in HTML pages, but not HTML that is constructed in JS.
Comment 8 Katrin Fischer 2024-08-27 08:55:15 UTC
I'd love to get some quick opinion on the message, so we can fix this fast (yes, feeling slightly guilty :) )
Comment 9 David Cook 2024-08-28 00:21:01 UTC
(In reply to Katrin Fischer from comment #6)
> OK, so we need to decide here if we want to adapt the error to be generic or
> not.

Happy to follow your lead here. My opinion is we should show something more user-friendly but that's just my opinion.
Comment 10 David Cook 2024-08-28 00:21:23 UTC
(In reply to Katrin Fischer from comment #7)
> (In reply to David Cook from comment #1)
> > If the translations can use template literals, then you could switch back to
> > a template literal.
> 
> What exactly is a template literal? 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Comment 11 David Cook 2024-08-28 00:23:59 UTC
(In reply to Katrin Fischer from comment #8)
> I'd love to get some quick opinion on the message, so we can fix this fast
> (yes, feeling slightly guilty :) )

<3

Instead of using "errorMessage" here I think we could use __("Unavailable to generate barcode").

It should be translatable, and I think anyone with developer support should be able to figure out the problem. If they don't have support, they can come online, and I'll probably end up helping them anyway :p
Comment 12 Katrin Fischer 2024-08-28 11:32:33 UTC
(In reply to David Cook from comment #10)
> (In reply to Katrin Fischer from comment #7)
> > (In reply to David Cook from comment #1)
> > > If the translations can use template literals, then you could switch back to
> > > a template literal.
> > 
> > What exactly is a template literal? 
> 
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/
> Template_literals

I don't think our tools can parse these currently. You'd also not want translators faced with the HTML bits included in these, but only the text.


>Instead of using "errorMessage" here I think we could use __("Unavailable to >generate barcode").

I'd maybe make it:

Uanble to generate barcode

Or:

The barcode image could not be generated. Please get in touch with library staff.
Comment 13 David Cook 2024-08-28 23:43:49 UTC
(In reply to Katrin Fischer from comment #12)
> I don't think our tools can parse these currently. You'd also not want
> translators faced with the HTML bits included in these, but only the text.

It looks like xgettext supports it (bug 24725), and we removed a prohibition against them. 

But I see your point about not wanting translators faced with the HTML/Javascript bits. Although maybe xgettext deals with that? Unfortunately, I don't know enough about the translatability topic.

Scanning through koha-tmpl, it looks like they're just used for non-translateable bits of JS code.

Might be worth adding a coding guideline for that I reckon...

> >Instead of using "errorMessage" here I think we could use __("Unavailable to >generate barcode").
> 
> I'd maybe make it:
> 
> Uanble to generate barcode
> 
> Or:
> 
> The barcode image could not be generated. Please get in touch with library
> staff.

Patch incoming...
Comment 14 David Cook 2024-08-28 23:51:27 UTC
Created attachment 170850 [details] [review]
Bug 37742: Fix error display

This change fixes the display of the error message on "My virtual card"
on the OPAC.

Test plan:
0. Apply the patch and enable syspref "OPACVirtualCard"
1. Go to http://localhost:8081/cgi-bin/koha/members/memberentry.pl
?op=edit_form&destination=circ&borrowernumber=51
2. Add an asterisk (*) to the end of the card number
3. Go to http://localhost:8080/cgi-bin/koha/opac-virtual-card.pl
4. Note that the error message appears as follows:
Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%
Comment 15 David Nind 2024-09-06 22:57:16 UTC
Created attachment 171159 [details] [review]
Bug 37742: Fix error display

This change fixes the display of the error message on "My virtual card"
on the OPAC.

Test plan:
0. Apply the patch and enable syspref "OPACVirtualCard"
1. Go to http://localhost:8081/cgi-bin/koha/members/memberentry.pl
?op=edit_form&destination=circ&borrowernumber=51
2. Add an asterisk (*) to the end of the card number
3. Go to http://localhost:8080/cgi-bin/koha/opac-virtual-card.pl
4. Note that the error message appears as follows:
Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%

Signed-off-by: David Nind <david@davidnind.com>
Comment 16 Martin Renvoize (ashimema) 2024-10-25 12:35:49 UTC
Created attachment 173355 [details] [review]
Bug 37742: Fix error display

This change fixes the display of the error message on "My virtual card"
on the OPAC.

Test plan:
0. Apply the patch and enable syspref "OPACVirtualCard"
1. Go to http://localhost:8081/cgi-bin/koha/members/memberentry.pl
?op=edit_form&destination=circ&borrowernumber=51
2. Add an asterisk (*) to the end of the card number
3. Go to http://localhost:8080/cgi-bin/koha/opac-virtual-card.pl
4. Note that the error message appears as follows:
Code 39 must contain only digits, capital letters, spaces and the symbols -.$/+%

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 17 Katrin Fischer 2024-10-25 13:38:58 UTC
Pushed for 24.11!

Well done everyone, thank you!