Tickets Module Access Analysts Developer Guide - edmozley/freeitsm GitHub Wiki
5.16.0, #497. The user's view: Tickets - ยง Analysts without Tickets access.
An analyst who cannot open the Tickets module - a manager given Forms only, so they can approve requests - used to appear in the Tickets inbox as an analyst folder and in every assign list, so a ticket could be given to someone who could never open it. Two endpoints now ask the one module-access question for each analyst, and the inbox acts on the answers: the assign lists leave such an analyst out, and the folder list drops them unless they still hold tickets, in which case the folder stays with a no Tickets access marker.
| File | What |
|---|---|
api/tickets/get_analysts.php |
With ?with_access=1, each analyst gets can_use_tickets
|
api/tickets/get_ticket_counts.php |
Drops the analyst folder of anyone without Tickets access, except the viewer and anyone holding tickets in scope; each folder gets no_tickets_access
|
assets/js/inbox.js (v230) |
assignableAnalysts() leaves out can_use_tickets === false, keeping keepId; renderFolders() draws the marker |
assets/css/inbox.css (v105) |
.folder-warn |
lang/en/tickets.php |
tickets.folders.no_access, tickets.folders.no_access_hint
|
tickets/index.php |
The two cache-busters |
tests/ticket-analyst-module-access.php |
New. 7 checks through the real endpoints |
No schema change.
Both endpoints call the same function every page gate (requireModuleAccess()) uses, in includes/functions.php:
function analystCanAccessModule(PDO $conn, int $analystId, string $moduleKey): bool {
if ($analystId <= 0) return false;
if ($moduleKey === 'system') return analystIsAdmin($conn, $analystId);
if (!moduleIsEnabled($conn, $moduleKey)) return false;
$allowed = getAnalystAllowedModules($conn, $analystId); // null = all modules
if ($allowed === null) return true;
return in_array($moduleKey, $allowed, true);
}So "can open Tickets" means exactly what it means at the door of tickets/: the module switched on for the install, and Tickets among the analyst's allowed modules - their own grants and their teams', combined by getAnalystAllowedModules() under the install's most / least policy. An administrator or an "all modules" analyst gets null there and passes.
-
TRAP: never a copy of that rule - not in SQL, not in JavaScript. The team union and the policy live in
getAnalystAllowedModules(); a second copy drifts. The comment inget_ticket_counts.phpsays the same. - It is one call per analyst. On an install with a few hundred analysts that is a few hundred small lookups per counts call - the same trade the multi-company check above it (
getAccessibleTenantIds()per analyst, #176) already makes.
The flag is only added when asked for:
if (!empty($_GET['with_access'])) {
// GH #497: and whether each can open Tickets at all, so the assign lists do not
// offer a manager given Forms only. analystCanAccessModule() is the one rule.
foreach ($analysts as &$analyst) {
$analyst['can_use_tickets'] = $analyst['is_active'] && analystCanAccessModule($conn, (int)$analyst['id'], 'tickets');
}
unset($analyst);
...?with_access=1 already existed for #176 (accessible_tenant_ids), and only the Tickets inbox sends it (loadAnalysts() in inbox.js). Other modules' pickers call get_analysts.php without it and get the list unchanged - a Forms-only manager must still be pickable as an approver in Forms. The test checks that too.
inbox.js keeps the whole list in analysts and filters only what is offered:
function assignableAnalysts(tickets, keepId) {
// GH #497: never offer someone who cannot open Tickets (a manager given Forms only,
// to approve) - a ticket given to them could not be worked. The server decides.
const canWork = analysts.filter(a => (keepId != null && a.id == keepId) || a.can_use_tickets !== false);
if (!analystsMultiCompany) return canWork;
const companies = [...new Set((tickets || []).map(ticketCompanyId).filter(id => id != null))];
return canWork.filter(a => (keepId != null && a.id == keepId)
|| !Array.isArray(a.accessible_tenant_ids)
|| companies.every(c => a.accessible_tenant_ids.includes(c)));
}It feeds the three assign lists in the inbox:
| Where | Call | keepId |
|---|---|---|
| The Owner dropdown in the reading pane | assignableAnalysts([email], email.owner_id) |
the ticket's owner |
| Right-click a ticket โ Assign to | assignableAnalysts(ctxRow ? [ctxRow] : [], currentOwnerId) |
the ticket's owner |
| The bulk Assignee menu | assignableAnalysts(selectedTickets) |
none |
-
Why
keepId: the Owner dropdown (#ownerSelect) is a<select>whose selected<option>is the current owner, after an empty first option. Leave the owner out and no option would match, so the ticket would look unassigned while it is not. Kept in, the current assignee stays visible and selected (and ticked in the right-click list), so the ticket reads truthfully and can then be moved. The bulk menu has no single owner, so it passes none. -
!== false, not=== true: a missing flag (the list loaded withoutwith_access) offers the analyst, as before 5.16.0, rather than emptying every list. -
TRAP: filter what is offered, never
analystsitself.getDisplayName('owner')reads that array; filtering it would blank the owner's name on every ticket held by someone without access (the same rule as #176, noted above the function).
After the counts are fetched (COUNT(t.id) per active analyst, within the viewer's department scope and ticket-type filters) and after the multi-company filter:
$noTicketsAccess = [];
foreach ($analystCounts as $row) {
$aid = (int)$row['id'];
if (!analystCanAccessModule($conn, $aid, 'tickets')) $noTicketsAccess[$aid] = true;
}
if ($noTicketsAccess) {
$analystCounts = array_values(array_filter($analystCounts, fn($r) =>
!isset($noTicketsAccess[(int)$r['id']]) || (int)$r['id'] === $analystId || (int)$r['count'] > 0));
$kept = array_flip(array_map(fn($r) => (int)$r['id'], $analystCounts));
$analystStatusCounts = array_values(array_filter($analystStatusCounts, fn($r) => isset($kept[(int)$r['analyst_id']])));
}and every folder row carries the answer:
'no_tickets_access' => isset($noTicketsAccess[(int)$aId]), // GH #497| Analyst | Folder |
|---|---|
| Can open Tickets | as before |
| Cannot, holds no tickets in scope | none |
| Cannot, holds tickets in scope | kept, marked no Tickets access |
| The viewer | always kept (the same exceptions as the #176 filter; the endpoint itself needs Tickets access, requireModuleAccessJson('tickets'), so in practice the viewer never lacks it) |
- Why a held ticket keeps its folder: those tickets exist and their owner's name is on them. Dropping the folder would hide them - the analyst folders would no longer add up to the tickets, and nobody would see that work is sitting with someone who cannot do it. Kept and marked, the gap is visible and the tickets can be dragged or reassigned to someone who can. Once the count reaches 0 the folder goes on the next refresh.
- The status sub-folders (
$analystStatusCounts) are filtered to the same set, so no orphaned children are drawn. - "In scope" is the viewer's: the count only includes tickets in departments this viewer can see. An analyst holding tickets only in departments the viewer cannot see has no folder for that viewer.
renderFolders() adds it beside the name:
${an.no_tickets_access ? `<span class="folder-warn" title="${escapeHtml(t('tickets.folders.no_access_hint'))}">${escapeHtml(t('tickets.folders.no_access'))}</span>` : ''}'no_access' => 'no Tickets access',
'no_access_hint' => 'This analyst cannot open the Tickets module, so the tickets here cannot be worked. Move them to someone who can, or give the analyst Tickets access.',.folder-warn { margin-left: 6px; padding: 0 6px; border-radius: 4px; font-size: var(--font-size-xs, 11px); background: var(--warning-bg); color: var(--warning-text); white-space: nowrap; }Theme tokens only (--warning-bg, --warning-text), so it follows light and dark themes. The hint is the title - hover text, which is where the "what do I do" lives.
-
It is not a permission. It changes what the inbox offers and lists. Nothing that saves an assignee checks the new assignee's module access - not the inbox's endpoints in
api/tickets/, notapi/v1/resources/tickets.php- so the REST API can still give such an analyst a ticket. That ticket then shows up in a marked folder, which is the point of keeping it. -
A kept folder is still a drop target. It is an ordinary analyst folder (
data-drop-type="analyst"), so dragging another ticket onto it assigns that ticket too. The marker is the warning. - Nobody's grants change. To clear the marker, move the tickets or give the analyst Tickets access under System โ Analysts.
tests/ticket-analyst-module-access.php - 7 checks, run against a test database only (FREEITSM_TEST_DATABASE=<test db> php tests/ticket-analyst-module-access.php; it refuses any other). It creates one zz497... analyst with can_access_all_modules = 0 and only forms in analyst_modules, and runs the real endpoints in-process with an administrator's session:
| Check | Through |
|---|---|
The Forms-only analyst has can_use_tickets === false
|
get_analysts.php?with_access=1 |
An administrator has can_use_tickets === true
|
same |
Without with_access: no flag, and nobody removed |
get_analysts.php |
| No folder for the Forms-only analyst | get_ticket_counts.php |
The viewer still has a folder, no_tickets_access === false
|
same |
| Given one ticket, the analyst keeps a folder with a count of at least 1 | same |
...marked no_tickets_access === true
|
same |
For the last two it borrows the newest ticket and puts its assignee back exactly as it was in finally, then deletes the ZZ analyst and their module row. TRAP (as in tests/ticket-team-folders.php): the script prints before the first call, so the endpoints' session_start() cannot replace the $_SESSION the test set.
- Tickets - the user's view
-
Module Access - Developer Guide -
getAnalystAllowedModules()and the most / least policy - All Companies ticket view - Developer Guide - the #176 filters this sits beside
- Inbox filter and My tickets - Developer Guide - the viewer's own folder