TheRare Visuals

The booking that renamed its booker: shared bookings, and a fix that was right for the wrong person

Before building shared bookings we found that booking for someone else would have renamed your account and moved your login to their email. Fixing it without losing the original fix, then letting co-owners view and pay without touching fifty ownership checks.

TheRare Engineering23 October 202611 min readIntermediate

The feature request

Weddings are rarely booked by one person. A groom books, his fiancée wants to see the photos, and a parent is the one actually paying the balance. Until now a booking belonged to exactly one customer account, so everyone else had to borrow that person's login or wait for screenshots on WhatsApp.

We wanted two things:

  1. Booking for someone else. "I'm booking this for my sister" should be something the booking can say.
  2. Shared bookings. The person who booked should be able to add a few others who can follow the booking, see the photos and pay.

Before writing either, we read how a booking gets attached to an account today. That's where this post starts, because the first thing we found was a bug.

The bug nobody had reported yet

When staff confirm a booking, BookingConfirmationService links it to a customer account. It looks for a returning customer by phone first, then by email, and creates a new account only if neither matches (Part 12 covers what went wrong with the email half of that).

For a returning customer, it then did this:

Java
private void syncContactInfoFromBooking(Customer customer, Booking booking) {
    if (!booking.getClientEmail().equalsIgnoreCase(customer.getEmail())) {
        customer.setEmail(booking.getClientEmail());
    }
    if (!booking.getClientPhone().equals(customer.getPhone())) {
        customer.setPhone(booking.getClientPhone());
    }
    if (!booking.getClientName().equals(customer.getFullName())) {
        customer.setFullName(booking.getClientName());
    }
    // ...save
}

Every new booking overwrote the account's name, email and phone with whatever was typed on the booking.

Now imagine the feature we were about to build, done the obvious way. Ravi books a shoot for his sister. He types his own phone number, because he's the one the studio should call, and her name and email, because it's her shoot. Staff confirm it:

  1. The phone matches Ravi's account, so the booking is linked to Ravi. Correct.
  2. The account's name becomes "Divya". Ravi's dashboard now greets him by his sister's name.
  3. The account's email becomes Divya's. Ravi signs in with a password and a code we email him, and that code now goes to Divya's inbox, so Ravi is locked out of his own account. Divya, who has never had an account, can click "Forgot password", get the reset link in her inbox, and sign in to his.

Nobody had hit this yet, as far as we know. But "booking for someone else" was exactly the feature that would have made it common.

Why the code was written that way

This wasn't careless code. It was a fix, with a comment explaining it. Someone testing bookings had reported that emails kept going to their old address: they'd made a new booking with a new email, and the confirmation still went to the email from their very first booking. They had reused the same phone number, so the phone matched their existing account, and every email about the new booking went to the email on the account.

Copying the booking's details onto the account fixed that complaint. It was right for that case: the same person, with a newer email.

The mistake was an assumption hidden inside the fix: the person on the booking is always the person who owns the account. For a returning customer updating their details, that holds. For anyone booking on someone else's behalf, it's the opposite of true. The code couldn't tell those cases apart, so it treated every booking as a profile update.

There's a second problem even for the "same person" case. Changing a login email is a security action. Our normal email-change flow sends a code to the old address and another to the new one before anything changes. Typing an address on a booking form skipped both.

The fix: answer the original complaint without touching the account

The complaint was about where booking emails go, not about the account. So we fixed it there.

The account is never overwritten. A confirmed booking may fill in details the account doesn't have yet, such as an email on an account that only had a phone number. It never replaces one:

Java
String email = trimToNull(booking.getClientEmail());
if (email != null && trimToNull(customer.getEmail()) == null
        && customerRepository.findByEmail(email).isEmpty()) {
    customer.setEmail(email);
}

Email and phone are unique per account, so a missing one is only filled when no other account already uses it.

Booking emails go to the booking's email. Every email about a specific booking (confirmation, payment receipts, "your shoot is scheduled", "your photos are ready" and the rest) now goes to the address typed on that booking, falling back to the account's:

