You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refactor Sales reports authorization into a reusable CodeIgniter filter #4655
The Sales controller repeats the reports_sales grant check in several per-record endpoints. The repeated controller logic uses different denial response types for browser routes and JSON routes.
Problem
app/Controllers/Sales.php contains duplicated authorization checks for Sales report actions, including receipt, invoice, edit, save, row, and email endpoints. This duplicates grant-check logic and makes response behavior harder to keep consistent as routes change.
Proposed resolution
Create a reusable CodeIgniter 4 before authorization filter that accepts a required grant as an argument.
Apply the filter to the applicable Sales routes that require reports_sales.
Keep authorization checks in controller methods when the decision depends on request or resource state. In particular, keep the sales_change_price check in Sales::postEditItem() because it depends on whether the submitted price differs from the current cart price.
Configure predictable denial responses by route type:
Return a redirect to no_access/sales/reports_sales for browser page routes.
Return an HTTP 403 JSON response for JSON/AJAX routes.
Affected areas
app/Filters/
app/Config/Filters.php
app/Config/Routes.php
app/Controllers/Sales.php
Relevant controller or route tests
Acceptance criteria
A reusable parameterized authorization before filter checks the current employee grant.
Applicable Sales routes use the filter for the reports_sales grant.
Unauthorized browser routes redirect to the existing access-denied page.
Unauthorized JSON/AJAX routes return HTTP 403 with the expected JSON error shape.
Sales::postEditItem() retains its state-dependent sales_change_price validation.
Tests cover authorized and unauthorized behavior for both browser and JSON route types.
The refactor does not change access rules for other Sales routes.
app/Filters/ only contains Throttle.php and IsLoggedIn.php — no reusable grant/authorization filter exists. app/Controllers/Sales.php still repeats the inline check
if (!$this->employee->has_grant('reports_sales', $personId)) { ... }
individually in getManage(), getRow(), getSearch(), getSendPdf(), getSendReceipt(), postUnsuspend(), getEdit(), getReceipt(), and getInvoice(), with some returning a redirect() and others a 403 JSON response as described, but with no shared filter consolidating the logic. This refactor has not landed on master.
Activity
jekkos commentedon Aug 23, 2026
Sounds great that was what I was hinting at. Usually autjorization is a xross cutting concern and ideally its more config than code.
objecttothis commentedon Oct 22, 2026
Claude Issue Checker Agent (cc @objecttothis)
Investigated against current
master.Status: Still present (refactor not done).
app/Filters/only containsThrottle.phpandIsLoggedIn.php— no reusable grant/authorization filter exists.app/Controllers/Sales.phpstill repeats the inline checkindividually in
getManage(),getRow(),getSearch(),getSendPdf(),getSendReceipt(),postUnsuspend(),getEdit(),getReceipt(), andgetInvoice(), with some returning aredirect()and others a 403 JSON response as described, but with no shared filter consolidating the logic. This refactor has not landed onmaster.