Enforce roles on admin endpoints and return real status codes
- users, SMTP and batch-lock endpoints are owner/admin only - engines answer 400/403/404/409/500 instead of 200 with an error body; database errors no longer leak to the client
This commit is contained in:
@@ -25,6 +25,7 @@ if (preg_match('#^(\d{2})/(\d{2})/(\d{4})$#', $journal_date, $m)) {
|
||||
}
|
||||
|
||||
if (!$journal_date || !preg_match('/^\d{4}-\d{2}-\d{2}$/', $journal_date)) {
|
||||
http_response_code(400);
|
||||
$answer['message'] = 'Valid journal date is required.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
@@ -51,11 +52,13 @@ foreach ($lines_raw as $l) {
|
||||
}
|
||||
|
||||
if (count($lines) < 2) {
|
||||
http_response_code(400);
|
||||
$answer['message'] = 'At least two journal lines are required.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
|
||||
if (abs($total_debit - $total_credit) > 0.005) {
|
||||
http_response_code(400);
|
||||
$answer['message'] = 'Journal is not balanced. Debit ' . number_format($total_debit, 2) . ' ≠ Credit ' . number_format($total_credit, 2) . '.';
|
||||
exit(json_encode($answer));
|
||||
}
|
||||
@@ -83,9 +86,15 @@ try {
|
||||
$answer['success'] = 1;
|
||||
$answer['gl_id'] = $gl_id;
|
||||
notify_node('gl_posted', gl_posted_payload('manual', (int)$gl_id, $event_action, $lines), $company_id);
|
||||
} catch (PDOException $e) {
|
||||
if ($pdo2->inTransaction()) $pdo2->rollBack();
|
||||
error_log('[' . basename(__FILE__) . '] ' . $e->getMessage());
|
||||
$answer['message'] = 'Database error, please try again.';
|
||||
http_response_code(500);
|
||||
} catch (Exception $e) {
|
||||
if ($pdo2->inTransaction()) $pdo2->rollBack();
|
||||
$answer['message'] = $e->getMessage();
|
||||
http_response_code(400);
|
||||
}
|
||||
|
||||
exit(json_encode($answer));
|
||||
|
||||
Reference in New Issue
Block a user