refactor: collapse CreateTicketRequest + RequireAdminUser + CurrentContact::tenant (PMS-479) #352
No reviewers
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
psa-systems/mokosh-server!352
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/PMS-479-refactor-boilerplate"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Three small but compounding boilerplate sinks fell out of the PMS-448..PMS-457 grind: every PR touching CreateTicketRequest hit a merge conflict against the same per-feature optional-field expansion; every admin-only handler spelled out a
RequireAuth(u): RequireAuth, _admin: RequireAdminpair; every portal handler spelled outcrate::modules::auth::TenantId::from_trusted(contact.tenant_id). None of these are hard to fix in isolation. Land them as one refactor PR so the boilerplate stops accumulating.What landed (no behavioural changes; the existing test suites for workflow_rules, email_intake, intake_token_admin, portal, portal_ticket_notes all pass verbatim):
CreateTicketRequestderivesDefault. Every internal struct-literal call site (rmm intake, email intake, seed/data, seed/qa, portal-ticket creation intickets::service) collapses the noisypriority_id: None, type_id: None, ...tail into..Default::default(). Adding a new optional field in a future PR no longer breaks these sites; they keep the new field at its default. The HTTP path still goes throughDeserialize + Validate, which enforces the non-empty title + present company_id at the boundary, so external requests cannot exploit the default.New
RequireAdminUser(pub CurrentUser)extractor inauth::middleware. The extractor delegates toRequireAdminso the role list stays a single source of truth, then unwraps the tuple to drop thePhantomDatatail consumers do not want. Every existingRequireAuth(u): RequireAuth, _admin: RequireAdminpair inemail_intake::routes(4 sites) andworkflows::routes(6 sites) collapses toRequireAdminUser(u): RequireAdminUser. Thetime_tracking::routesadmin sites useRequireTimeTracking + RequireAdmin(a different first half) and are deliberately left untouched - extending the pattern to module-gated admin extractors is its own scope.New
CurrentContact::tenant() -> TenantIdhelper that wraps the verified portal-JWTtenant_idclaim. The 8 verbosecrate::modules::auth::TenantId::from_trusted(contact.tenant_id)call sites inportal::routescollapse tocontact.tenant(). TheResolvedTenantTokenfrom email-intake already storestenant_id: TenantId(not a raw Uuid), so no helper is needed there.#PMS-479