Sales never see purchase prices: RBAC and PostgreSQL row-level security in fordway
In a trading company, purchase prices and supplier identities are the crown jewels. A salesperson who knows the customer, the selling price, the purchase price and the supplier can cut the company out and do the deal directly. So for fordway, permissions are not about "can this person click this button"; they are about who can see each field, who can change it and whether it can be exported.
Data visibility by role
| Data | Owner | Sales | Customer service | Purchasing |
|---|---|---|---|---|
| Customers and orders | All | Own | All | Read only, no prices |
| Selling prices, sales, receivables | Yes | Own | Yes | No |
| Purchase prices, payables | Yes | No | No | Yes |
| Supplier identity (name, code, contacts) | Yes | No | Yes | Yes |
| Cost amounts (average cost, delivery cost, stock value) | Yes | No | No | No |
| Profit (gross profit, margin) | Yes | Own customers | No | No |
| Business dashboard | Yes | Own data | Yes | No |
| Other people's personal files | No | No | No | No |
Five roles come built in (owner, sales, customer service, purchasing / warehouse and administrator), a user can hold several roles, and the users and permissions page shows exactly which menus each role can see.
Three layers: page, API, database
- Pages: menus, buttons and whole columns you may not use are not shown, and pages you may not open are blocked at the router.
- APIs: a field you may not see is never returned, not returned as an empty value; exports leave the whole column out; and hidden price fields cannot be written either, so when purchasing edits an item, its selling and floor prices stay unchanged.
- Database: PostgreSQL row-level security (RLS) is the last line of defence. A salesperson opening a colleague's order link gets "record not found or access denied"; purchasing opening a sales order sees no prices or amounts at all.
Why do it again in the database? Because a business system keeps gaining endpoints: reports, exports, generic queries, mobile pages, the Mini Program. With application code alone, sooner or later a new endpoint leaks a field. Row-level security makes "which rows this person may see" a property of the database itself, which no query can bypass.
Row-level security that stays fast
RLS is often blamed for slow queries. fordway writes its policies as scalar subqueries so the planner can still use indexes, and report results are cached per visibility scope and parameters and invalidated as soon as any write commits. The owner and a salesperson looking at the same dashboard hit different cache entries, so data never crosses over.
Personal files are private, even from the owner
The file center has personal files, files shared with me, company files and a recycle bin. Personal files are protected by row-level security too, so not even the owner can see them. Sharing is granted per person, with separate download, print and expiry controls; previews carry a watermark, and every access is logged. URLs only contain file access tokens, never storage paths.
Deletion and audit trail
- Every deletion (customers, suppliers, items, part numbers, contacts, aliases, learned mappings and more) is a soft delete that stays traceable, and only owners and administrators may do it; other roles do not see the delete button, and calling the API directly is refused.
- Audit records are written in the same transaction as the business operation: if the operation succeeds, the log exists, and the log is append-only.
- Confirmed documents are never deleted, only changed (versioned), voided or reversed; stock has an append-only ledger; original documents are kept permanently, the database forbids deleting them, and tamper-protection triggers are verified at startup.
Mapped to MLPS 2.0 level 2
| Requirement | How fordway does it |
|---|---|
| Authentication | Passwords of 8 to 64 characters with at least two character types, no usernames or weak passwords, a 90-day lifetime and forced change on first sign-in and after resets; optional sign-in with mobile number and SMS code |
| Failed sign-ins | 5 failures lock the account for 10 minutes; 30 failures from one source within 10 minutes pause sign-in; the same message for unknown users and wrong passwords prevents enumeration |
| Sessions | Sign-out after 30 idle minutes; tokens expire after 12 hours with a reminder to save work first; password changes and sign-out revoke tokens immediately |
| Audit | Sign-ins, business operations and file access go to an append-only audit log with the real client IP |
| API protection | Limits on request bodies and uploads, rate limits on writes, CSP and other security headers, and no CORS headers in production |
In short
For a trading company, permission design decides whether its margins are safe. fordway writes "who can see what" into pages, APIs and the database, and all three follow the same rules. Learn more on the fordway product page or book a demo.