Skip to content

Customer portal access

The authenticated customer portal admits the caller through an exact live person/company relation, then builds a customer-safe projection with separate publication rules. Discovery and direct links now share the same SQL admission rule. A customer card discovered through one project does not grant the rest of that customer’s projects.

Contact, quote recipient, invoice recipient and deduction recipient remain independent roles. Creating a contact or selecting a deduction recipient creates no portal grant. Naming that contact on a project is a separate, project-only admission basis, selected as the product rule on 2026-11-17.

The API verifies the bearer token. private.customer_portal_people requires an active, non-deleted person and company and excludes workers. Staff can participate through their own customer relation; staff status alone grants no customer access. These exact person/company pairs feed private.customer_project_access, which admits a project through either:

  • Current customer access from v_contact_accessible_customers: an unrevoked explicit grant or the historical person-customer self relation in that company. This basis applies to that customer’s projects in the company.
  • Direct project contact: the person’s party matches the contact on that project in that company. This basis applies only to that project.

The bases are independent. Revoking a customer grant removes its wider access; a remaining direct project contact can still open that project. Replacing the project contact removes the direct basis while an independent customer grant may remain. Inactivating/deleting the person or company excludes both on the next request. Membership labels and deduction recipients do not create new access.

The service-only resolve_customer_project_access and list_customer_portal_customers RPCs expose complete JSON sets over private projections. Browser roles cannot call them. The project context and admitted person are read together; presentation contact lists cannot substitute another person’s private uploads. The internal active company does not choose a customer’s target company.

Legacy contact/customer-company RLS reads of complete projects rows are removed. Customer views use the safe API projection; owner-company staff and published worker RLS keep their separate scopes.

Surface Selection
/customer → /my-customers One company/customer pair from current customer access or an admitted direct-contact project. Company labels distinguish the same customer across contractors.
/customer/customers/:fkCustomerParty?tenant=... → /my-projects?tenant_id=...&customer_party_id=... The same admitted project set, restricted to the customer/company pair. An older company-less link works only when unambiguous.
/customer/projects/:pkProject → /projects/{pk}/detail require_customer_project returns the exact admitted project/person context; the response renders that person’s own uploads. No contact-list fallback establishes identity.
flowchart TD
  B[Verified account] --> S[Service-only access RPC]
  S --> P[Live non-worker person and company pair]
  P --> G{Customer access OR direct project contact?}
  G -->|No| D[Deny direct request or omit from discovery]
  G -->|Yes| C[Admitted project and exact person context]
  C --> L[Customer and project discovery]
  C --> V[Customer-safe published projection]
  C --> O[Additional operation rules]
Discovery and direct links share admission; publication and operation permissions remain separate.

Admission permits the API to assemble information. Each projection or action has its own conditions; there is no single publication flag for the entire portal.

Boundary Information or operation Additional conditions
Project admission Customer project Live non-worker company relation and customer access or direct project contact as above.
Planning Promised dates and scheduled passes Use the highest-version planning publication only when it is not withdrawn. No fallback to an older publication or internal project/phase dates.
Work information Work orders, daily logs and crew Work orders and daily logs require customer visibility. Crew uses the explicit, unrevoked name-snapshot projection. Phase labels/status may be returned without internal dates.
Project files Download links Match company and project, customer visibility, content_valid = true, non-deleted metadata and canonical object folder. Signing must succeed; internal storage paths are omitted. Links are signed for one hour; later grant revocation does not itself recall an issued link.
Presentation Customer editorial version Use a published customer-audience revision. Media file IDs must already be in the allowed file projection. Editorial title/description can change; canonical agreement and financial facts remain intact. Missing or invalid presentation content falls back to the safe live payload.
Messages Customer dialogue Use the project’s customer conversation and its attachment rules, rather than internal conversations. See conversation audiences.
Customer upload Photo or document submission Admission, supported MIME type/content signature and size limit. Saved as review_pending with customer visibility false; staff publication is separate. The selected contact can see metadata for their own uploads.
Completion acceptance Record customer acknowledgement Admission, nonblank signer and idempotency header, then the atomic acceptance RPC’s authorization and conflict checks. Detail access is insufficient to establish a successful acknowledgement.

Publication and record ownership owns the wider distinction between editorial content and commercial authority. Deduction proposals likewise remain distinct from staff approval; this article does not define the complete financial or action contracts.

The customer card shows active explicit grants. A parties:update editor can confirm Återkalla kundåtkomst, including when the contact has no deliverable email. Invitation still additionally requires quotes:send and an email.

DELETE /api/customer-portal/customers/{customer}/people/{person}/access uses the verified active company. Its service-only revoke_customer_portal_access RPC rechecks live capability and customer scope, and commits the grant change and verified actor audit event together. Retrying an already revoked grant preserves the original timestamp and audit. Project contacts and historical self access remain independent bases; the confirmation explains the project-contact boundary.

POST /api/customer-portal/ensure-person binds or creates people through a service-role-only RPC. The general path matches contact profiles to the verified user’s email; the project path uses ensure_portal_person_for_project to match the registered contact and company profile to the confirmed Auth email. It works without an accepted quote and creates no customer-wide grant. It refuses inactive, deleted or worker identities and cannot overwrite another account binding. The accepted-quote-only RPC has been removed.

The explicit customer-person invitation endpoint requires parties:update and quotes:send, an eligible customer membership and an unambiguous deliverable profile. After sending the access email it upserts a staff_invitation grant, including clearing prior revocation. These are separate steps; the route is not one atomic email-and-grant transaction. Accepted-quote/project triggers can create an accepted_quote grant for a matching named person contact. Their conflict handling preserves an existing revocation.

Project access-link and recovery emails use the current project contact’s company profile and do not upsert a wider grant. Customer-wide recipient edits retain their explicit-grant requirement; project-only contacts can edit the project dossier and ask staff to add a new shared recipient. Completion acceptance retains its additional non-staff signer rule.

A public quote URL uses its share token and quote-specific validity rules. It does not authorize an authenticated project request. Quote acceptance and subsequent grant/identity creation are separate from possession of that URL.

The resource contract names the current rule owners, admission bases, stronger operation permissions and maintained behavioral tests. PR #653 records local checks and their source versions; shared publication requires its own dated release evidence. The earlier source review in #648 identified the former list/detail mismatch and does not describe this replacement.