Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.
Go email-relayemail-routinghttp-to-smtpmail-deliverymailchimp-alternativemailgun-alternativemailsendermailservermailtemplatemailtestpostmark-alternativesend-emailsendgrid-alternativesendmailtransactional-emailtransactional-outbox
feat: create resources from one name, and keep names fixed
Jonas Kaninda0bb7395f4d11
diff --git a/docs/docs/admin/oauth-providers.md b/docs/docs/admin/oauth-providers.mdindex e00f93e..062b1e0 100644--- a/docs/docs/admin/oauth-providers.md+++ b/docs/docs/admin/oauth-providers.md@@ -36,8 +36,7 @@ POST /api/v1/admin/oauth/providers```json{- "name": "google",- "display_name": "Google",+ "name": "Google","type": "google","client_id": "your-google-client-id","client_secret": "your-google-client-secret",@@ -50,8 +49,7 @@ POST /api/v1/admin/oauth/providers```json{- "name": "keycloak",- "display_name": "Keycloak",+ "name": "Keycloak","type": "oidc","client_id": "posta","client_secret": "your-client-secret",@@ -68,8 +66,7 @@ POST /api/v1/admin/oauth/providers| Field | Required | Default | Description ||-------|----------|---------|-------------|-| `name` | No | from `display_name` | Identifier in the sign-in URLs (`/auth/oauth/{name}/authorize`): lowercase letters, digits and hyphens, unique. Cannot change later. |-| `display_name` | No | `name` | Shown on the sign-in button. One of `name` and `display_name` is required. |+| `name` | Yes | — | The provider's name, as shown on the sign-in button. Its identifier in the sign-in URLs (`/auth/oauth/{name}/authorize`) is derived from it: `Google` becomes `google`. Unique, and cannot change later. || `type` | Yes | — | `google` or `oidc` || `client_id` | Yes | — | OAuth client ID || `client_secret` | Yes | — | OAuth client secret |diff --git a/docs/docs/messages/creating-a-form.md b/docs/docs/messages/creating-a-form.mdindex 24d09a8..bded2f4 100644--- a/docs/docs/messages/creating-a-form.md+++ b/docs/docs/messages/creating-a-form.md@@ -14,8 +14,7 @@ curl -X POST https://posta.example.com/api/v1/workspaces/current/forms \-H "X-Posta-Workspace-Id: 1" \-H "Content-Type: application/json" \-d '{- "name": "contact",- "display_name": "Contact form",+ "name": "Contact form","allowed_origins": ["https://example.com", "https://www.example.com"],"notify_emails": ["[email protected]"],"reply_from": "[email protected]"@@ -24,7 +23,7 @@ curl -X POST https://posta.example.com/api/v1/workspaces/current/forms \The response includes `public_key` — the unguessable 22-character string that appears in your embed URL.-`name` identifies the form in the API: lowercase letters, digits and hyphens, unique in the workspace. `display_name` is its label. Send either; the other is derived. Before 0.18 these were `slug` and `name`; requests in the old shape are still read the old way until 0.19.+Give the form a `name` as you would write it. Posta keeps it as the form's `display_name` and derives its identifier from it: `Contact form` is saved as `contact-form`, unique in the workspace, and the response carries both. A name cannot change once the form exists; to use another, create a new form. Before 0.18 the identifier was `slug`; requests in the old shape are still read until 0.19.## Example formsdiff --git a/docs/docs/templates/creating-templates.md b/docs/docs/templates/creating-templates.mdindex de9c422..07393be 100644--- a/docs/docs/templates/creating-templates.md+++ b/docs/docs/templates/creating-templates.md@@ -13,7 +13,7 @@ A template has two names:- **`name`**: its identifier, like `welcome-email`. It is what you send as `template` and is unique in the workspace: up to 63 lowercase letters, digits and hyphens.- **`display_name`**: its label in the dashboard, like `Welcome Email`.-When you create a template you can send either. A missing `name` is derived from the display name, and a missing display name is the name.+Create a template with its `name` as you would write it, `Welcome Email`: Posta keeps it as the `display_name` and derives the identifier, `welcome-email`. A name cannot change once the template exists, because callers send it; to use another, create a new template.:::caution Changed in 0.18Before 0.18 a template had only `name`, which was both its label and what you sent. Upgrading keeps every label as the `display_name` and gives each template a `name` derived from it: `Welcome Email` becomes `welcome-email`. Sending by the old label still works until 0.19 and logs a deprecation warning; switch to the new names. Stylesheets, forms, workspaces and OAuth providers follow the same scheme.@@ -33,8 +33,7 @@ curl -X POST http://localhost:9000/api/v1/workspaces/current/templates \-H "X-Posta-Workspace-Id: 1" \-H "Content-Type: application/json" \-d '{- "name": "welcome",- "display_name": "Welcome",+ "name": "Welcome","description": "Welcome email for new users","html": "<h1>Welcome, {{name}}!</h1><p>Thanks for joining.</p>","text": "Welcome, {{name}}! Thanks for joining.",@@ -78,13 +77,12 @@ PUT /api/v1/workspaces/current/templates/{id}```json{- "display_name": "Welcome (v2)","description": "Updated welcome email","default_language": "en"}```-Changing `name` renames the template for sending: callers that send the old name stop finding it.+Sending a different `name` answers `400`: a template's name cannot change.## Delete a Templatediff --git a/docs/docs/templates/import-export.md b/docs/docs/templates/import-export.mdindex c2a3932..834dcb9 100644--- a/docs/docs/templates/import-export.md+++ b/docs/docs/templates/import-export.md@@ -71,9 +71,8 @@ Every other form field is optional and overrides a default:| Field | Default ||-------|---------|-| `name` | Derived from `display_name` |-| `display_name` | The filename without its extension |-| `subject` | The document's `<title>`, or else the display name |+| `name` | The filename without its extension. The identifier is derived from it |+| `subject` | The document's `<title>`, or else the name || `language` | The workspace's default language || `description` | `Imported from <filename>` |@@ -82,6 +81,6 @@ curl -X POST http://localhost:9000/api/v1/workspaces/current/templates/import-ht-H "Authorization: Bearer <jwt-token>" \-H "X-Posta-Workspace-Id: 1" \-F [email protected] \- -F display_name="Spring sale" \+ -F name="Spring sale" \-F subject="20% off this week"```diff --git a/docs/docs/templates/stylesheets.md b/docs/docs/templates/stylesheets.mdindex 7aeb81e..6f73b62 100644--- a/docs/docs/templates/stylesheets.md+++ b/docs/docs/templates/stylesheets.md@@ -20,13 +20,12 @@ POST /api/v1/workspaces/current/stylesheets```json{- "name": "brand-styles",- "display_name": "Brand styles",+ "name": "Brand styles","css": "h1 { color: #333; font-family: Arial, sans-serif; } .btn { background-color: #7c3aed; color: white; padding: 12px 24px; border-radius: 6px; text-decoration: none; }"}```-`name` is the stylesheet's identifier (lowercase letters, digits and hyphens, unique in the workspace); imported HTML templates link stylesheets by it. `display_name` is its label. Send either; the other is derived.+Give the stylesheet a `name` as you would write it. Posta keeps it as the `display_name` and derives the identifier from it, unique in the workspace: `Brand styles` is saved as `brand-styles`, and imported HTML templates link stylesheets by it. A name cannot change once the stylesheet exists.## List Stylesheetsdiff --git a/docs/docs/workspaces/overview.md b/docs/docs/workspaces/overview.mdindex 1705f41..dbb9602 100644--- a/docs/docs/workspaces/overview.md+++ b/docs/docs/workspaces/overview.md@@ -12,9 +12,9 @@ Workspaces provide multi-tenant isolation within Posta. Every resource — templ### Personal space-A workspace is provisioned for you when you sign up, named after you and owned by you. It is an ordinary workspace in every respect: rename it, invite people to it, or delete it once you have another. There is no separate "personal" workspace type.+A workspace is provisioned for you when you sign up, named after you and owned by you. It is an ordinary workspace in every respect: invite people to it, or delete it once you have another. There is no separate "personal" workspace type.-One workspace is special. The **system workspace** is created on first boot, owned by the first administrator, and holds platform-managed resources. It is flagged `system: true`, admits only platform administrators, and cannot be renamed or deleted.+One workspace is special. The **system workspace** is created on first boot, owned by the first administrator, and holds platform-managed resources. It is flagged `system: true`, admits only platform administrators, and cannot be deleted.### The system workspace@@ -147,15 +147,14 @@ Request body:```json{- "name": "acme",- "display_name": "Acme Inc",+ "name": "Acme Inc","description": "Marketing and transactional mail","default_language": "en","seed_defaults": true}```-Send `name`, `display_name` or both. A missing `name` is derived from the display name, and a missing display name is the name. A name is up to 63 lowercase letters, digits and hyphens, unique on the platform, and cannot change after creation; `display_name` can. `default_language` defaults to `en`. The caller becomes the workspace **owner**.+Give the workspace a `name` as you would write it. Posta keeps it as the `display_name` and derives the identifier from it: `Acme Inc` is saved as `acme-inc`, up to 63 lowercase letters, digits and hyphens, unique on the platform. A name cannot change after creation; to use another, create a new workspace. `default_language` defaults to `en`. The caller becomes the workspace **owner**.`seed_defaults` controls whether the new workspace starts with content: a welcome template in English, French and German, a default stylesheet, and the matching languages. It defaults to `true`, so omitting it gives you a workspace you can send from immediately. Send `false` when you intend to populate the workspace from an [export](../gdpr/data-export-import.md) or the API and do not want the starter template in the way.@@ -165,7 +164,7 @@ Seeding is best effort and runs after the workspace exists, so a workspace is necurl -X POST http://localhost:9000/api/v1/workspaces \-H "Authorization: Bearer <jwt>" \-H "Content-Type: application/json" \- -d '{"name": "acme", "display_name": "Acme Inc"}'+ -d '{"name": "Acme Inc"}'```Response (`201`):@@ -174,7 +173,7 @@ Response (`201`):{"data": {"id": 1,- "name": "acme",+ "name": "acme-inc","display_name": "Acme Inc","description": "","owner_id": 42,@@ -217,7 +216,7 @@ DELETE /api/v1/workspaces/currentTwo workspaces refuse deletion:-- The **system workspace** returns `409`. It is the built-in platform workspace, created on first boot, owned by the first administrator, and holds platform-managed resources. It cannot be renamed either, and only platform administrators are members.+- The **system workspace** returns `409`. It is the built-in platform workspace, created on first boot, owned by the first administrator, and holds platform-managed resources. Only platform administrators are members.- Your **last remaining workspace** returns `400`. Everything in Posta belongs to a workspace, so deleting the only one you belong to would leave you with nowhere to work. Create another first.```bashdiff --git a/internal/handlers/form_handler.go b/internal/handlers/form_handler.goindex 8a9663d..7533d69 100644--- a/internal/handlers/form_handler.go+++ b/internal/handlers/form_handler.go@@ -95,7 +95,7 @@ func NewFormHandler(type CreateFormRequest struct {Body struct {- Name string `json:"name" doc:"Identifier, like contact-form: lowercase letters, digits and hyphens. Derived from display_name when empty."`+ Name string `json:"name" doc:"The form's name, as typed: \"Contact form\" is stored as the identifier contact-form, with \"Contact form\" as display_name. It cannot change later."`DisplayName string `json:"display_name" doc:"The form's label. Defaults to name."`Slug string `json:"slug,omitempty" doc:"Deprecated: the identifier before 0.18, now name."`Description string `json:"description"`@@ -127,7 +127,7 @@ type CreateFormRequest struct {type UpdateFormRequest struct {ID int `param:"id"`Body struct {- Name string `json:"name" doc:"Identifier, like contact-form"`+ Name string `json:"name" doc:"A form's name cannot change; only accepted when it is the current one."`DisplayName string `json:"display_name"`Slug string `json:"slug,omitempty" doc:"Deprecated: the identifier before 0.18, now name."`Description string `json:"description"`@@ -326,19 +326,13 @@ func (h *FormHandler) Update(c *okapi.Context, req *UpdateFormRequest) error {}b := req.Body- name, displayName, err := resolveRenames(b.Name, b.DisplayName, b.Slug)+ displayName, err := resolveRename(b.Name, b.DisplayName, b.Slug, form.Name, "form")if err != nil {return c.AbortBadRequest(err.Error())}if displayName != "" {form.DisplayName = displayName}- if name != "" && name != form.Name {- if h.repo.NameExists(*scope.WorkspaceID, name, form.ID) {- return c.AbortConflict("a form named \"" + name + "\" already exists")- }- form.Name = name- }if strings.TrimSpace(b.Description) != "" {form.Description = strings.TrimSpace(b.Description)}diff --git a/internal/handlers/identifier.go b/internal/handlers/identifier.goindex bf40211..53b463c 100644--- a/internal/handlers/identifier.go+++ b/internal/handlers/identifier.go@@ -28,36 +28,36 @@ import (// Workspaces, forms, OAuth providers, templates and stylesheets share one// naming scheme: name is the identifier the API and URLs use, like-// "contact-form"; display_name is the label people read.+// "contact-form"; display_name is the label people read. People create a+// resource by typing only its name, as a label ("Contact form"): the+// identifier is derived from it. A name never changes once the resource+// exists; using another one means creating a new resource.-// legacyNames reads a request made before 0.18, when name was the label:-// with a slug and no display_name, the slug is the identifier; with no-// display_name and a name that is not an identifier, that name is the-// label. Deprecated, until 0.19.+// legacyNames reads a request made before 0.18, when name was the label and+// slug the identifier: with a slug and no display_name, the slug is the+// identifier and name the label. Deprecated, until 0.19.func legacyNames(name, displayName, legacySlug string) (string, string) {name, displayName, legacySlug = strings.TrimSpace(name), strings.TrimSpace(displayName), strings.TrimSpace(legacySlug)- switch {- case displayName != "":- return name, displayName- case legacySlug != "":+ if displayName == "" && legacySlug != "" {return legacySlug, name- case name != "" && models.CheckIdentifier(name) != nil:- return "", name}return name, displayName}// resolveNames settles the name and display name of a resource being-// created. A missing name is derived from the display name, and a missing-// display name is the name. legacySlug is the slug field of requests made-// before the rename, read by legacyNames.+// created. A name given alone may be a label, as people type it: it becomes+// the display name and the identifier is derived from it. A missing display+// name is the name. legacySlug is read by legacyNames.func resolveNames(name, displayName, legacySlug string) (string, string, error) {name, displayName = legacyNames(name, displayName, legacySlug)+ if displayName == "" && models.CheckIdentifier(name) != nil {+ name, displayName = "", name+ }if name == "" {name = models.ToIdentifier(displayName)}if name == "" {- return "", "", fmt.Errorf("name or display_name is required")+ return "", "", fmt.Errorf("name is required")}if err := models.CheckIdentifier(name); err != nil {return "", "", err@@ -68,17 +68,20 @@ func resolveNames(name, displayName, legacySlug string) (string, string, error)return name, displayName, nil}-// resolveRenames settles the name and display name an update asks for;-// an empty result leaves that value as it is. legacySlug is read by-// legacyNames.-func resolveRenames(name, displayName, legacySlug string) (string, string, error) {+// resolveRename settles the display name an update of resource asks for,+// whose name is current; an empty result leaves it as it is. Sending the+// current name is fine, any other is refused. Before 0.18 the label was+// sent as name: a name that is not an identifier, sent without a display+// name, is read as the label (deprecated, until 0.19).+func resolveRename(name, displayName, legacySlug, current, resource string) (string, error) {name, displayName = legacyNames(name, displayName, legacySlug)- if name != "" {- if err := models.CheckIdentifier(name); err != nil {- return "", "", err- }+ if displayName == "" && name != "" && models.CheckIdentifier(name) != nil {+ name, displayName = "", name}- return name, displayName, nil+ if name != "" && name != current {+ return "", fmt.Errorf("a %s's name cannot change; create a new %s to use another name", resource, resource)+ }+ return displayName, nil}// importNames settles the names of a resource read from an export or a@@ -86,6 +89,9 @@ func resolveRenames(name, displayName, legacySlug string) (string, string, error// it is derived from the display name, or fallback.func importNames(name, displayName, fallback string) (string, string) {name, displayName = legacyNames(name, displayName, "")+ if displayName == "" && models.CheckIdentifier(name) != nil {+ displayName = name+ }if name == "" || models.CheckIdentifier(name) != nil {name = models.ToIdentifier(firstNonEmpty(name, displayName))}diff --git a/internal/handlers/identifier_test.go b/internal/handlers/identifier_test.goindex a0fe752..589a375 100644--- a/internal/handlers/identifier_test.go+++ b/internal/handlers/identifier_test.go@@ -31,7 +31,7 @@ func TestResolveNames(t *testing.T) {{"both", "contact", "Contact form", "", "contact", "Contact form", false},{"display only", "", "Contact form", "", "contact-form", "Contact form", false},{"name only", "contact", "", "", "contact", "contact", false},- {"legacy label in name", "Contact form", "", "", "contact-form", "Contact form", false},+ {"label in name", "Contact form", "", "", "contact-form", "Contact form", false},{"legacy name and slug", "Contact form", "", "contact", "contact", "Contact form", false},{"slug ignored with display_name", "contact", "Contact form", "other", "contact", "Contact form", false},{"bad name with display_name", "Contact form", "Contact", "", "", "", true},@@ -51,16 +51,32 @@ func TestResolveNames(t *testing.T) {}}-func TestResolveRenames(t *testing.T) {- // An old client renaming the label sent it as name.- if name, display, err := resolveRenames("New label", "", ""); err != nil || name != "" || display != "New label" {- t.Fatalf("legacy label rename = (%q, %q, %v)", name, display, err)- }- if name, display, err := resolveRenames("new-id", "", ""); err != nil || name != "new-id" || display != "" {- t.Fatalf("identifier rename = (%q, %q, %v)", name, display, err)+func TestResolveRename(t *testing.T) {+ cases := []struct {+ label string+ name, displayName, slug string+ wantDisplay string+ wantErr bool+ }{+ {"display name only", "", "New label", "", "New label", false},+ {"current name", "contact", "New label", "", "New label", false},+ {"nothing", "", "", "", "", false},+ {"other name", "other", "", "", "", true},+ {"other name with display name", "other", "New label", "", "", true},+ {"other legacy slug", "New label", "", "other", "", true},+ // An old client renaming the label sent it as name.+ {"legacy label in name", "New label", "", "", "New label", false},}- if _, _, err := resolveRenames("Bad Id", "Label", ""); err == nil {- t.Fatal("a malformed name with a display name must be refused")+ for _, tc := range cases {+ t.Run(tc.label, func(t *testing.T) {+ display, err := resolveRename(tc.name, tc.displayName, tc.slug, "contact", "form")+ if (err != nil) != tc.wantErr {+ t.Fatalf("err = %v, want error %v", err, tc.wantErr)+ }+ if !tc.wantErr && display != tc.wantDisplay {+ t.Fatalf("got %q, want %q", display, tc.wantDisplay)+ }+ })}}diff --git a/internal/handlers/oauth_admin_handler.go b/internal/handlers/oauth_admin_handler.goindex 05eaa78..b3b5c89 100644--- a/internal/handlers/oauth_admin_handler.go+++ b/internal/handlers/oauth_admin_handler.go@@ -47,7 +47,7 @@ func NewOAuthAdminHandler(providerRepo *repositories.OAuthProviderRepository, sstype CreateOAuthProviderRequest struct {Body struct {- Name string `json:"name" doc:"Identifier used in the sign-in URLs, like google: lowercase letters, digits and hyphens. Derived from display_name when empty."`+ Name string `json:"name" doc:"The provider's name, as typed: \"Google\" is stored as the identifier google, used in the sign-in URLs, and \"Google\" as display_name. It cannot change later."`DisplayName string `json:"display_name" doc:"Shown on the sign-in button. Defaults to name."`Slug string `json:"slug,omitempty" doc:"Deprecated: the identifier before 0.18, now name."`Type string `json:"type" required:"true"`@@ -194,13 +194,10 @@ func (h *OAuthAdminHandler) UpdateProvider(c *okapi.Context, req *UpdateOAuthProreturn c.AbortNotFound("provider not found")}- name, displayName, err := resolveRenames(req.Body.Name, req.Body.DisplayName, "")+ displayName, err := resolveRename(req.Body.Name, req.Body.DisplayName, "", provider.Name, "provider")if err != nil {return c.AbortBadRequest(err.Error())}- if name != "" && name != provider.Name {- return c.AbortBadRequest("a provider's name is in its sign-in URLs and cannot change; set display_name to rename it")- }if displayName != "" {provider.DisplayName = displayName}diff --git a/internal/handlers/stylesheet_handler.go b/internal/handlers/stylesheet_handler.goindex 8d4d490..9b1ee08 100644--- a/internal/handlers/stylesheet_handler.go+++ b/internal/handlers/stylesheet_handler.go@@ -32,7 +32,7 @@ type StyleSheetHandler struct {}type CreateStyleSheetRequest struct {Body struct {- Name string `json:"name" doc:"Identifier, like brand: lowercase letters, digits and hyphens. Derived from display_name when empty."`+ Name string `json:"name" doc:"The stylesheet's name, as typed: \"Brand Styles\" is stored as the identifier brand-styles, with \"Brand Styles\" as display_name. It cannot change later."`DisplayName string `json:"display_name" doc:"The stylesheet's label. Defaults to name."`CSS string `json:"css"`} `json:"body"`@@ -87,13 +87,10 @@ func (h *StyleSheetHandler) Update(c *okapi.Context, req *UpdateStyleSheetRequesreturn c.AbortNotFound("stylesheet not found")}- name, displayName, err := resolveRenames(req.Body.Name, req.Body.DisplayName, "")+ displayName, err := resolveRename(req.Body.Name, req.Body.DisplayName, "", ss.Name, "stylesheet")if err != nil {return c.AbortBadRequest(err.Error())}- if name != "" {- ss.Name = name- }if displayName != "" {ss.DisplayName = displayName}@@ -105,9 +102,6 @@ func (h *StyleSheetHandler) Update(c *okapi.Context, req *UpdateStyleSheetRequesss.UpdatedAt = &nowif err := h.repo.Update(ss); err != nil {- if repositories.IsDuplicateName(err) {- return c.AbortConflict("a stylesheet named \"" + ss.Name + "\" already exists")- }return c.AbortInternalServerError("failed to update stylesheet")}diff --git a/internal/handlers/template_handler.go b/internal/handlers/template_handler.goindex 64c71d4..8eb973b 100644--- a/internal/handlers/template_handler.go+++ b/internal/handlers/template_handler.go@@ -43,7 +43,7 @@ type TemplateHandler struct {}type CreateTemplateRequest struct {Body struct {- Name string `json:"name" doc:"Identifier used to send with this template, like welcome-email: lowercase letters, digits and hyphens. Derived from display_name when empty."`+ Name string `json:"name" doc:"The template's name, as typed: \"Welcome Email\" is stored as the identifier welcome-email, which you send with, and \"Welcome Email\" as display_name. It cannot change later."`DisplayName string `json:"display_name" doc:"The template's label. Defaults to name."`SampleData string `json:"sample_data" default:"{}"`DefaultLanguage string `json:"default_language"`@@ -53,7 +53,7 @@ type CreateTemplateRequest struct {type UpdateTemplateRequest struct {ID int `param:"id"`Body struct {- Name string `json:"name" doc:"Identifier used to send with this template. Renaming it breaks callers that send by the old name."`+ Name string `json:"name" doc:"A template's name cannot change; only accepted when it is the current one."`DisplayName string `json:"display_name"`SampleData *string `json:"sample_data" default:"{}"`DefaultLanguage string `json:"default_language"`@@ -147,13 +147,10 @@ func (h *TemplateHandler) Update(c *okapi.Context, req *UpdateTemplateRequest) ereturn c.AbortNotFound("template not found")}- name, displayName, err := resolveRenames(req.Body.Name, req.Body.DisplayName, "")+ displayName, err := resolveRename(req.Body.Name, req.Body.DisplayName, "", tmpl.Name, "template")if err != nil {return c.AbortBadRequest(err.Error())}- if name != "" {- tmpl.Name = name- }if displayName != "" {tmpl.DisplayName = displayName}@@ -173,9 +170,6 @@ func (h *TemplateHandler) Update(c *okapi.Context, req *UpdateTemplateRequest) etmpl.LastEditedByID = &editorIDif err := h.repo.Update(tmpl); err != nil {- if repositories.IsDuplicateName(err) {- return c.AbortConflict("a template named \"" + tmpl.Name + "\" already exists in this workspace")- }return c.AbortInternalServerError("failed to update template")}diff --git a/internal/handlers/workspace_handler.go b/internal/handlers/workspace_handler.goindex 6e1234b..d947d36 100644--- a/internal/handlers/workspace_handler.go+++ b/internal/handlers/workspace_handler.go@@ -72,7 +72,7 @@ func (h *WorkspaceHandler) SetSeeder(s workspaceSeeder) { h.seeder = s }type CreateWorkspaceRequest struct {Body struct {- Name string `json:"name" doc:"Identifier, like acme: lowercase letters, digits and hyphens, unique on the platform. Derived from display_name when empty."`+ Name string `json:"name" doc:"The workspace's name, as typed: \"Acme Corp\" is stored as the identifier acme-corp, unique on the platform, with \"Acme Corp\" as display_name. It cannot change later."`DisplayName string `json:"display_name" doc:"The workspace's label. Defaults to name."`Slug string `json:"slug,omitempty" doc:"Deprecated: the identifier before 0.18, now name."`Description string `json:"description"`@@ -88,7 +88,7 @@ type CreateWorkspaceRequest struct {type UpdateWorkspaceRequest struct {Body struct {- Name string `json:"name" doc:"A workspace's name cannot change; only accepted when it is the current one. Set display_name to rename it."`+ Name string `json:"name" doc:"A workspace's name cannot change; only accepted when it is the current one."`DisplayName string `json:"display_name"`Description string `json:"description"`DefaultLanguage string `json:"default_language"`@@ -311,13 +311,10 @@ func (h *WorkspaceHandler) Update(c *okapi.Context, req *UpdateWorkspaceRequest)return c.AbortNotFound("workspace not found")}- name, displayName, err := resolveRenames(req.Body.Name, req.Body.DisplayName, "")+ displayName, err := resolveRename(req.Body.Name, req.Body.DisplayName, "", ws.Name, "workspace")if err != nil {return c.AbortBadRequest(err.Error())}- if name != "" && name != ws.Name {- return c.AbortBadRequest("a workspace's name cannot change; set display_name to rename it")- }if ws.System && displayName != "" && displayName != ws.DisplayName {return c.AbortConflict("the system workspace cannot be renamed")}diff --git a/web/src/api/types.ts b/web/src/api/types.tsindex afea81f..2d3fa59 100644--- a/web/src/api/types.ts+++ b/web/src/api/types.ts@@ -204,8 +204,12 @@ export interface TemplateInput {description?: string}-/** A template being created or edited in the dashboard: both names are set. */-export type TemplateDraft = TemplateInput & { name: string; display_name: string }+/**+ * A template being created or edited in the dashboard. Creating one sends the+ * name as typed and the server derives the identifier; editing one sends its+ * name unchanged.+ */+export type TemplateDraft = TemplateInput & { name: string }export interface TemplateExportLocalization {language: stringdiff --git a/web/src/assets/styles.css b/web/src/assets/styles.cssindex 62163ac..b794276 100644--- a/web/src/assets/styles.css+++ b/web/src/assets/styles.css@@ -321,6 +321,12 @@ option::checkmark {box-shadow: var(--shadow-focus);}+.form-input:disabled {+ background: var(--bg-tertiary);+ color: var(--text-secondary);+ cursor: not-allowed;+}+.form-input::placeholder,.form-textarea::placeholder { color: var(--text-muted); }@@ -331,12 +337,6 @@ option::checkmark {font-size: 13px;}-/* An identifier field: a resource's name, as the API and URLs use it. */-.form-input.mono {- font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;- font-size: 13px;-}-.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }.form-error { font-size: 12px; color: var(--danger-500); margin-top: 4px; }.form-hint-warning { color: var(--warning-600); }diff --git a/web/src/components/NameField.vue b/web/src/components/NameField.vuenew file mode 100644index 0000000..94a6c24--- /dev/null+++ b/web/src/components/NameField.vue@@ -0,0 +1,47 @@+<script setup lang="ts">+import { computed } from 'vue'+import { toIdentifier } from '@/composables/identifier'++// A resource's name. Creating one takes the name as typed, like "Contact+// form", and the server derives the identifier, contact-form; once the+// resource exists its name is shown, and cannot change.+interface Props {+ /** The resource being edited; absent while creating one. */+ existing?: { name: string; display_name?: string } | null+ /** What the resource is called, for the hint: "template", "form". */+ resource: string+ /** What the identifier is used for, like "Send with it as template in the API." */+ usage?: string+ placeholder?: string+ autofocus?: boolean+}+const props = withDefaults(defineProps<Props>(), {+ existing: null,+ usage: '',+ placeholder: '',+ autofocus: false,+})+const model = defineModel<string>({ default: '' })++const identifier = computed(() => toIdentifier(model.value))+</script>++<template>+ <div class="form-group">+ <label class="form-label">Name</label>+ <template v-if="existing">+ <input :value="existing.display_name || existing.name" class="form-input" disabled />+ <span class="form-hint">+ Saved as <code>{{ existing.name }}</code>. {{ usage }}+ A {{ resource }}'s name cannot change: create a new {{ resource }} to use another.+ </span>+ </template>+ <template v-else>+ <input v-model="model" class="form-input" :placeholder="placeholder" :autofocus="autofocus" />+ <span class="form-hint">+ <template v-if="identifier">Saved as <code>{{ identifier }}</code>.</template>+ {{ usage }} It cannot change later.+ </span>+ </template>+ </div>+</template>diff --git a/web/src/components/TemplateModal.vue b/web/src/components/TemplateModal.vueindex 23eed35..0c5e06f 100644--- a/web/src/components/TemplateModal.vue+++ b/web/src/components/TemplateModal.vue@@ -1,9 +1,9 @@<script setup lang="ts">import { languagesApi } from '@/api/languages';import { Language, Template, TemplateDraft } from '@/api/types';-import { IDENTIFIER_HINT, toIdentifier } from '@/composables/identifier';+import NameField from '@/components/NameField.vue';import { useModalSafeClose } from '@/composables/useModalSafeClose';-import { onMounted, ref, watch } from 'vue';+import { onMounted, ref } from 'vue';interface Props {form: TemplateDraft@@ -11,7 +11,7 @@ interface Props {saving?: booleanediting?: Template | null}-const props = withDefaults(defineProps<Props>(), {+withDefaults(defineProps<Props>(), {isVisible: false,saving: false,editing: null@@ -39,16 +39,6 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {onMounted(() => {loadLanguages();});--// A new template's name follows its display name until edited by hand; an-// existing one keeps its name, which callers send.-const nameEdited = ref(false)-watch(() => props.isVisible, (visible) => {- if (visible) nameEdited.value = !!props.editing-})-function syncName() {- if (!nameEdited.value) props.form.name = toIdentifier(props.form.display_name)-}</script><template>@@ -59,19 +49,8 @@ function syncName() {</div><div class="modal-body">- <div class="form-group">- <label class="form-label">Display name</label>- <input v-model="form.display_name" class="form-input" placeholder="e.g. Welcome Email" @input="syncName" />- </div>- <div class="form-group">- <label class="form-label">Name</label>- <input v-model="form.name" class="form-input mono" placeholder="welcome-email" :title="IDENTIFIER_HINT"- @input="nameEdited = true" />- <span v-if="editing && form.name !== editing.name" class="form-hint form-hint-warning">- Callers that send with <code>{{ editing.name }}</code> stop finding this template.- </span>- <span v-else class="form-hint">What you send as <code>template</code> in the API. {{ IDENTIFIER_HINT }}</span>- </div>+ <NameField v-model="form.name" :existing="editing" resource="template"+ usage="Send it as template in the API." placeholder="e.g. Welcome Email" autofocus /><div class="form-group"><label class="form-label">Description</label><input v-model="form.description" class="form-input" placeholder="e.g. Sent after user registration" />@@ -95,7 +74,7 @@ function syncName() {<div class="modal-footer"><button class="btn btn-secondary" @click="emit('close')">Cancel</button>- <button class="btn btn-primary" :disabled="saving || !form.display_name.trim() || !form.name.trim()" @click="emit('save')">+ <button class="btn btn-primary" :disabled="saving || !form.name.trim()" @click="emit('save')">{{ saving ? "Saving..." : editing ? "Update" : "Create" }}</button></div>diff --git a/web/src/composables/identifier.ts b/web/src/composables/identifier.tsindex f661734..eaddafe 100644--- a/web/src/composables/identifier.ts+++ b/web/src/composables/identifier.ts@@ -1,22 +1,14 @@// Workspaces, forms, OAuth providers, templates and stylesheets share one// naming scheme: name is the identifier the API and URLs use, like-// "contact-form"; display_name is the label people read. These mirror the-// server's rules in internal/models/identifier.go.+// "contact-form"; display_name is the label people read. The server derives+// the identifier from the name people type; toIdentifier mirrors its rules+// in internal/models/identifier.go, to show it before the resource exists.export const MAX_IDENTIFIER_LENGTH = 63-const IDENTIFIER = /^[a-z0-9]+(?:-[a-z0-9]+)*$/-/** Derives an identifier from a label: "Contact form" becomes "contact-form". */export function toIdentifier(label: string): string {let v = label.trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '')if (v.length > MAX_IDENTIFIER_LENGTH) v = v.slice(0, MAX_IDENTIFIER_LENGTH).replace(/-+$/, '')return v}--/** Whether name can be an identifier. */-export function isIdentifier(name: string): boolean {- return name.length <= MAX_IDENTIFIER_LENGTH && IDENTIFIER.test(name)-}--export const IDENTIFIER_HINT = 'Lowercase letters, digits and hyphens.'diff --git a/web/src/views/admin/OAuthProviders.vue b/web/src/views/admin/OAuthProviders.vueindex b491893..60b82a3 100644--- a/web/src/views/admin/OAuthProviders.vue+++ b/web/src/views/admin/OAuthProviders.vue@@ -6,7 +6,7 @@ import { useNotificationStore } from '../../stores/notification'import { useConfirm } from '../../composables/useConfirm'import { useLicenseStore } from '../../stores/license'import { ENTERPRISE_URL } from '../../api/license'-import { IDENTIFIER_HINT, toIdentifier } from '../../composables/identifier'+import NameField from '../../components/NameField.vue'const notify = useNotificationStore()const { confirm } = useConfirm()@@ -22,26 +22,20 @@ const loading = ref(true)const showCreateModal = ref(false)const creating = ref(false)const emptyForm = () => ({- display_name: '', name: '', type: 'oidc',- client_id: '', client_secret: '', issuer: '',- auth_url: '', token_url: '', userinfo_url: '',- scopes: 'openid email profile',- auto_register: true, hidden: false, allowed_domains: '',-})-const form = ref({- display_name: '', name: '', type: 'oidc',+ name: '', type: 'oidc',client_id: '', client_secret: '', issuer: '',auth_url: '', token_url: '', userinfo_url: '',scopes: 'openid email profile',auto_register: true, hidden: false, allowed_domains: '',})+const form = ref(emptyForm())// Edit modalconst showEditModal = ref(false)const editing = ref(false)const editingProvider = ref<OAuthProviderAdmin | null>(null)const editForm = ref({- display_name: '', client_id: '', client_secret: '', issuer: '',+ client_id: '', client_secret: '', issuer: '',auth_url: '', token_url: '', userinfo_url: '',scopes: '', auto_register: true, hidden: false, allowed_domains: '',})@@ -58,21 +52,14 @@ async function fetchProviders() {}}-// The name follows the display name until it is edited by hand.-const nameEdited = ref(false)-function syncName() {- if (!nameEdited.value) form.value.name = toIdentifier(form.value.display_name)-}-async function createProvider() {- if (!form.value.display_name || !form.value.name || !form.value.client_id || !form.value.client_secret) return+ if (!form.value.name.trim() || !form.value.client_id || !form.value.client_secret) returncreating.value = truetry {await oauthApi.adminCreate(form.value)notify.success('Provider created')showCreateModal.value = falseform.value = emptyForm()- nameEdited.value = falseawait fetchProviders()} catch (err: any) {notify.error(err.response?.data?.error?.message || 'Failed to create provider')@@ -84,7 +71,6 @@ async function createProvider() {function openEdit(p: OAuthProviderAdmin) {editingProvider.value = peditForm.value = {- display_name: p.display_name,client_id: '',client_secret: '',issuer: p.issuer || '',@@ -104,7 +90,6 @@ async function updateProvider() {editing.value = truetry {const data: Record<string, any> = {}- if (editForm.value.display_name) data.display_name = editForm.value.display_nameif (editForm.value.client_id) data.client_id = editForm.value.client_idif (editForm.value.client_secret) data.client_secret = editForm.value.client_secretif (editForm.value.issuer) data.issuer = editForm.value.issuer@@ -231,19 +216,8 @@ onMounted(() => {<div class="modal-header"><h3>Add OAuth Provider</h3></div><form @submit.prevent="createProvider"><div class="modal-body">- <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 16px;">- <div class="form-group">- <label class="form-label">Display name</label>- <input v-model="form.display_name" class="form-input" placeholder="Google" required @input="syncName" />- <span class="form-hint">Shown on the sign-in button.</span>- </div>- <div class="form-group">- <label class="form-label">Name</label>- <input v-model="form.name" class="form-input mono" placeholder="google" required pattern="[a-z0-9]+(-[a-z0-9]+)*"- :title="IDENTIFIER_HINT" @input="nameEdited = true" />- <span class="form-hint">In the sign-in URLs. It cannot change later.</span>- </div>- </div>+ <NameField v-model="form.name" resource="provider" usage="Shown on the sign-in button, and in its URLs."+ placeholder="e.g. Google" autofocus /><div class="form-group"><label class="form-label">Type</label><select v-model="form.type" class="form-select">@@ -302,11 +276,7 @@ onMounted(() => {<div class="modal-header"><h3>Edit {{ editingProvider.display_name }}</h3></div><form @submit.prevent="updateProvider"><div class="modal-body">- <div class="form-group">- <label class="form-label">Display name</label>- <input v-model="editForm.display_name" class="form-input" required />- <span class="form-hint">Its name, <code>{{ editingProvider.name }}</code>, is in the sign-in URLs and stays the same.</span>- </div>+ <NameField :existing="editingProvider" resource="provider" usage="Shown on the sign-in button, and in its URLs." /><div style="display: grid; grid-template-columns: 1fr 1fr; gap: 16px;"><div class="form-group"><label class="form-label">Client ID</label>diff --git a/web/src/views/forms/FormDetail.vue b/web/src/views/forms/FormDetail.vueindex 37f2b39..de166ea 100644--- a/web/src/views/forms/FormDetail.vue+++ b/web/src/views/forms/FormDetail.vue@@ -1,6 +1,6 @@<script setup lang="ts">import { computed, onMounted, ref, watch } from "vue";-import { IDENTIFIER_HINT } from "../../composables/identifier";+import NameField from "../../components/NameField.vue";import { useRoute, useRouter } from "vue-router";import { formsApi } from "../../api/messages";import { useNotificationStore } from "../../stores/notification";@@ -113,8 +113,6 @@ async function save() {saving.value = true;try {const res = await formsApi.update(id, {- display_name: form.value.display_name,- name: form.value.name,description: form.value.description,status: form.value.status,mode: form.value.mode,@@ -309,17 +307,7 @@ onMounted(load);<div v-show="tab === 'setup'" class="card" style="margin-bottom: 20px"><div class="card-header"><h2>Setup</h2></div><div class="card-body">- <div class="name-row">- <div class="form-group">- <label class="form-label">Display name</label>- <input v-model="form.display_name" class="form-input" />- </div>- <div class="form-group">- <label class="form-label">Name</label>- <input v-model="form.name" class="form-input mono" pattern="[a-z0-9]+(-[a-z0-9]+)*" :title="IDENTIFIER_HINT" />- <span class="form-hint">Identifies the form in the API. The embed and share links use its key, so they keep working if it changes.</span>- </div>- </div>+ <NameField :existing="form" resource="form" usage="Identifies the form in the API." /><div class="form-group"><label class="form-label">Description</label><input v-model="form.description" class="form-input" />@@ -710,12 +698,6 @@ onMounted(load);</template><style scoped>-.name-row {- display: grid;- grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));- gap: 0 16px;-}-.mode-choice {border: 0;padding: 0;diff --git a/web/src/views/forms/Forms.vue b/web/src/views/forms/Forms.vueindex 628da3b..a432371 100644--- a/web/src/views/forms/Forms.vue+++ b/web/src/views/forms/Forms.vue@@ -1,6 +1,6 @@<script setup lang="ts">import { ref } from "vue";-import { IDENTIFIER_HINT, toIdentifier } from "../../composables/identifier";+import NameField from "../../components/NameField.vue";import { useRouter } from "vue-router";import { formsApi } from "../../api/messages";import { useNotificationStore } from "../../stores/notification";@@ -17,10 +17,7 @@ const forms = ref<Form[]>([]);const showCreate = ref(false);const creating = ref(false);-const newDisplayName = ref("");const newName = ref("");-// The name follows the display name until it is edited by hand.-const nameEdited = ref(false);const newOrigins = ref("");const newNotify = ref("");const newMode = ref<FormMode>("inbox");@@ -43,14 +40,8 @@ const { pageable, goToPage } = usePagination(async (page) => {}});-function syncName() {- if (!nameEdited.value) newName.value = toIdentifier(newDisplayName.value);-}-function openCreate() {- newDisplayName.value = "";newName.value = "";- nameEdited.value = false;newOrigins.value = "";newNotify.value = "";newMode.value = "inbox";@@ -58,12 +49,11 @@ function openCreate() {}async function createForm() {- if (!newDisplayName.value.trim()) return;+ if (!newName.value.trim()) return;creating.value = true;try {const res = await formsApi.create({- display_name: newDisplayName.value.trim(),- name: newName.value.trim() || undefined,+ name: newName.value.trim(),mode: newMode.value,allowed_origins: splitList(newOrigins.value),notify_emails: splitList(newNotify.value),@@ -174,16 +164,8 @@ function formatDate(date: string | null | undefined) {<h3>New form</h3></div><div class="modal-body">- <div class="form-group">- <label class="form-label">Display name</label>- <input v-model="newDisplayName" class="form-input" placeholder="Contact form" @input="syncName" />- </div>- <div class="form-group">- <label class="form-label">Name</label>- <input v-model="newName" class="form-input mono" placeholder="contact-form" :title="IDENTIFIER_HINT"- @input="nameEdited = true" />- <span class="form-hint">Identifies the form in the API. {{ IDENTIFIER_HINT }}</span>- </div>+ <NameField v-model="newName" resource="form" usage="Identifies the form in the API."+ placeholder="e.g. Contact form" autofocus /><div class="form-group"><label class="form-label">Submissions are</label><select v-model="newMode" class="form-select">@@ -218,7 +200,7 @@ function formatDate(date: string | null | undefined) {</div><div class="modal-footer"><button class="btn btn-secondary" @click="showCreate = false">Cancel</button>- <button class="btn btn-primary" :disabled="creating || !newDisplayName.trim()" @click="createForm">+ <button class="btn btn-primary" :disabled="creating || !newName.trim()" @click="createForm">{{ creating ? "Creating..." : "Create form" }}</button></div>diff --git a/web/src/views/stylesheets/Stylesheets.vue b/web/src/views/stylesheets/Stylesheets.vueindex 9e27b9b..46745ff 100644--- a/web/src/views/stylesheets/Stylesheets.vue+++ b/web/src/views/stylesheets/Stylesheets.vue@@ -1,6 +1,6 @@<script setup lang="ts">import { ref, onMounted } from 'vue'-import { IDENTIFIER_HINT, toIdentifier } from '../../composables/identifier'+import NameField from '../../components/NameField.vue'import { stylesheetsApi } from '../../api/stylesheets'import type { StyleSheet, StyleSheetInput, Pageable } from '../../api/types'import { useNotificationStore } from '../../stores/notification'@@ -22,22 +22,15 @@ const showModal = ref(false)const editing = ref<StyleSheet | null>(null)const saving = ref(false)- const form = ref<Required<StyleSheetInput>>({+// Creating a stylesheet sends its name as typed; editing one sends its name+// unchanged.+const form = ref<Required<Omit<StyleSheetInput, 'display_name'>>>({name: '',- display_name: '',css: '',})-// A new stylesheet's name follows its display name until edited by hand;-// an existing one keeps its name.-const nameEdited = ref(false)--function syncName() {- if (!nameEdited.value) form.value.name = toIdentifier(form.value.display_name)-}function resetForm() {- form.value = { name: '', display_name: '', css: '' }- nameEdited.value = false+ form.value = { name: '', css: '' }editing.value = null}@@ -50,10 +43,8 @@ function openEdit(sheet: StyleSheet) {editing.value = sheetform.value = {name: sheet.name,- display_name: sheet.display_name,css: sheet.css,}- nameEdited.value = trueshowModal.value = true}@@ -76,7 +67,7 @@ const { pageable, goToPage } = usePagination(async (page) => {async function saveStylesheet() {- if (!form.value.display_name.trim() || !form.value.name.trim()) return+ if (!form.value.name.trim()) returnsaving.value = truetry {if (editing.value) {@@ -185,16 +176,8 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {<h3>{{ editing ? 'Edit Stylesheet' : 'Create Stylesheet' }}</h3></div><div class="modal-body">- <div class="form-group">- <label class="form-label">Display name</label>- <input v-model="form.display_name" class="form-input" placeholder="e.g. Brand Styles" @input="syncName" />- </div>- <div class="form-group">- <label class="form-label">Name</label>- <input v-model="form.name" class="form-input mono" placeholder="brand-styles" :title="IDENTIFIER_HINT"- @input="nameEdited = true" />- <span class="form-hint">Imported HTML templates link stylesheets by this name. {{ IDENTIFIER_HINT }}</span>- </div>+ <NameField v-model="form.name" :existing="editing" resource="stylesheet"+ usage="Imported HTML templates link stylesheets by it." placeholder="e.g. Brand Styles" autofocus /><div class="form-group"><label class="form-label">CSS</label><textarea v-model="form.css" class="form-textarea css-editor" rows="12" placeholder="body { font-family: sans-serif; }"></textarea>@@ -205,7 +188,7 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {<button class="btn btn-secondary" @click="closeModal">Cancel</button><buttonclass="btn btn-primary"- :disabled="saving || !form.display_name.trim() || !form.name.trim()"+ :disabled="saving || !form.name.trim()"@click="saveStylesheet">{{ saving ? 'Saving...' : (editing ? 'Update' : 'Create') }}diff --git a/web/src/views/templates/TemplateDetail.vue b/web/src/views/templates/TemplateDetail.vueindex dd1354b..e188820 100644--- a/web/src/views/templates/TemplateDetail.vue+++ b/web/src/views/templates/TemplateDetail.vue@@ -85,7 +85,6 @@ const savingTemplate = ref(false);const showTemplateEditModal = ref(false);const templateForm = ref<TemplateDraft>({name: "",- display_name: "",sample_data: "",default_language: "en",description: "",@@ -378,7 +377,6 @@ function openEditTemplate() {if (!template.value) return;templateForm.value = {name: template.value.name,- display_name: template.value.display_name,sample_data: template.value.sample_data || "",default_language: template.value.default_language || "en",description: template.value.description || "",@@ -387,7 +385,7 @@ function openEditTemplate() {}async function saveTemplate() {- if (!template.value || !templateForm.value.display_name.trim() || !templateForm.value.name.trim()) return;+ if (!template.value || !templateForm.value.name.trim()) return;savingTemplate.value = true;try {await templatesApi.update(template.value.id, templateForm.value);diff --git a/web/src/views/templates/Templates.vue b/web/src/views/templates/Templates.vueindex 0d87773..5792eff 100644--- a/web/src/views/templates/Templates.vue+++ b/web/src/views/templates/Templates.vue@@ -38,7 +38,6 @@ const languages = ref<Language[]>([]);const form = ref<TemplateDraft>({name: "",- display_name: "",sample_data: "",default_language: "en",description: "",@@ -54,7 +53,7 @@ async function loadLanguages() {}function resetForm() {- form.value = { name: "", display_name: "", sample_data: "", default_language : languages.value.find(l => l.is_default)?.code || 'en', description: "" };+ form.value = { name: "", sample_data: "", default_language : languages.value.find(l => l.is_default)?.code || 'en', description: "" };editing.value = null;}@@ -67,7 +66,6 @@ function openEdit(template: Template) {editing.value = template;form.value = {name: template.name,- display_name: template.display_name,sample_data: template.sample_data || "",default_language: template.default_language || "en",description: template.description || "",@@ -98,7 +96,7 @@ function onSearchInput() {}async function saveTemplate() {- if (!form.value.display_name.trim() || !form.value.name.trim()) return;+ if (!form.value.name.trim()) return;saving.value = true;try {if (editing.value) {diff --git a/web/src/views/templates/detail/TemplateSummary.vue b/web/src/views/templates/detail/TemplateSummary.vueindex fed934b..bafb893 100644--- a/web/src/views/templates/detail/TemplateSummary.vue+++ b/web/src/views/templates/detail/TemplateSummary.vue@@ -8,15 +8,16 @@ const props = defineProps<{languages: string[];}>();-const copied = ref(false);+// Which value was just copied: "name" or "id".+const copied = ref<string | null>(null);-async function copyId() {+async function copy(what: "name" | "id") {try {- await navigator.clipboard.writeText(String(props.template.id));- copied.value = true;- setTimeout(() => (copied.value = false), 2000);+ await navigator.clipboard.writeText(what === "name" ? props.template.name : String(props.template.id));+ copied.value = what;+ setTimeout(() => (copied.value = null), 2000);} catch {- // Clipboard access can be denied; the id is selectable either way.+ // Clipboard access can be denied; the value is selectable either way.}}@@ -32,12 +33,22 @@ function formatDate(value?: string | null) {<template><div class="summary"><div class="facts">+ <div class="fact">+ <span class="k">Name</span>+ <span class="v">+ <code class="id" title="What you send as template in the API">{{ template.name }}</code>+ <button class="copy" type="button" :title="copied === 'name' ? 'Copied' : 'Copy template name'" @click="copy('name')">+ {{ copied === "name" ? "Copied" : "Copy" }}+ </button>+ </span>+ </div>+<div class="fact"><span class="k">ID</span><span class="v"><code class="id">{{ template.id }}</code>- <button class="copy" type="button" :title="copied ? 'Copied' : 'Copy template ID'" @click="copyId">- {{ copied ? "Copied" : "Copy" }}+ <button class="copy" type="button" :title="copied === 'id' ? 'Copied' : 'Copy template ID'" @click="copy('id')">+ {{ copied === "id" ? "Copied" : "Copy" }}</button></span></div>@@ -127,6 +138,10 @@ function formatDate(value?: string | null) {}.id {+ max-width: 100%;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;font-family: "JetBrains Mono", "Fira Code", monospace;font-size: 12px;padding: 2px 8px;diff --git a/web/src/views/workspaces/WorkspaceSettings.vue b/web/src/views/workspaces/WorkspaceSettings.vueindex 2c79d3d..3a9491d 100644--- a/web/src/views/workspaces/WorkspaceSettings.vue+++ b/web/src/views/workspaces/WorkspaceSettings.vue@@ -9,6 +9,7 @@ import { useNotificationStore } from '../../stores/notification'import { useWorkspaceStore } from '../../stores/workspace'import { useConfirm } from '../../composables/useConfirm'import { timezoneOptions } from '../../composables/timezones'+import NameField from '../../components/NameField.vue'const route = useRoute()const router = useRouter()@@ -59,7 +60,6 @@ const importing = ref(false)const importFileRef = ref<HTMLInputElement | null>(null)// Settings (workspace name/description)-const editDisplayName = ref('')const editDescription = ref('')const saving = ref(false)@@ -113,7 +113,6 @@ async function fetchWorkspace() {try {const res = await withWorkspace(() => workspaceApi.getCurrent())ws.value = res.data.data- editDisplayName.value = ws.value.display_nameeditDescription.value = ws.value.description || ''} catch {notify.error('Failed to load workspace')@@ -298,7 +297,7 @@ function formatLimit(value: number): string {async function saveSettings() {saving.value = truetry {- await withWorkspace(() => workspaceApi.update({ display_name: editDisplayName.value.trim(), description: editDescription.value.trim() }))+ await withWorkspace(() => workspaceApi.update({ description: editDescription.value.trim() }))notify.success('Workspace updated')await wsStore.fetchWorkspaces()} catch (err: any) {@@ -536,19 +535,11 @@ watch(activeTab, (value) => {<div v-if="activeTab === 'settings' && isAdminOrOwner" class="card"><div class="card-header"><span>Workspace Settings</span></div><div class="card-body">- <div class="form-group">- <label class="form-label">Display name</label>- <input v-model="editDisplayName" class="form-input" />- </div>+ <NameField v-if="ws" :existing="ws" resource="workspace" usage="Unique on this Posta." /><div class="form-group"><label class="form-label">Description</label><input v-model="editDescription" class="form-input" placeholder="Optional description" /></div>- <div class="form-group">- <label class="form-label">Name</label>- <input :value="ws?.name" class="form-input mono" disabled />- <span class="form-hint">The workspace's identifier. It cannot change after creation.</span>- </div><button class="btn btn-primary" :disabled="saving" @click="saveSettings">{{ saving ? 'Saving...' : 'Save Changes' }}</button>diff --git a/web/src/views/workspaces/Workspaces.vue b/web/src/views/workspaces/Workspaces.vueindex 520cd6b..1ede1d3 100644--- a/web/src/views/workspaces/Workspaces.vue+++ b/web/src/views/workspaces/Workspaces.vue@@ -1,6 +1,6 @@<script setup lang="ts">import { ref, onMounted } from 'vue'-import { IDENTIFIER_HINT, toIdentifier } from '../../composables/identifier'+import NameField from '../../components/NameField.vue'import { useRouter, useRoute } from 'vue-router'import { workspaceApi } from '../../api/workspaces'import type { Workspace, WorkspaceInvitation } from '../../api/types'@@ -17,10 +17,7 @@ const invitations = ref<WorkspaceInvitation[]>([])const loading = ref(true)const showCreateModal = ref(false)-const newDisplayName = ref('')const newName = ref('')-// The name follows the display name until it is edited by hand.-const nameEdited = ref(false)const newDescription = ref('')// On by default: an empty workspace has nothing to send and nothing to look at.const newSeedDefaults = ref(true)@@ -42,25 +39,18 @@ async function fetchData() {}}-function syncName() {- if (!nameEdited.value) newName.value = toIdentifier(newDisplayName.value)-}-async function createWorkspace() {- if (!newDisplayName.value.trim() || !newName.value.trim()) return+ if (!newName.value.trim()) returncreating.value = truetry {await workspaceApi.create({- display_name: newDisplayName.value.trim(),name: newName.value.trim(),description: newDescription.value.trim(),seed_defaults: newSeedDefaults.value,})notify.success('Workspace created')showCreateModal.value = false- newDisplayName.value = ''newName.value = ''- nameEdited.value = falsenewDescription.value = ''newSeedDefaults.value = trueawait fetchData()@@ -224,29 +214,8 @@ if (route.query.create !== undefined) {</div><form @submit.prevent="createWorkspace"><div class="modal-body">- <div class="form-group">- <label class="form-label">Display name</label>- <input- v-model="newDisplayName"- class="form-input"- placeholder="My Team"- required- @input="syncName"- />- </div>- <div class="form-group">- <label class="form-label">Name</label>- <input- v-model="newName"- class="form-input mono"- placeholder="my-team"- pattern="[a-z0-9]+(-[a-z0-9]+)*"- :title="IDENTIFIER_HINT"- required- @input="nameEdited = true"- />- <span class="form-hint">Unique on this Posta. {{ IDENTIFIER_HINT }} It cannot change later.</span>- </div>+ <NameField v-model="newName" resource="workspace" usage="Unique on this Posta." placeholder="e.g. My Team"+ autofocus /><div class="form-group"><label class="form-label">Description (optional)</label><input@@ -269,7 +238,7 @@ if (route.query.create !== undefined) {</div><div class="modal-footer"><button type="button" class="btn btn-secondary" @click="showCreateModal = false">Cancel</button>- <button type="submit" class="btn btn-primary" :disabled="creating || !newDisplayName.trim() || !newName.trim()">+ <button type="submit" class="btn btn-primary" :disabled="creating || !newName.trim()">{{ creating ? 'Creating...' : 'Create' }}</button></div>