Which customers can a sales rep see?
Sofia and Lee sit on the same sales team. Sofia should see the customers she owns. Their manager needs both books of business to cover holidays. A manager on another team should see neither. All three people can legitimately sign in to the same application. A successful login tells you very little about whose customers belong in the list.
Start with three customer records
Give Sofia a record called Juniper Bikes, give Lee another called Cedar Parts, and assign Orchard Supply to a different team. Before writing any code, agree with the sales lead on what Sofia and her manager should see. For this example, editing follows the same ownership rule as viewing.
| Test customer | Sofia | Sofia’s manager |
|---|---|---|
| Juniper Bikes · owned by Sofia | View and edit | View and edit |
| Cedar Parts · owned by Lee | No access | View and edit |
| Orchard Supply · another team | No access | No access |
Scope the list, then check the individual action
SeviaFlow’s panel gate controls admission to the operator UI. Inside the panel, CustomerResource::query(Builder $query) is where you can limit the rows that search, filters and pagination work with. Scope the query to the signed-in operator’s team. For a rep, add an owner_id condition. A manager with the application’s manage-team-customers ability can keep the team-wide query. Have the scope return no rows when the operator has no team.
When Sofia submits an edit, a Laravel policy decides whether she may update that particular customer. For an app with integer IDs, team_id on users and customers, and owner_id on customers, the rule can read like the table above. The application defines the manage-team-customers ability for its sales managers.
public function update(User $user, Customer $customer): bool
{
if ($user->team_id === null || $user->team_id !== $customer->team_id) {
return false;
}
return $customer->owner_id === $user->getKey()
|| $user->can('manage-team-customers');
}
Use the same ownership decision for view in this example and grant viewAny to the roles allowed to list customers. The UI panel gate applies to the operator UI. If you enable the customer REST API, configure its own authentication middleware. Its resource operations also go through Core authorization. Configure access and row scoping
Test the handover
Sign in to the local panel as Sofia and search for each company. Repeat with her manager. For every allowed edit, save a different test value and verify which record changed. For a denied action, assert in an application test that the stored customer stays untouched. Transfer Juniper Bikes to Lee and run the checks again. The customer should leave Sofia’s list while remaining visible to her manager. That final transfer is the case a test with just one user and one customer would miss.