Koha Solutions knowledge base: run log of a live check Article https://kohasolutions.com/knowledge-base/koha-independent-branches Check scripts/kb/live/koha-independent-branches.mjs (SHA-256 225414f42ae34ae04dfa91354d108e7e6defd95b3b73b0414140c37cda864267) Ran 2026-11-05T16:29:42Z (UTC), 44 s Koha 26.05.02 (Koha::version 26.05.02.002, database version 26.0600002) Source https://git.koha-community.org/Koha-community/Koha/src/commit/d3fc229bc5eaea25dfe88f86149386408fe5d32d System Debian GNU/Linux 13 (trixie) Result PASS: all 25 claims held Each claim is something the article says. "seen" is what the check read back when it is not just a yes/no. Changes the check made to the test server were undone afterwards, as its header describes. == Claims == ok IndependentBranches off: the staff login page offers a "Library:" choice ok off: the Centerville staff member opens the Midway patron ok off: the Centerville staff member can open a Midway item for editing seen: http://localhost:8081/cgi-bin/koha/cataloguing/additem.pl?biblionumber=9&itemnumber=24 ok off, without view_borrower_infos_from_any_libraries: the Midway patron is already refused: "This account cannot view requested patron information." seen: Circulation | Patrons | Search | More | kbvstaff Centerville | Search patrons | Search patrons | Check out | Check in | Renew | Search catalog | Home | Patro ok on: the staff login page has no "Library:" choice (everyone logs in at their own library) ok on, without view_borrower_infos_from_any_libraries: the Midway patron is refused: "This account cannot view requested patron information." seen: Circulation | Patrons | Search | More | kbvstaff Centerville | Search patrons | Search patrons | Check out | Check in | Renew | Search catalog | Home | Patro ok on: a Centerville patron still opens ok on, WITH the full Patrons permission (view_borrower_infos_from_any_libraries): the Midway patron still opens seen: Circulation | Patrons | Search | More | kbvstaff Centerville | Search patrons | Search patrons | Check out | Check in | Renew | Search catalog | Home | Patro ok on: but editing the Midway patron sends the staff member back to Patrons (members-home.pl) seen: http://localhost:8081/cgi-bin/koha/members/members-home.pl ok on: a Centerville patron still opens for editing seen: http://localhost:8081/cgi-bin/koha/members/memberentry.pl?op=edit_form&borrowernumber=3699 ok on: opening a Midway item for editing sends the staff member back to the record (catalogue/detail.pl) seen: http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=9 ok on: a Centerville item still opens for editing seen: http://localhost:8081/cgi-bin/koha/cataloguing/additem.pl?biblionumber=1&itemnumber=1 ok on: the shared record still lists the Midway copies in its holdings table (the catalogue is not split) seen: http://localhost:8081/cgi-bin/koha/catalogue/detail.pl?biblionumber=9 ok on: the Centerville staff member can still edit the bibliographic record that only Midway holds seen: http://localhost:8081/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=9 ok on: checking out a Midway copy at Centerville is refused: "This item belongs to Midway and cannot be checked out from this location." seen: Circulation | Patrons | Search | More | kbvstaff Centerville | Check out | Check out | Check in | Renew | Search catalog | Home | Circulation | Checkouts | Reset Test (KBRESET1) | Help | Edit | Add guarantee | Change password | Duplicate | Print | Search to hold | Add message | More | C ok …and nothing was checked out ok on, canreservefromotherbranches off: a Centerville patron cannot hold a Midway copy (cannotReserveFromOtherBranches) seen: cannotReserveFromOtherBranches ok on, canreservefromotherbranches on: the same hold is allowed seen: OK ok on: the OPAC still shows the Midway copies to everyone ok on, with the loggedinlibrary permission: after Set library → Midway, the same staff member edits Midway items seen: http://localhost:8081/cgi-bin/koha/cataloguing/additem.pl?biblionumber=9&itemnumber=24 ok …and edits Midway patrons too seen: http://localhost:8081/cgi-bin/koha/members/memberentry.pl?op=edit_form&borrowernumber=3719 ok the preference carries the warning "Changing this system preference will radically alter the behavior of Koha. Changing preference on a production system is highly discouraged." seen: 1 ok the labels read "Limit patron data access by group" and "Allow staff to change logged in library" seen: 2 1 ok koha-sites.conf sets each new instance's ports with OPACPORT and INTRAPORT seen: INTRAPORT="80" OPACPORT="80" ok the preference reads "Prevent staff (but not superlibrarians) from modifying objects (holds, items, patrons, etc.) belonging to other libraries" seen: 1 == The check that produced this log (scripts/kb/live/koha-independent-branches.mjs) == /** * Live check for prisma/ks-kb/101-koha-independent-branches.ts (plan48 OPAC customization cluster, child 4). On live * Koha it creates a staff account at Centerville (CPL) that is NOT a superlibrarian (circulate, catalogue, borrowers, * reserveforothers, editcatalogue), a patron at Midway (MPL), and compares what that staff member can do with * IndependentBranches off and on: open the Midway patron, edit a Midway item, edit the shared bibliographic record, * check out a Midway item, place a hold across libraries, choose a library at login, and the loggedinlibrary loophole. * Undone: both preferences, the staff account and the patron (deleted), the fixture patron's checkouts (none made). */ import { spawnSync } from 'node:child_process' export const meta = { koha: '26.05.02', passed: '2026-11-05' } const PW = 'Kbverify-Staff-2026' // circulate 2 + catalogue 4 + borrowers 16 + reserveforothers 64 + editcatalogue 512 (userflags bits 1, 2, 4, 6, 9) const FLAGS = 2 + 4 + 16 + 64 + 512 const LOGGEDINLIBRARY = 2 ** 29 export default async function run(ctx) { const perl = (code) => { const r = spawnSync('docker', ['exec', '-i', 'koha-koha-1', 'bash', '-c', 'cat > /tmp/kbv-ib.pl && koha-shell kohadev -c "perl /tmp/kbv-ib.pl" 2>&1; rm -f /tmp/kbv-ib.pl'], { input: code }) return String(r.stdout).trim() } // A Midway item that is free to lend (no loan, hold, loss or block), and its record. const [itemMpl, bibMpl, barcodeMpl] = ctx.sql("SELECT i.itemnumber, i.biblionumber, i.barcode FROM items i WHERE i.homebranch = 'MPL' AND i.holdingbranch = 'MPL' AND i.onloan IS NULL AND i.itemlost = 0 AND i.withdrawn = 0 AND i.notforloan = 0 AND i.damaged = 0 AND i.barcode IS NOT NULL AND NOT EXISTS (SELECT 1 FROM reserves r WHERE r.biblionumber = i.biblionumber) ORDER BY i.itemnumber LIMIT 1")[0] const [itemCpl, bibCpl] = ctx.sql("SELECT itemnumber, biblionumber FROM items WHERE homebranch = 'CPL' AND holdingbranch = 'CPL' AND itemlost = 0 AND withdrawn = 0 ORDER BY itemnumber LIMIT 1")[0] // The staff member and the Midway patron. ctx.restore('delete the Kbverify staff account and Midway patron', () => { perl("use Koha::Patrons; for my $c (qw(KBVSTAFF KBVMPL)) { my $p = Koha::Patrons->find({ cardnumber => $c }); $p->delete if $p }") }) const out = perl(`use Koha::Patron; use Koha::Patrons; for my $c (qw(KBVSTAFF KBVMPL)) { my $p = Koha::Patrons->find({ cardnumber => $c }); $p->delete if $p } my $s = Koha::Patron->new({ cardnumber => 'KBVSTAFF', surname => 'Kbverify', firstname => 'Staff', categorycode => 'S', branchcode => 'CPL', userid => 'kbvstaff', flags => ${FLAGS} })->store; $s->set_password({ password => '${PW}', skip_validation => 1 }); my $m = Koha::Patron->new({ cardnumber => 'KBVMPL', surname => 'Kbverify', firstname => 'Midway', categorycode => 'PT', branchcode => 'MPL' })->store; print $s->borrowernumber, ' ', $m->borrowernumber;`) const [staffBn, mplBn] = out.split(/\s+/).slice(-2) const cplPatron = ctx.patron() let page // a fresh page (own cookies) per login: the session keeps the library and the permissions it started with const login = async () => { page = await ctx.newPage(); await ctx.staffLogin(page, 'kbvstaff', PW) } const at = async (path) => { await page.goto(`${ctx.STAFF}/cgi-bin/koha/${path}`); await page.waitForLoadState('load'); return { url: page.url(), text: await ctx.pageText(page), html: await page.content() } } // Patron access: the full Patrons permission (flag bit 4) includes view_borrower_infos_from_any_libraries; the // limited set is list_borrowers + edit_borrowers only (user_permissions rows, flag bit 4 off). const perms = (full, extra = 0) => { ctx.sql(`DELETE FROM user_permissions WHERE borrowernumber = ${staffBn}`) ctx.sql(`UPDATE borrowers SET flags = ${(full ? FLAGS : FLAGS - 16) + extra} WHERE borrowernumber = ${staffBn}`) if (!full) ctx.sql(`INSERT INTO user_permissions (borrowernumber, module_bit, code) VALUES (${staffBn}, 4, 'list_borrowers'), (${staffBn}, 4, 'edit_borrowers')`) } const REFUSED = 'This account cannot view requested patron information.' // A. IndependentBranches off (the default): the Centerville staff member works across libraries. ctx.setPref('IndependentBranches', '0') const loginOff = ctx.sh(`curl -s '${ctx.STAFF}/cgi-bin/koha/mainpage.pl'`).out ctx.check('IndependentBranches off: the staff login page offers a "Library:" choice', loginOff.includes('id="set-library-branch"')) await login() let r = await at(`members/moremember.pl?borrowernumber=${mplBn}`) ctx.check('off: the Centerville staff member opens the Midway patron', r.text.includes('KBVMPL') && !r.text.includes('This account cannot view requested patron information.')) r = await at(`cataloguing/additem.pl?biblionumber=${bibMpl}&itemnumber=${itemMpl}`) ctx.check('off: the Centerville staff member can open a Midway item for editing', r.url.includes('cataloguing/additem.pl'), r.url) perms(false) await login() r = await at(`members/moremember.pl?borrowernumber=${mplBn}`) ctx.check(`off, without view_borrower_infos_from_any_libraries: the Midway patron is already refused: "${REFUSED}"`, r.text.includes(REFUSED), r.text.slice(0, 160)) // B. On. ctx.setPref('IndependentBranches', '1') const loginOn = ctx.sh(`curl -s '${ctx.STAFF}/cgi-bin/koha/mainpage.pl'`).out ctx.check('on: the staff login page has no "Library:" choice (everyone logs in at their own library)', !loginOn.includes('id="set-library-branch"') && loginOn.includes('login_userid')) await login() r = await at(`members/moremember.pl?borrowernumber=${mplBn}`) ctx.check(`on, without view_borrower_infos_from_any_libraries: the Midway patron is refused: "${REFUSED}"`, r.text.includes(REFUSED), r.text.slice(0, 160)) r = await at(`members/moremember.pl?borrowernumber=${cplPatron}`) ctx.check('on: a Centerville patron still opens', r.text.includes('KBRESET1')) perms(true) await login() r = await at(`members/moremember.pl?borrowernumber=${mplBn}`) ctx.check('on, WITH the full Patrons permission (view_borrower_infos_from_any_libraries): the Midway patron still opens', r.text.includes('KBVMPL') && !r.text.includes(REFUSED), r.text.slice(0, 160)) r = await at(`members/memberentry.pl?op=edit_form&borrowernumber=${mplBn}`) ctx.check('on: but editing the Midway patron sends the staff member back to Patrons (members-home.pl)', r.url.includes('members/members-home.pl'), r.url) r = await at(`members/memberentry.pl?op=edit_form&borrowernumber=${cplPatron}`) ctx.check('on: a Centerville patron still opens for editing', r.url.includes('members/memberentry.pl'), r.url) r = await at(`cataloguing/additem.pl?biblionumber=${bibMpl}&itemnumber=${itemMpl}`) ctx.check('on: opening a Midway item for editing sends the staff member back to the record (catalogue/detail.pl)', r.url.includes('catalogue/detail.pl'), r.url) r = await at(`cataloguing/additem.pl?biblionumber=${bibCpl}&itemnumber=${itemCpl}`) ctx.check('on: a Centerville item still opens for editing', r.url.includes('cataloguing/additem.pl'), r.url) await page.goto(`${ctx.STAFF}/cgi-bin/koha/catalogue/detail.pl?biblionumber=${bibMpl}`) const rows = await page.locator('table[id*=holdings] tbody tr, #holdings_table tbody tr').filter({ hasText: 'Midway' }).first().waitFor({ timeout: 20000 }).then(() => true, () => false) ctx.check('on: the shared record still lists the Midway copies in its holdings table (the catalogue is not split)', rows, page.url()) r = await at(`cataloguing/addbiblio.pl?biblionumber=${bibMpl}`) ctx.check('on: the Centerville staff member can still edit the bibliographic record that only Midway holds', r.url.includes('cataloguing/addbiblio.pl') && r.text.includes('Save'), r.url) await page.goto(`${ctx.STAFF}/cgi-bin/koha/circ/circulation.pl?borrowernumber=${cplPatron}`) await page.fill('#barcode', barcodeMpl) await page.press('#barcode', 'Enter') await page.waitForLoadState('load') const co = await ctx.pageText(page) ctx.check('on: checking out a Midway copy at Centerville is refused: "This item belongs to Midway and cannot be checked out from this location."', co.includes('This item belongs to Midway and cannot be checked out from this location.'), co.slice(0, 300)) ctx.check('…and nothing was checked out', ctx.sqlValue(`SELECT COUNT(*) FROM issues WHERE itemnumber = ${itemMpl}`) === '0') // C. Holds across libraries: canreservefromotherbranches. const hold = (allow) => { ctx.setPref('canreservefromotherbranches', allow) return perl(`use C4::Context; use C4::Reserves; use Koha::Patrons; use Koha::Items; C4::Context->set_userenv(${staffBn}, 'kbvstaff', 'KBVSTAFF', 'Staff', 'Kbverify', 'CPL', 'Centerville', ${FLAGS}); print C4::Reserves::CanItemBeReserved(Koha::Patrons->find(${cplPatron}), Koha::Items->find(${itemMpl}))->{status};`).split('\n').pop() } const h0 = hold('0') ctx.check('on, canreservefromotherbranches off: a Centerville patron cannot hold a Midway copy (cannotReserveFromOtherBranches)', h0 === 'cannotReserveFromOtherBranches', h0) const h1 = hold('1') ctx.check('on, canreservefromotherbranches on: the same hold is allowed', h1 === 'OK', h1) // D. The OPAC is not affected. const opac = ctx.sh(`curl -s '${ctx.OPAC}/cgi-bin/koha/opac-detail.pl?biblionumber=${bibMpl}'`).out ctx.check('on: the OPAC still shows the Midway copies to everyone', opac.includes('Midway')) // E. The loophole: the "loggedinlibrary" permission lets staff switch library, and then act as that library. perms(true, LOGGEDINLIBRARY) await login() await page.goto(`${ctx.STAFF}/cgi-bin/koha/circ/set-library.pl`) await page.selectOption('#set-library-branch', 'MPL') await page.click('input[type=submit][value=Submit]') await page.waitForLoadState('load') r = await at(`cataloguing/additem.pl?biblionumber=${bibMpl}&itemnumber=${itemMpl}`) ctx.check('on, with the loggedinlibrary permission: after Set library → Midway, the same staff member edits Midway items', r.url.includes('cataloguing/additem.pl'), r.url) r = await at(`members/memberentry.pl?op=edit_form&borrowernumber=${mplBn}`) ctx.check('…and edits Midway patrons too', r.url.includes('members/memberentry.pl'), r.url) // F. The preference text. const pref = ctx.sh("grep -c 'Prevent staff (but not superlibrarians) from modifying objects (holds, items, patrons, etc.) belonging to other libraries' /kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref").out.trim() const warnTxt = ctx.sh("grep -c 'Changing this system preference will radically alter the behavior of Koha. Changing preference on a production system is highly discouraged.' /kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref").out.trim() ctx.check('the preference carries the warning "Changing this system preference will radically alter the behavior of Koha. Changing preference on a production system is highly discouraged."', warnTxt === '1', warnTxt) const labels = ctx.sh("grep -c 'Limit patron data access by group' /kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt; grep -c 'Allow staff to change logged in library' /kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc").out.trim().split(/\s+/) ctx.check('the labels read "Limit patron data access by group" and "Allow staff to change logged in library"', labels.every((n) => Number(n) >= 1), labels.join(' ')) const ports = ctx.sh("grep -E '^(OPACPORT|INTRAPORT)=' /kohadevbox/koha/debian/templates/koha-sites.conf").out ctx.check('koha-sites.conf sets each new instance\'s ports with OPACPORT and INTRAPORT', ports.includes('OPACPORT=') && ports.includes('INTRAPORT='), ports) ctx.check('the preference reads "Prevent staff (but not superlibrarians) from modifying objects (holds, items, patrons, etc.) belonging to other libraries"', pref === '1', pref) }