# Website Contact Messages

The public contact forms in all five website themes submit to one Laravel message pipeline. Messages are stored before any realtime broadcast is attempted, so a Pusher outage cannot discard an enquiry.

## Data captured

Each record stores the sender's full name, email, optional phone, subject, message text, selected theme, source page and URL, matched client, owning administrator, read status, reader, timestamps, IP address, user agent, and limited metadata.

The public endpoint is protected by Laravel CSRF validation, a six-requests-per-minute throttle, server-side field validation, and a hidden honeypot field.

## Client matching and administrator visibility

The sender email is normalized and matched case-insensitively against the `clients.email` field.

- Super administrators can see every contact message.
- A regular administrator can see messages whose matched client is assigned to that administrator or any administrator below them in the hierarchy.
- A regular administrator cannot see records belonging to an unrelated hierarchy branch.
- Messages whose email does not match a client are visible only to super administrators.
- Visibility is enforced in list queries, counters, direct record URLs, status changes, deletion, dashboard widgets, and realtime recipients.

`App\Services\ContactMessageVisibilityService` contains the shared visibility policy. User hierarchy traversal includes cycle protection to avoid malformed parent relationships causing an endless loop.

## Administrator module

The **Contact Messages** module includes:

- read and unread states;
- unread sidebar counter;
- unread-row highlighting;
- detailed message view;
- mark read, mark unread, and mark all visible messages read;
- filters for global search, full name, email, subject/message context, match status, read status, date range, and page size;
- matched client, owner administrator, reader, theme, source, and received-time information;
- permission-protected deletion.

Permissions are grouped under `Contact Messages`:

```text
contact_messages_access
contact_messages_view
contact_messages_edit
contact_messages_delete
```

The migration assigns these permissions to recognized super-administrator roles and the normal permissions seeder also includes them.

## Pusher realtime delivery

Each authorized administrator receives events only on their own private channel:

```text
private-admin.contact-messages.{admin_id}
```

The channel authorization callback requires the authenticated user's ID to match the channel ID. The event name is `ContactMessageReceived`.

When Pusher is configured, a new enquiry updates the dashboard panel and unread counter and shows a popup containing the sender, email, subject, message preview, and direct record link.

Configuration:

```dotenv
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=...
PUSHER_APP_KEY=...
PUSHER_APP_SECRET=...
PUSHER_APP_CLUSTER=mt1
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
```

The web installer accepts the Pusher values. It enables the Pusher broadcast driver only when the required credentials are complete; otherwise the safe default is the log broadcaster.
