Files
api/services/nginx/app/routes/potentialOrderMatchesRoute.php
T
Jeppe B ab6c3ba5b6 Fix route permission instance calls (#344)
## Root cause

`route_t::hasPermission()` and `requirePermission()` are instance
methods. Route code was invoking them with `self::`; the new XL Vask
hall-scope helper made that call from a genuinely static context,
causing PHP to throw:

`Non-static method routes\\xlvaskUsageLogsRoute::hasPermission() cannot
be called statically`

## Changes

- Invoke route permission methods through `$this` across all 273
executable legacy calls in 45 route classes.
- Make `xlvaskUsageLogsRoute::allowedHallIdsForUser()` an instance
helper and update all 13 callers.
- Preserve the existing all-scope and own-scope hall selection rules.
- Add a token-aware regression test that rejects executable
`self::hasPermission()` and `self::requirePermission()` calls, while
ignoring comments.
- Add focused XL Vask tests for global scanner hall scope and
group-limited own scope.
- Update affected route contract assertions to the instance-call form.

## Verification

- PHP lint: all 53 changed PHP files
- Focused PHPStan: changed XL Vask route and both new regression tests —
clean
- Focused regression slice: 58 passed, 748 assertions
- Full local unit suite: 1,300 passed, 9,442 assertions (1 unrelated
existing warning, 1 environment skip)
- Full local API suite: 285 passed, 11,704 assertions
- Exact-SHA GitHub Tests workflow: all 7 jobs passed (unit, API,
integration, legacy, edge gateway, and supporting checks)
- Independent exact-SHA QA gate: PASS, no findings
- Independent exact-SHA security gate: PASS, no findings
- Independent exact-SHA reviewer gate: PASS, no findings
- Remote comparison: exactly one commit ahead of
`40b104abed7723a7d1b7028190ecda0e7aeef829`; all 53 remote blob hashes
matched the reviewed worktree

## Delivery state

Draft only for human review. No merge or deployment is included. Qodana
is skipped while the PR remains draft and is therefore not represented
as a passed gate.
2026-08-04 16:04:41 +02:00

131 lines
6.7 KiB
PHP

<?php
namespace routes;
use classes\authentication;
use objects\logs_o;
use objects\xlvask_potential_order_matches_o;
use traits\route_t;
class potentialOrderMatchesRoute
{
use route_t;
public function run(): void
{
$this->get('/orders/sync/potential-matches', function () {
// Require the user to be logged in
global $response;
$this->requirePermission('list_potential_order_matches');
// Check if the user has permission to list all potential order matches
if ($this->hasPermission('list_all_potential_order_matches')) {
$this->requirePermission('list_all_potential_order_matches');
} else {
$this->requirePermission('list_own_potential_order_matches');
}
// Get the user object
$user = (new authentication())->get_user();
// Check if the request was successful
if ($user) {
// Log the incident
(new logs_o())->add('potential_order_matches', 'global', 1, $user->id, 'LIST_OWN_POTENTIAL_ORDER_MATCHES', 'User accessed the list of potential order matches');
$potentialOrderMatches = new \objects\xlvask_potential_order_matches_o();
// Return the list of potential order matches
$response->success(
$potentialOrderMatches
->setSearchableFields([
'id',
'wash_id',
'order_id',
'customer_id',
'customer_number',
'ignore_duplicate',
'department',
'created_at',
'updated_at',
'deleted_at',
])
->listObjectsWithPaginationIfSet(
function ($match) use ($potentialOrderMatches, $user) {
return [
'id' => (int)$match['id'],
'wash_id' => (string)$match['wash_id'],
'order_id' => (int)$match['order_id'],
'customer_id' => (string)$match['customer_id'],
'customer_number' => (int)$match['customer_number'],
'ignore_duplicate' => (int)$match['ignore_duplicate'],
'department' => (int)$match['department'],
'created_at' => (string)$match['created_at'],
'updated_at' => (string)$match['updated_at'],
'deleted_at' => $match['deleted_at'] ? (string)$match['deleted_at'] : null,
];
},
$potentialOrderMatches->forceRestrictFilters(
[
// This makes sure that the user can only see department matches that belong to their departments
'department' => $this->effectiveDepartmentIds($user)
]
)
)
);
} else {
// Log the incident
(new logs_o())->add('potential_order_matches', 'global', 1, 0, 'LIST_OWN_POTENTIAL_ORDER_MATCHES', 'No user found, or invalid session');
// Return an error
$response->error('Invalid session', 400);
}
},
[
'list_potential_order_matches' => 'List potential order matches, provided the user has either list_all_potential_order_matches, or list_own_potential_order_matches permission',
'list_own_potential_order_matches' => 'List all potential order matches for the logged in user',
'list_all_potential_order_matches' => 'List all potential order matches for all users (superuser only)',
]
);
$this->post('/orders/sync/potential-matches/ignore-duplicate', function () {
// Require the user to be logged in
global $response;
$this->requirePermission('ignore_duplicate_potential_order_matches');
// Get the user object
$user = (new authentication())->get_user();
// Check if the request was successful
if ($user) {
// Log the incident
(new logs_o())->add('potential_order_matches', 'global', 1, $user->id, 'IGNORE_DUPLICATE_POTENTIAL_ORDER_MATCHES', 'User ignored duplicate potential order matches');
// Get the potential order match data from the request
self::requireParameters(['id']);
self::requireType((int)self::getParameter('id'), self::type_int());
self::requireMinValue((int)self::getParameter('id'), 1); // Ensure the ID is a positive integer
$potentialOrderMatch = new xlvask_potential_order_matches_o();
$potentialOrderMatch->select((int)self::getParameter('id'));
if (!$potentialOrderMatch->exists()) {
// Log the incident
(new logs_o())->add('potential_order_matches', 'global', 1, $user->id, 'IGNORE_DUPLICATE_POTENTIAL_ORDER_MATCHES', 'Potential order match not found');
// Return an error response
$response->error('Potential order match not found', 404);
}
// Check if the user has permission to ignore duplicate potential order matches in the department of the potential order match
self::requireDepartmentAccess((int)$potentialOrderMatch->department->value());
// Set the ignore_duplicate field to 1
$potentialOrderMatch->ignore_duplicate->set(1);
// Save the potential order match
$potentialOrderMatch->objectChanged();
// Return a success response
$response->success(
$potentialOrderMatch->asArray(),
200,
);
} else {
// Log the incident
(new logs_o())->add('potential_order_matches', 'global', 1, 0, 'IGNORE_DUPLICATE_POTENTIAL_ORDER_MATCHES', 'No user found, or invalid session');
// Return an error response
$response->error('Invalid session', 400);
}
},
[
'ignore_duplicate_potential_order_matches' => 'Ignore duplicate potential order matches for a specific wash and order',
]
);
}
}