Issue 360 Links Opened Inside The Ticket - edmozley/freeitsm GitHub Wiki
🪆 #360 A linked record opened the whole of FreeITSM inside the ticket
GitHub #360, reported by pappas81 · Tickets, Tasks · since the task editor arrived in the workspace (PR #212), fixed in 5.4.1 (#2981)
What you saw
In workspace mode, a task linked to the ticket opens in place on the Work tab. Inside that task, its own links (to the ticket it belongs to, an asset, a project) are clickable. Clicking one did not open that record. Instead, the whole of FreeITSM loaded inside the ticket: the top bar, the module menu, the folder list, and another copy of the ticket, all in the space where the task had been. Its links did the same again, so it could go on nesting, a page inside a page inside a page.
As pappas81 put it, it was also unsafe: with a full copy of the app squeezed inside a ticket, it is easy to click something you did not mean to.
What was wrong
The task's editor in the Work tab is the real Tasks page, shown in a frame inside the ticket (tasks/embedded.php). Its links to other records are drawn by one function:
// assets/js/tasks.js
function linkedRecord(url, label) {
if (!url) return esc(label);
const base = window.APP_BASE || '';
return `<a class="linked-record" href="${escAttr(base + url)}">${esc(label)}</a>`;
}
On the task board that is right: the link takes you to the record. Inside a frame, a link with no target opens in the frame, so the record's full page, with all of FreeITSM around it, loaded inside the ticket. The developer guide already said the embedded editor must open other records in a new tab, but nothing made it so.
Was it more than one place? Yes: any link in the task panel that goes to another page, including the project link and links inside a form on the task. So the fix is not on each link, but on the frame as a whole.
The fix
1. Links open in a new browser tab. The embedded editor now watches clicks. A plain click on a link to another page opens it in a new tab and leaves the task where it is:
// assets/js/task-embed-bridge.js
function leaveInNewTab(event) {
if (event.defaultPrevented || event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
const link = event.target.closest?.('a[href]');
// ...left alone: target=_blank, downloads, #links, mailto:, tel:, links to this same page
event.preventDefault();
window.open(url.href, '_blank', 'noopener');
}
It is added to every document the editor draws in, including a form's own frame on the task, so a link added later is covered without anyone remembering to.
2. A safety net on the ticket. If anything else ever moves the frame to another page, the ticket notices when it loads and puts the task editor back. It does this once; if the frame lands somewhere else again straight away (for example, a signed-out session going to the sign-in page), the normal could not be loaded message shows instead of trying forever.
// assets/js/ticket-workspace.js
function frameLeftEditor(frame, context) {
// ...the frame is not on tasks/embedded.php: send it back, once
}
📁 Files
| File | Change |
|---|---|
🔵 assets/js/task-embed-bridge.js |
leaveInNewTab(), added to every watched document |
🔵 assets/js/ticket-workspace.js |
frameLeftEditor(), run on each load of the task frame |
⚪ tasks/index.php |
task-embed-bridge.js?v=3 |
⚪ tickets/index.php |
ticket-workspace.js?v=7 |
🟢 tests/task-embed-bridge.php |
Three checks: a linked record opens a new tab and the task stays; same-page and self-handled links are left alone; a frame sent elsewhere is put back |
How it was verified
tests/task-embed-bridge.php opens a task in a ticket's workspace in Chrome and clicks a linked record. All 14 checks pass. Control: the same test run against the code before the fix fails the three new checks, and the frame ends up on /tickets/index.php, which is the bug as reported. The real Tickets and Tasks pages were also loaded on a test install with no script errors.
What this means for you
Update to 5.4.1. Clicking a linked record inside a task on the Work tab then opens it in a new browser tab, and the task stays open in the ticket. Ctrl-click and middle-click still work as they always have.
Related: Ticket workspace · Tasks on tickets (developer guide) · #354 Workspace Links missed tasks