feat(erp): erpsetup for live ERPNext, reserved tenant slugs
cmd/erpsetup applies what the registry expects in a live ERPNext: tenant_id/tenant_slug custom fields on Customer and Lead, the Usage Record doctype, and Frappe Webhooks (Sales Order submit, Sales Invoice overdue, Payment Entry submit, Subscription cancelled) signed with the registry's webhook secret. It checks before it creates, so it can run again at any time, and -dry-run only reports. It ships in the image as /erpsetup. Tenant creation refuses slugs the portal serves itself (admin, start, install, docs, …), mirroring the portal's signup check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit is contained in:
1 parent
13da983d1e
commit
bcb0895480
8 files changed
+587
-2
No files matched your search
@@ -17,6 +17,17 @@ import (
|
||||
// at the API boundary rather than waiting for the DB to do it.
|
||||
var slugRE = regexp.MustCompile(`^[a-z0-9][a-z0-9-]{1,38}[a-z0-9]$`)
|
||||
|
||||
// reservedSlugs are paths the portal or the platform serves itself
|
||||
// (app.breakpilot.com/<slug>): a tenant with one of these names would be
|
||||
// unreachable or would shadow a route. Mirrors the portal's src/lib/signup.ts,
|
||||
// except "demo", which the sales demo tenant itself uses.
|
||||
var reservedSlugs = map[string]bool{
|
||||
"admin": true, "api": true, "app": true, "auth": true, "billing": true,
|
||||
"docs": true, "help": true, "install": true, "login": true, "logout": true,
|
||||
"portal": true, "signin": true, "signout": true, "signup": true, "start": true,
|
||||
"static": true, "status": true, "support": true, "www": true, "breakpilot": true,
|
||||
}
|
||||
|
||||
type createTenantReq struct {
|
||||
Slug string `json:"slug"`
|
||||
Name string `json:"name"`
|
||||
@@ -46,6 +57,10 @@ func (s *Server) createTenant(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusBadRequest, "invalid_slug", "slug must match ^[a-z0-9][a-z0-9-]{1,38}[a-z0-9]$")
|
||||
return
|
||||
}
|
||||
if reservedSlugs[in.Slug] {
|
||||
writeError(w, http.StatusBadRequest, "reserved_slug", "this slug is reserved for a platform path")
|
||||
return
|
||||
}
|
||||
if in.Name == "" || len(in.Name) > 255 {
|
||||
writeError(w, http.StatusBadRequest, "invalid_name", "name must be 1..255 chars")
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ package server_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -46,6 +47,17 @@ func TestCreateTenant_invalidSlug(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateTenant_reservedSlug(t *testing.T) {
|
||||
eachStore(t, func(t *testing.T, h *testHarness) {
|
||||
resp, body := h.do("POST", "/v1/tenants", map[string]any{
|
||||
"slug": "admin", "name": "Shadow",
|
||||
})
|
||||
if resp.StatusCode != http.StatusBadRequest || !strings.Contains(string(body), "reserved_slug") {
|
||||
t.Fatalf("status = %d body = %s", resp.StatusCode, body)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateTenant_duplicateSlugConflict(t *testing.T) {
|
||||
eachStore(t, func(t *testing.T, h *testHarness) {
|
||||
// 'acme' is pre-seeded
|
||||
|
||||
Reference in new issue
Block a user