Java
private static String bookingRecipient(Customer customer, Booking booking) {
    String typed = booking != null ? booking.getClientEmail() : null;
    return typed != null && !typed.isBlank() ? typed.trim() : customer.getEmail();
}

Account emails stay with the account. Sign-in codes, password resets and the onboarding email with a temporary password still go to the account's own address. Those are the emails that control access, so they must never follow whatever someone typed on a form.

The original complaint stays fixed: a new email on a booking gets that booking's emails. The difference is that it no longer quietly becomes the login. A customer who wants a new login email changes it through the flow that checks both addresses.

We wrote the "booking for your sister" case as a test before anything else: after confirmation, the account still has Ravi's name, email and phone, and the booking is still linked to Ravi.

Booking for someone else

With the account safe, the first feature was small. Three nullable columns on bookings:

SQL
ALTER TABLE bookings
    ADD COLUMN booked_for_name  VARCHAR(255),
    ADD COLUMN booked_for_phone VARCHAR(50),
    ADD COLUMN booked_for_email VARCHAR(255);

The existing client_* columns stay the booker's: the person who has the account, gets the emails and pays. The booked_for_* columns only describe who the shoot is for. All three empty means "booking for myself", which is every booking made before this change.

The booking form, the dashboard's "book again" wizard and the admin's new-booking form each gained a "This booking is for someone else" checkbox. A name is required once it's ticked; their phone and email are optional. The customer's booking card reads "Wedding for Divya", and the admin booking list shows both names and can be searched by either.

Because confirmation only ever looks at the client_* fields, nothing here can reach the account. That separation is the whole point.

Shared bookings: who can do what

The second feature is the interesting one. Before designing a table, we answered a product question: what can a co-owner do?

We settled on view and pay. A co-owner can follow the booking's progress, see and download the delivered photos, see invoices and make payments. Everything else stays with the owner: messaging the studio, commenting on photos, asking for a refund, changing shoot locations, sharing the gallery with guests, choosing raw footage for editing, and adding or removing co-owners.

That one decision shaped the whole implementation.

Customer-side endpoints check ownership in around fifty places across 17 services, each a variation of:

Java
if (booking.getCustomer() == null
        || !booking.getCustomer().getId().equals(customer.getId())) {
    throw new AccessDeniedException("This booking does not belong to the current customer");
}

Refactoring all of them into one central check would have been a large, risky change. With "view and pay", we didn't have to. Co-owners only need the view and pay paths to let them in. Every owner-only action keeps its existing check, which already refuses anyone who isn't the owner, including co-owners, without those services knowing co-owners exist.

So one new class, BookingAccessService, answers one question:

Java
public Booking requireViewer(Customer customer, Booking booking) {
    if (isOwner(customer, booking) || isCoOwner(customer, booking)) {
        return booking;
    }
    throw new AccessDeniedException("This booking does not belong to the current customer");
}

and only the view and pay paths call it: the dashboard's booking list, a single booking, photo downloads and zips, media folders, invoices, the shoot concept, and online payment.

This also fails in the safe direction. If someone adds a new customer endpoint next month by copying an existing ownership check, it's owner-only. Opening it to co-owners has to be a deliberate change.

Where the owner lives

The new table holds co-owners, and only co-owners:

SQL
CREATE TABLE booking_co_owners (
    id          BIGSERIAL PRIMARY KEY,
    booking_id  BIGINT       NOT NULL REFERENCES bookings (id) ON DELETE CASCADE,
    email       VARCHAR(255) NOT NULL,
    customer_id BIGINT REFERENCES customers (id) ON DELETE CASCADE,
    created_at  TIMESTAMPTZ  NOT NULL DEFAULT now(),
    joined_at   TIMESTAMPTZ
);

CREATE UNIQUE INDEX uq_booking_co_owners_email
    ON booking_co_owners (booking_id, lower(email));

A cleaner-looking design puts everyone in one booking_members table with a role column: one row for the owner, one per co-owner. We deliberately didn't, because the owner already has a home: bookings.customer_id. The confirmation flow sets it. Moving a shoot's files between bookings (Part 11) reads it. All those owner checks compare against it. A second copy of "who owns this booking" in another table would be one more thing that can disagree with the first, and the first time a code path updated one and not the other, someone would see a booking they shouldn't.

