Remove unused hostname_prefix from server types and add duplicate checking
The HostnamePrefix field on ServerType was loaded from YAML but never used — hostnames are user-provided. This removes the field and adds explicit duplicate checks (hostname + MAC) with clear per-field error messages in both the JSON API and web UI, backed by a new GetByHostname store method with case-insensitive matching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -74,6 +74,22 @@ func (u *UI) CreateHost(w http.ResponseWriter, r *http.Request) {
|
||||
}))
|
||||
return
|
||||
}
|
||||
if existing, err := u.Hosts.GetByHostname(r.Context(), hostname); err == nil && existing != nil {
|
||||
errs = append(errs, "A host with this hostname already exists")
|
||||
}
|
||||
if existing, err := u.Hosts.GetByMAC(r.Context(), mac); err == nil && existing != nil {
|
||||
errs = append(errs, "A host with this MAC address already exists")
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
types := u.ServerTypes.Keys()
|
||||
renderHTML(w, hostFormPage(types, strings.Join(errs, "; "), &model.Host{
|
||||
Hostname: hostname,
|
||||
MAC: mac,
|
||||
ServerType: serverType,
|
||||
Notes: notes,
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
_, err := u.Hosts.Create(r.Context(), model.Host{
|
||||
Hostname: hostname,
|
||||
|
||||
Reference in New Issue
Block a user