Bug 20921 - Expose borrowernumber and branch when user is logged in to OPAC
Summary: Expose borrowernumber and branch when user is logged in to OPAC
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Nick Clemens
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-12 15:57 UTC by Nick Clemens
Modified: 2019-10-14 19:57 UTC (History)
4 users (show)

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


Attachments
Bug 20921: Add borrowernumber and branchcode as html attributes (2.00 KB, patch)
2018-06-12 16:02 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 20921: Add borrowernumber and branchcode as html attributes (2.02 KB, patch)
2018-06-19 23:39 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 20921: Add borrowernumber and branchcode as html attributes (2.12 KB, patch)
2018-06-22 21:00 UTC, Maryse Simard
Details | Diff | Splinter Review
Bug 20921: Add borrowernumber and branchcode as html attributes (2.19 KB, patch)
2018-06-25 19:57 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 20921: Fix opac_auth for selenium (1010 bytes, patch)
2018-06-25 19:57 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 20921: Add selenium tests for .loggedinusername (2.73 KB, patch)
2018-06-25 19:57 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clemens 2018-06-12 15:57:46 UTC
Some libraries would like the ability to trigger javascript ofr users of a certain branch or specific borrowers.

There is currently no way to retrieve this information on the opac.

This patchset will add these two variables as attributes on the loggedinusername span
Comment 1 Nick Clemens 2018-06-12 16:02:12 UTC
Created attachment 76005 [details] [review]
Bug 20921: Add borrowernumber and branchcode as html attributes

To test:
1 - Apply patch
2 - Visit the opac
3 - Sign in
4 - You should not see any difference
5 - Inspect the element  'Welcome, {username}'
6 - Note the attributes for borrowernumber and branchcode
7 - Add to OPACUserJS:
$(document).ready(function(){
    console.log( $(".loggedinusername").attr('branchcode'));
    console.log( $(".loggedinusername").attr('borrowernumber'));
});
8 - Check the console and note you can see the info expected
Comment 2 Katrin Fischer 2018-06-12 16:54:58 UTC
I think we already have the branch in the source code, but in another spot.
Comment 3 paxed 2018-06-13 08:30:37 UTC
Custom HTML attributes should be prefixed with "data-" (as per the HTML5 spec)
Comment 4 Katrin Fischer 2018-06-18 21:53:43 UTC
It's a class in the <body> tag:

<body ID="advsearch" class="branch-CPL scrollto" >

branch-CPL represents the branch of the currently logged in user. 

Maybe it would be cleaner to also add the borrowernumber there? Also the use of custom attributes appears strange to me - why use class for the username but then 2 attributes?
Comment 5 Owen Leonard 2018-06-19 12:33:31 UTC
(In reply to paxed from comment #3)
> Custom HTML attributes should be prefixed with "data-" (as per the HTML5
> spec)

I agree with this. I think it makes sense to add data- attributes for branch and borrowernumber even with the branch information in a class.
Comment 6 Katrin Fischer 2018-06-19 19:37:04 UTC
Talked to Owen on IRC - all things cleared up. I think only thing missing here is adding the data- prefix.
Comment 7 Nick Clemens 2018-06-19 23:39:14 UTC
Created attachment 76200 [details] [review]
Bug 20921: Add borrowernumber and branchcode as html attributes

To test:
1 - Apply patch
2 - Visit the opac
3 - Sign in
4 - You should not see any difference
5 - Inspect the element  'Welcome, {username}'
6 - Note the attributes for borrowernumber and branchcode
7 - Add to OPACUserJS:
$(document).ready(function(){
    console.log( $(".loggedinusername").attr('data-branchcode'));
    console.log( $(".loggedinusername").attr('data-borrowernumber'));
});
8 - Check the console and note you can see the info expected
Comment 8 Maryse Simard 2018-06-22 21:00:09 UTC
Created attachment 76310 [details] [review]
Bug 20921: Add borrowernumber and branchcode as html attributes

To test:
1 - Apply patch
2 - Visit the opac
3 - Sign in
4 - You should not see any difference
5 - Inspect the element  'Welcome, {username}'
6 - Note the attributes for borrowernumber and branchcode
7 - Add to OPACUserJS:
$(document).ready(function(){
    console.log( $(".loggedinusername").attr('data-branchcode'));
    console.log( $(".loggedinusername").attr('data-borrowernumber'));
});
8 - Check the console and note you can see the info expected

Signed-off-by: Maryse Simard <maryse.simard@inlibro.com>
Followed the test plan and it works.
Comment 9 Jonathan Druart 2018-06-25 19:57:10 UTC
Created attachment 76413 [details] [review]
Bug 20921: Add borrowernumber and branchcode as html attributes

To test:
1 - Apply patch
2 - Visit the opac
3 - Sign in
4 - You should not see any difference
5 - Inspect the element  'Welcome, {username}'
6 - Note the attributes for borrowernumber and branchcode
7 - Add to OPACUserJS:
$(document).ready(function(){
    console.log( $(".loggedinusername").attr('data-branchcode'));
    console.log( $(".loggedinusername").attr('data-borrowernumber'));
});
8 - Check the console and note you can see the info expected

Signed-off-by: Maryse Simard <maryse.simard@inlibro.com>
Followed the test plan and it works.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 10 Jonathan Druart 2018-06-25 19:57:16 UTC
Created attachment 76414 [details] [review]
Bug 20921: Fix opac_auth for selenium

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 11 Jonathan Druart 2018-06-25 19:57:22 UTC
Created attachment 76415 [details] [review]
Bug 20921: Add selenium tests for .loggedinusername

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 12 Jonathan Druart 2018-06-25 19:58:08 UTC
I am not sure it makes sense to have borrowernumber and branchcode at loggedinusername level. Maybe we should rename it "loggedinuser"?
Can be done later.
Comment 13 Nick Clemens 2018-06-29 21:04:33 UTC
Awesome work all!

Pushed to master for 18.11
Comment 14 Martin Renvoize 2018-07-02 09:20:12 UTC
Enhancement, won't be backported to 18.05.x series.