So the owner stays where it was, and the new table only adds people.

The unique index on lower(email) is Part 12's lesson applied from day one: Divya@ and divya@ are the same person, so they can't be invited twice.

Invites that wait for a sign-in

The owner adds a co-owner by email. Two cases:

  • They already have an account with that email. The row is created with their customer_id set, and they see the booking straight away.
  • They don't. The row is created with customer_id empty. That's an invite. We email them once, saying who added them and how to sign in.

An invite becomes access the next time someone signs in with that email and opens their dashboard:

SQL
update booking_co_owners co
   set customer_id = :customerId, joined_at = now()
 where co.customer_id is null
   and lower(co.email) = lower(:email)
   and not exists (select 1 from bookings b
                    where b.id = co.booking_id and b.customer_id = :customerId)

The not exists skips bookings the person already owns; being a co-owner of your own booking means nothing.

Matching on email is only safe if every way into an account proves you control that email. For us it does: password sign-in sends a code to the account's email, and Google sign-in gives us an email Google has verified. Someone with no account at all signs in with Google, which creates one on the spot, the same way "Shared with me" gallery guests already join.

A small Spring detail: the dashboard load runs in a read-only transaction, and this is a write. Claiming invites therefore runs in its own transaction (Propagation.REQUIRES_NEW), which commits before the dashboard reads the bookings it just unlocked.

Files are checked through their booking

One check didn't fit the pattern. Photo downloads checked the file's own customer:

Java
if (!media.getCustomer().getId().equals(customer.getId())) { /* refuse */ }

A file has its own customer_id, set when it's uploaded or moved (Part 11), so a co-owner would see the gallery and then get "not yours" on every download. That check now goes through the file's booking instead: if you may view the booking, you may view its files. Locked files stay locked for everyone until the booking is paid; that rule didn't change.

The rules that keep it small

  • At most five co-owners per booking. A couple and their parents, with room to spare.
  • Not the owner's own email, and no duplicates, compared ignoring case.
  • Only confirmed bookings can be shared. Before confirmation there's no account for the booking to belong to.
  • A co-owner can leave, and only the owner (or the studio) can add or remove people.
  • Co-owners get one email, the invite. Everything else they see on their dashboard.

On the dashboard, a shared booking says "Ravi shared this booking with you" and shows progress, payments, invoices and the gallery. The owner-only sections aren't there, rather than being visible and failing, so a co-owner never sees a button that gives them an error. If Ravi's booking says it's for Divya and has her email, Ravi gets a one-tap "Give Divya access" button. We chose a button over inviting her automatically: sharing someone's booking should be their decision, not a side effect of filling in a form.

When a co-owner pays, the audit log says so: the payment is recorded against their name, marked "(co-owner)", not the owner's.

Raw footage is the one thing we hid from co-owners for now, even though it's "viewing". That section is built around the owner choosing files for editing and cutting clips. Opening half of it would have meant shipping a section where most buttons fail.

Takeaways

  • Read the code you're about to build on. The worst bug in this work was in a file we only opened to understand how bookings link to accounts.
  • A fix carries the assumptions of the case it was written for. Copying booking details onto the account was right for "same person, new email" and wrong for "booking for someone else". When a fix touches identity, write down who it assumes the person is.
  • Changing how someone signs in is a security action. It belongs behind the flow that verifies both addresses, not inside an unrelated form.
  • Send each email to the address that owns its subject. Booking emails go to the booking's email; access emails go to the account's.
  • Decide what a new role can do before designing the table. "View and pay" meant a handful of paths changed, not fifty checks.
  • Prefer access checks that fail closed. Every endpoint we didn't touch refuses co-owners by default.
  • Keep one source of truth for ownership. A members table with an owner row would have duplicated bookings.customer_id, and duplicates drift.
  • Matching invites by email is only as safe as your sign-in. It works here because every way in proves control of the email.

Found this useful?

Built something with what you learned here, or spotted a better way? Tell us. We work with freelance developers on Shootlo.