- Private CRM: an AI CRM where Claude does the data entry and you make the calls · part 9 of 12
- Rust
- CRM
Push notifications, task reminders and quiet deals in a Rust PWA
Private CRM installs as an app and sends web push from Rust. Here is the push host allowlist, reminders that fire once, and a nightly check for quiet deals.
5 min read
A CRM nobody opens is a database. So on day one, Private CRM got a notification bell, became installable, and started sending web push from Rust. It also picked up a security fix the same hour: the first version would have posted to any URL a browser gave it.
This post covers the push setup, the allowlist, reminders that fire exactly once, quiet-deal alerts, and the timezone fixes that followed.
The bell, the manifest and the service worker
The header got a bell showing the last 8 notifications with an unread count. It polls every 30 seconds and toasts new ones. Opening one marks it read and goes to its record.
The app got a manifest, icons and a service worker, so it can be installed (Add to Home Screen) and receive push alerts. A SendWebPush job encrypts and signs each message with the web-push-native crate, and drops subscriptions the push service says it no longer knows.
Push needs a VAPID key pair. A console command makes one:
laravel push:keys
It prints two lines to paste into .env. On iPhone, push only works once the app is on the Home Screen, so the README says that up front. If you're weighing whether an installable web app is enough, I compared the options in PWAs vs native apps.
The allowlist commit
Web push works like this: the browser gives your server an endpoint URL, and your server POSTs to it later. Nothing stops a crafted request from subscribing with http://10.0.0.5/admin as the endpoint. Then your server sends a request to an internal address on someone else's behalf. That's server-side request forgery.
The fix only allows the hosts browsers actually use:
const PUSH_HOSTS: [&str; 5] = [
"fcm.googleapis.com",
"updates.push.services.mozilla.com",
"web.push.apple.com",
".push.apple.com",
".notify.windows.com",
];
pub fn is_push_service(endpoint: &str) -> bool {
let Ok(uri) = endpoint.parse::<http::Uri>() else { return false };
let Some(host) = uri.host().map(|host| host.trim_end_matches('.').to_ascii_lowercase()) else {
return false;
};
uri.scheme_str() == Some("https")
&& uri.port().is_none()
&& PUSH_HOSTS.iter().any(|allowed| {
if allowed.starts_with('.') { host.ends_with(allowed) } else { host == *allowed }
})
}
Note the details: https only, no custom port, a trailing dot stripped, case folded, and suffix matching only for entries that start with a dot. The check runs twice, when subscribing and again before sending, so a row that got in some other way is still dropped.
Reminders that fire once
A task can have a reminder time. The browser picks it in local time and the server stores UTC. The scheduler runs Task::send_due_reminders every minute.
The risk with "every minute" jobs is two runs overlapping, or two scheduler processes, and a reminder going out twice. The fix is to claim the row first:
for task in due {
// Claim the reminder first, so two schedulers running at once can't both send it.
let claimed = Task::query()
.filter(Task::id.eq(task.id) & Task::reminded_at.is_null())
.update()
.reminded_at(laravel::now())
.await?;
if claimed == 0 {
continue;
}
// ...send the notification
}
The update only matches while reminded_at is still null, so exactly one run wins. Completed tasks are skipped. The MCP create_task tool takes remind_at too, and npm run dev now starts the scheduler so reminders work locally.
Deals that have gone quiet
Deals keep a last_activity_at, backfilled from the activity log and moved forward by a listener whenever an activity is logged. Each user sets how many days count as quiet (14 by default). Pipeline cards and the deal page mark quiet deals, and a nightly sweep notifies the deal's owner once per quiet stretch. Logging anything on the deal starts a new stretch.
The schedule lives in one place:
schedule.call(Task::send_due_reminders).every_minute();
// 05:00 UTC is 08:00 in Kuwait, which has no daylight saving.
schedule.call(Opportunity::notify_stale).daily_at("05:00");
schedule.call(Invoice::mark_overdue).daily_at("05:00");
That comment is the whole timezone strategy for scheduled jobs, and it only works because Kuwait doesn't change clocks.
When AI agents started syncing email (part 6), a new rule protected this: a back-dated activity never moves last_activity_at backwards. Otherwise importing an old thread would make an active deal look quiet.
Timezones for people
Scheduled jobs can live in UTC. People can't. A later commit gave each user a timezone, taken from the browser the first time they sign in and changeable on the profile. Settings holds a company default for anyone who hasn't picked one, and every page shows dates and times in the reader's zone.
That still left one bug, found in the code review (part 12). "Today" was the UTC date. Early in the morning in Kuwait, UTC is still on yesterday, so tasks due today were missing from the Today page. Now "today" comes from the user:
/// Today's date where the user is: their own timezone, else the company's. Due dates are local dates.
pub async fn today(&self) -> laravel::Result<laravel::time::civil::Date> {
let zone = match &self.timezone {
Some(zone) => zone.clone(),
None => Setting::current().await?.timezone,
};
Ok(laravel::now().in_tz(&zone)?.date())
}
Today, Tasks, the deal and contact pages, the pipeline and the dashboard's overdue list all use it.
Before you ship push
Allowlist push hosts on day one, not after someone reads your subscribe endpoint. Claim scheduled work with a conditional update before doing it. And treat "today" as a property of a person, not of the server. Running these jobs needs a worker and a scheduler next to the web process, which is exactly how the Docker setup in part 11 is laid out.
Part 10 is the UI pass: shadcn, a new preset, bigger text and a phone audit at 390px.
Last updated 4 Dec 2026 · filed under Rust, crm