A continuation of HomeBox the inventory and organization system built for the Home User
fix: various new bugs (#1553)
Matte01dd737238a
diff --git a/backend/app/api/handlers/v1/v1_ctrl_entity_templates.go b/backend/app/api/handlers/v1/v1_ctrl_entity_templates.goindex f68ed9f8..2663a640 100644--- a/backend/app/api/handlers/v1/v1_ctrl_entity_templates.go+++ b/backend/app/api/handlers/v1/v1_ctrl_entity_templates.go@@ -104,11 +104,14 @@ func (ctrl *V1Controller) HandleEntityTemplatesDelete() errchain.HandlerFunc {}type EntityTemplateCreateItemRequest struct {- Name string `json:"name" validate:"required,min=1,max=255"`- Description string `json:"description" validate:"max=1000"`- ParentID uuid.UUID `json:"parentId" validate:"required"`- TagIDs []uuid.UUID `json:"tagIds"`- Quantity *float64 `json:"quantity"`+ Name string `json:"name" validate:"required,min=1,max=255"`+ Description string `json:"description" validate:"max=1000"`+ ParentID uuid.UUID `json:"parentId" validate:"required"`+ // EntityTypeID is the entity type selected by the user. When set it takes+ // precedence; when empty the repository falls back to the group's default.+ EntityTypeID uuid.UUID `json:"entityTypeId"`+ TagIDs []uuid.UUID `json:"tagIds"`+ Quantity *float64 `json:"quantity"`}// HandleEntityTemplatesCreateItem godoc@@ -152,6 +155,7 @@ func (ctrl *V1Controller) HandleEntityTemplatesCreateItem() errchain.HandlerFuncDescription: body.Description,Quantity: quantity,ParentID: body.ParentID,+ EntityTypeID: body.EntityTypeID,TagIDs: body.TagIDs,Insured: template.DefaultInsured,Manufacturer: template.DefaultManufacturer,diff --git a/backend/app/api/main.go b/backend/app/api/main.goindex d3e0b8ca..c33fa025 100644--- a/backend/app/api/main.go+++ b/backend/app/api/main.go@@ -202,7 +202,11 @@ func run(cfg *config.Config) error {router.Use(middleware.RequestID,- middleware.RealIP,+ // middleware.RealIP is intentionally omitted: it unconditionally rewrites+ // r.RemoteAddr from X-Forwarded-For / X-Real-IP / True-Client-IP headers,+ // which is spoofable and bypasses our trustProxy gate. Client IP is+ // resolved instead by extractClientIP, which only trusts those headers+ // when the operator has enabled trustProxy.mid.Logger(logger),mid.SecurityHeaders(),// Restrict the max body size to the upload limit + 1MB (for overhead).diff --git a/backend/app/api/static/docs/docs.go b/backend/app/api/static/docs/docs.goindex c6a1a696..279bc5eb 100644--- a/backend/app/api/static/docs/docs.go+++ b/backend/app/api/static/docs/docs.go@@ -6383,6 +6383,10 @@ const docTemplate = `{"type": "string","maxLength": 1000},+ "entityTypeId": {+ "description": "EntityTypeID is the entity type selected by the user. When set it takes\nprecedence; when empty the repository falls back to the group's default.",+ "type": "string"+ },"name": {"type": "string","maxLength": 255,diff --git a/backend/app/api/static/docs/openapi-3.json b/backend/app/api/static/docs/openapi-3.jsonindex a16bb34b..f2474084 100644--- a/backend/app/api/static/docs/openapi-3.json+++ b/backend/app/api/static/docs/openapi-3.json@@ -6622,6 +6622,10 @@"type": "string","maxLength": 1000},+ "entityTypeId": {+ "description": "EntityTypeID is the entity type selected by the user. When set it takes\nprecedence; when empty the repository falls back to the group's default.",+ "type": "string"+ },"name": {"type": "string","maxLength": 255,diff --git a/backend/app/api/static/docs/openapi-3.yaml b/backend/app/api/static/docs/openapi-3.yamlindex 867abc4f..c074bb7b 100644--- a/backend/app/api/static/docs/openapi-3.yaml+++ b/backend/app/api/static/docs/openapi-3.yaml@@ -4250,6 +4250,13 @@ components:description:type: stringmaxLength: 1000+ entityTypeId:+ description: >-+ EntityTypeID is the entity type selected by the user. When set it+ takes++ precedence; when empty the repository falls back to the group's default.+ type: stringname:type: stringmaxLength: 255diff --git a/backend/app/api/static/docs/swagger.json b/backend/app/api/static/docs/swagger.jsonindex 257fa81d..666f56c4 100644--- a/backend/app/api/static/docs/swagger.json+++ b/backend/app/api/static/docs/swagger.json@@ -6380,6 +6380,10 @@"type": "string","maxLength": 1000},+ "entityTypeId": {+ "description": "EntityTypeID is the entity type selected by the user. When set it takes\nprecedence; when empty the repository falls back to the group's default.",+ "type": "string"+ },"name": {"type": "string","maxLength": 255,diff --git a/backend/app/api/static/docs/swagger.yaml b/backend/app/api/static/docs/swagger.yamlindex 6332c8ec..2f828070 100644--- a/backend/app/api/static/docs/swagger.yaml+++ b/backend/app/api/static/docs/swagger.yaml@@ -2196,6 +2196,11 @@ definitions:description:maxLength: 1000type: string+ entityTypeId:+ description: |-+ EntityTypeID is the entity type selected by the user. When set it takes+ precedence; when empty the repository falls back to the group's default.+ type: stringname:maxLength: 255minLength: 1diff --git a/backend/go.sum b/backend/go.sumindex fa4f2694..9493468f 100644--- a/backend/go.sum+++ b/backend/go.sum@@ -133,6 +133,12 @@ github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xgithub.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=+github.com/clipperhouse/displaywidth v0.6.2 h1:ZDpTkFfpHOKte4RG5O/BOyf3ysnvFswpyYrV7z2uAKo=+github.com/clipperhouse/displaywidth v0.6.2/go.mod h1:R+kHuzaYWFkTm7xoMmK1lFydbci4X2CicfbGstSGg0o=+github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs=+github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA=+github.com/clipperhouse/uax29/v2 v2.3.0 h1:SNdx9DVUqMoBuBoW3iLOj4FQv3dN5mDtuqwuhIGpJy4=+github.com/clipperhouse/uax29/v2 v2.3.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2 h1:aBangftG7EVZoUb69Os8IaYg++6uMOdKK83QtkkvJik=github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2/go.mod h1:qwXFYgsP6T7XnJtbKlf1HP8AjxZZyzxMmc+Lq5GjlU4=github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=@@ -328,6 +334,8 @@ github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWygithub.com/mattn/go-colorable v0.1.15/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=+github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=+github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=github.com/mattn/go-sqlite3 v1.14.34 h1:3NtcvcUnFBPsuRcno8pUtupspG/GM+9nZ88zgJcp6Zk=github.com/mattn/go-sqlite3 v1.14.34/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=@@ -350,6 +358,14 @@ github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFgithub.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=github.com/olahol/melody v1.4.0 h1:Pa5SdeZL/zXPi1tJuMAPDbl4n3gQOThSL6G1p4qZ4SI=github.com/olahol/melody v1.4.0/go.mod h1:GgkTl6Y7yWj/HtfD48Q5vLKPVoZOH+Qqgfa7CvJgJM4=+github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 h1:zrbMGy9YXpIeTnGj4EljqMiZsIcE09mmF8XsD5AYOJc=+github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6/go.mod h1:rEKTHC9roVVicUIfZK7DYrdIoM0EOr8mK1Hj5s3JjH0=+github.com/olekukonko/errors v1.1.0 h1:RNuGIh15QdDenh+hNvKrJkmxxjV4hcS50Db478Ou5sM=+github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=+github.com/olekukonko/ll v0.1.4-0.20260115111900-9e59c2286df0 h1:jrYnow5+hy3WRDCBypUFvVKNSPPCdqgSXIE9eJDD8LM=+github.com/olekukonko/ll v0.1.4-0.20260115111900-9e59c2286df0/go.mod h1:b52bVQRRPObe+yyBl0TxNfhesL0nedD4Cht0/zx55Ew=+github.com/olekukonko/tablewriter v1.1.3 h1:VSHhghXxrP0JHl+0NnKid7WoEmd9/urKRJLysb70nnA=+github.com/olekukonko/tablewriter v1.1.3/go.mod h1:9VU0knjhmMkXjnMKrZ3+L2JhhtsQ/L38BbL3CRNE8tM=github.com/onsi/ginkgo/v2 v2.9.2 h1:BA2GMJOtfGAfagzYtrAlufIP0lq6QERkFmHLMLPwFSU=github.com/onsi/ginkgo/v2 v2.9.2/go.mod h1:WHcJJG2dIlcCqVfBAwUCrJxSPFb6v4azBwgxeMeDuts=github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=@@ -393,6 +409,10 @@ github.com/shirou/gopsutil/v4 v4.26.5 h1:RPcBXkpz7kOj9PqGFQOlBPZHsyaPvPVQc098y9Rgithub.com/shirou/gopsutil/v4 v4.26.5/go.mod h1:LZ6ewCSkBqUpvSOf+LsTGnRinC6iaNUNMGBtDkJBaLQ=github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=+github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=+github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=+github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=+github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=github.com/spiffe/go-spiffe/v2 v2.6.0 h1:l+DolpxNWYgruGQVV0xsfeya3CsC7m8iBzDnMpsbLuo=github.com/spiffe/go-spiffe/v2 v2.6.0/go.mod h1:gm2SeUoMZEtpnzPNs2Csc0D/gX33k1xIx7lEzqblHEs=github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=diff --git a/backend/internal/data/ent/migrate/schema.go b/backend/internal/data/ent/migrate/schema.goindex 47a90066..b214fbc8 100644--- a/backend/internal/data/ent/migrate/schema.go+++ b/backend/internal/data/ent/migrate/schema.go@@ -492,7 +492,7 @@ var ({Name: "token", Type: field.TypeBytes, Unique: true},{Name: "expires_at", Type: field.TypeTime},{Name: "used_at", Type: field.TypeTime, Nullable: true},- {Name: "user_password_reset_tokens", Type: field.TypeUUID},+ {Name: "user_id", Type: field.TypeUUID},}// PasswordResetTokensTable holds the schema information for the "password_reset_tokens" table.PasswordResetTokensTable = &schema.Table{diff --git a/backend/internal/data/ent/mutation.go b/backend/internal/data/ent/mutation.goindex 47ee0234..70dbae1d 100644--- a/backend/internal/data/ent/mutation.go+++ b/backend/internal/data/ent/mutation.go@@ -13124,6 +13124,42 @@ func (m *PasswordResetTokensMutation) ResetUpdatedAt() {m.updated_at = nil}+// SetUserID sets the "user_id" field.+func (m *PasswordResetTokensMutation) SetUserID(u uuid.UUID) {+ m.user = &u+}++// UserID returns the value of the "user_id" field in the mutation.+func (m *PasswordResetTokensMutation) UserID() (r uuid.UUID, exists bool) {+ v := m.user+ if v == nil {+ return+ }+ return *v, true+}++// OldUserID returns the old "user_id" field's value of the PasswordResetTokens entity.+// If the PasswordResetTokens object wasn't provided to the builder, the object is fetched from the database.+// An error is returned if the mutation operation is not UpdateOne, or the database query fails.+func (m *PasswordResetTokensMutation) OldUserID(ctx context.Context) (v uuid.UUID, err error) {+ if !m.op.Is(OpUpdateOne) {+ return v, errors.New("OldUserID is only allowed on UpdateOne operations")+ }+ if m.id == nil || m.oldValue == nil {+ return v, errors.New("OldUserID requires an ID field in the mutation")+ }+ oldValue, err := m.oldValue(ctx)+ if err != nil {+ return v, fmt.Errorf("querying old value for OldUserID: %w", err)+ }+ return oldValue.UserID, nil+}++// ResetUserID resets all changes to the "user_id" field.+func (m *PasswordResetTokensMutation) ResetUserID() {+ m.user = nil+}+// SetToken sets the "token" field.func (m *PasswordResetTokensMutation) SetToken(b []byte) {m.token = &b@@ -13245,14 +13281,10 @@ func (m *PasswordResetTokensMutation) ResetUsedAt() {delete(m.clearedFields, passwordresettokens.FieldUsedAt)}-// SetUserID sets the "user" edge to the User entity by id.-func (m *PasswordResetTokensMutation) SetUserID(id uuid.UUID) {- m.user = &id-}-// ClearUser clears the "user" edge to the User entity.func (m *PasswordResetTokensMutation) ClearUser() {m.cleareduser = true+ m.clearedFields[passwordresettokens.FieldUserID] = struct{}{}}// UserCleared reports if the "user" edge to the User entity was cleared.@@ -13260,14 +13292,6 @@ func (m *PasswordResetTokensMutation) UserCleared() bool {return m.cleareduser}-// UserID returns the "user" edge ID in the mutation.-func (m *PasswordResetTokensMutation) UserID() (id uuid.UUID, exists bool) {- if m.user != nil {- return *m.user, true- }- return-}-// UserIDs returns the "user" edge IDs in the mutation.// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use// UserID instead. It exists only for internal usage by the builders.@@ -13318,13 +13342,16 @@ func (m *PasswordResetTokensMutation) Type() string {// order to get all numeric fields that were incremented/decremented, call// AddedFields().func (m *PasswordResetTokensMutation) Fields() []string {- fields := make([]string, 0, 5)+ fields := make([]string, 0, 6)if m.created_at != nil {fields = append(fields, passwordresettokens.FieldCreatedAt)}if m.updated_at != nil {fields = append(fields, passwordresettokens.FieldUpdatedAt)}+ if m.user != nil {+ fields = append(fields, passwordresettokens.FieldUserID)+ }if m.token != nil {fields = append(fields, passwordresettokens.FieldToken)}@@ -13346,6 +13373,8 @@ func (m *PasswordResetTokensMutation) Field(name string) (ent.Value, bool) {return m.CreatedAt()case passwordresettokens.FieldUpdatedAt:return m.UpdatedAt()+ case passwordresettokens.FieldUserID:+ return m.UserID()case passwordresettokens.FieldToken:return m.Token()case passwordresettokens.FieldExpiresAt:@@ -13365,6 +13394,8 @@ func (m *PasswordResetTokensMutation) OldField(ctx context.Context, name string)return m.OldCreatedAt(ctx)case passwordresettokens.FieldUpdatedAt:return m.OldUpdatedAt(ctx)+ case passwordresettokens.FieldUserID:+ return m.OldUserID(ctx)case passwordresettokens.FieldToken:return m.OldToken(ctx)case passwordresettokens.FieldExpiresAt:@@ -13394,6 +13425,13 @@ func (m *PasswordResetTokensMutation) SetField(name string, value ent.Value) err}m.SetUpdatedAt(v)return nil+ case passwordresettokens.FieldUserID:+ v, ok := value.(uuid.UUID)+ if !ok {+ return fmt.Errorf("unexpected type %T for field %s", value, name)+ }+ m.SetUserID(v)+ return nilcase passwordresettokens.FieldToken:v, ok := value.([]byte)if !ok {@@ -13479,6 +13517,9 @@ func (m *PasswordResetTokensMutation) ResetField(name string) error {case passwordresettokens.FieldUpdatedAt:m.ResetUpdatedAt()return nil+ case passwordresettokens.FieldUserID:+ m.ResetUserID()+ return nilcase passwordresettokens.FieldToken:m.ResetToken()return nildiff --git a/backend/internal/data/ent/passwordresettokens.go b/backend/internal/data/ent/passwordresettokens.goindex ee4254b6..942550c6 100644--- a/backend/internal/data/ent/passwordresettokens.go+++ b/backend/internal/data/ent/passwordresettokens.go@@ -23,6 +23,8 @@ type PasswordResetTokens struct {CreatedAt time.Time `json:"created_at,omitempty"`// UpdatedAt holds the value of the "updated_at" field.UpdatedAt time.Time `json:"updated_at,omitempty"`+ // UserID holds the value of the "user_id" field.+ UserID uuid.UUID `json:"user_id,omitempty"`// Token holds the value of the "token" field.Token []byte `json:"token,omitempty"`// ExpiresAt holds the value of the "expires_at" field.@@ -31,9 +33,8 @@ type PasswordResetTokens struct {UsedAt *time.Time `json:"used_at,omitempty"`// Edges holds the relations/edges for other nodes in the graph.// The values are being populated by the PasswordResetTokensQuery when eager-loading is set.- Edges PasswordResetTokensEdges `json:"edges"`- user_password_reset_tokens *uuid.UUID- selectValues sql.SelectValues+ Edges PasswordResetTokensEdges `json:"edges"`+ selectValues sql.SelectValues}// PasswordResetTokensEdges holds the relations/edges for other nodes in the graph.@@ -65,10 +66,8 @@ func (*PasswordResetTokens) scanValues(columns []string) ([]any, error) {values[i] = new([]byte)case passwordresettokens.FieldCreatedAt, passwordresettokens.FieldUpdatedAt, passwordresettokens.FieldExpiresAt, passwordresettokens.FieldUsedAt:values[i] = new(sql.NullTime)- case passwordresettokens.FieldID:+ case passwordresettokens.FieldID, passwordresettokens.FieldUserID:values[i] = new(uuid.UUID)- case passwordresettokens.ForeignKeys[0]: // user_password_reset_tokens- values[i] = &sql.NullScanner{S: new(uuid.UUID)}default:values[i] = new(sql.UnknownType)}@@ -102,6 +101,12 @@ func (_m *PasswordResetTokens) assignValues(columns []string, values []any) erro} else if value.Valid {_m.UpdatedAt = value.Time}+ case passwordresettokens.FieldUserID:+ if value, ok := values[i].(*uuid.UUID); !ok {+ return fmt.Errorf("unexpected type %T for field user_id", values[i])+ } else if value != nil {+ _m.UserID = *value+ }case passwordresettokens.FieldToken:if value, ok := values[i].(*[]byte); !ok {return fmt.Errorf("unexpected type %T for field token", values[i])@@ -121,13 +126,6 @@ func (_m *PasswordResetTokens) assignValues(columns []string, values []any) erro_m.UsedAt = new(time.Time)*_m.UsedAt = value.Time}- case passwordresettokens.ForeignKeys[0]:- if value, ok := values[i].(*sql.NullScanner); !ok {- return fmt.Errorf("unexpected type %T for field user_password_reset_tokens", values[i])- } else if value.Valid {- _m.user_password_reset_tokens = new(uuid.UUID)- *_m.user_password_reset_tokens = *value.S.(*uuid.UUID)- }default:_m.selectValues.Set(columns[i], values[i])}@@ -175,6 +173,9 @@ func (_m *PasswordResetTokens) String() string {builder.WriteString("updated_at=")builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))builder.WriteString(", ")+ builder.WriteString("user_id=")+ builder.WriteString(fmt.Sprintf("%v", _m.UserID))+ builder.WriteString(", ")builder.WriteString("token=")builder.WriteString(fmt.Sprintf("%v", _m.Token))builder.WriteString(", ")diff --git a/backend/internal/data/ent/passwordresettokens/passwordresettokens.go b/backend/internal/data/ent/passwordresettokens/passwordresettokens.goindex b793452f..ca779984 100644--- a/backend/internal/data/ent/passwordresettokens/passwordresettokens.go+++ b/backend/internal/data/ent/passwordresettokens/passwordresettokens.go@@ -19,6 +19,8 @@ const (FieldCreatedAt = "created_at"// FieldUpdatedAt holds the string denoting the updated_at field in the database.FieldUpdatedAt = "updated_at"+ // FieldUserID holds the string denoting the user_id field in the database.+ FieldUserID = "user_id"// FieldToken holds the string denoting the token field in the database.FieldToken = "token"// FieldExpiresAt holds the string denoting the expires_at field in the database.@@ -35,7 +37,7 @@ const (// It exists in this package in order to avoid circular dependency with the "user" package.UserInverseTable = "users"// UserColumn is the table column denoting the user relation/edge.- UserColumn = "user_password_reset_tokens"+ UserColumn = "user_id")// Columns holds all SQL columns for passwordresettokens fields.@@ -43,17 +45,12 @@ var Columns = []string{FieldID,FieldCreatedAt,FieldUpdatedAt,+ FieldUserID,FieldToken,FieldExpiresAt,FieldUsedAt,}-// ForeignKeys holds the SQL foreign-keys that are owned by the "password_reset_tokens"-// table and are not defined as standalone fields in the schema.-var ForeignKeys = []string{- "user_password_reset_tokens",-}-// ValidColumn reports if the column name is valid (part of the table columns).func ValidColumn(column string) bool {for i := range Columns {@@ -61,11 +58,6 @@ func ValidColumn(column string) bool {return true}}- for i := range ForeignKeys {- if column == ForeignKeys[i] {- return true- }- }return false}@@ -100,6 +92,11 @@ func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()}+// ByUserID orders the results by the user_id field.+func ByUserID(opts ...sql.OrderTermOption) OrderOption {+ return sql.OrderByField(FieldUserID, opts...).ToFunc()+}+// ByExpiresAt orders the results by the expires_at field.func ByExpiresAt(opts ...sql.OrderTermOption) OrderOption {return sql.OrderByField(FieldExpiresAt, opts...).ToFunc()diff --git a/backend/internal/data/ent/passwordresettokens/where.go b/backend/internal/data/ent/passwordresettokens/where.goindex d29acf34..7e7070ee 100644--- a/backend/internal/data/ent/passwordresettokens/where.go+++ b/backend/internal/data/ent/passwordresettokens/where.go@@ -66,6 +66,11 @@ func UpdatedAt(v time.Time) predicate.PasswordResetTokens {return predicate.PasswordResetTokens(sql.FieldEQ(FieldUpdatedAt, v))}+// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.+func UserID(v uuid.UUID) predicate.PasswordResetTokens {+ return predicate.PasswordResetTokens(sql.FieldEQ(FieldUserID, v))+}+// Token applies equality check predicate on the "token" field. It's identical to TokenEQ.func Token(v []byte) predicate.PasswordResetTokens {return predicate.PasswordResetTokens(sql.FieldEQ(FieldToken, v))@@ -161,6 +166,26 @@ func UpdatedAtLTE(v time.Time) predicate.PasswordResetTokens {return predicate.PasswordResetTokens(sql.FieldLTE(FieldUpdatedAt, v))}+// UserIDEQ applies the EQ predicate on the "user_id" field.+func UserIDEQ(v uuid.UUID) predicate.PasswordResetTokens {+ return predicate.PasswordResetTokens(sql.FieldEQ(FieldUserID, v))+}++// UserIDNEQ applies the NEQ predicate on the "user_id" field.+func UserIDNEQ(v uuid.UUID) predicate.PasswordResetTokens {+ return predicate.PasswordResetTokens(sql.FieldNEQ(FieldUserID, v))+}++// UserIDIn applies the In predicate on the "user_id" field.+func UserIDIn(vs ...uuid.UUID) predicate.PasswordResetTokens {+ return predicate.PasswordResetTokens(sql.FieldIn(FieldUserID, vs...))+}++// UserIDNotIn applies the NotIn predicate on the "user_id" field.+func UserIDNotIn(vs ...uuid.UUID) predicate.PasswordResetTokens {+ return predicate.PasswordResetTokens(sql.FieldNotIn(FieldUserID, vs...))+}+// TokenEQ applies the EQ predicate on the "token" field.func TokenEQ(v []byte) predicate.PasswordResetTokens {return predicate.PasswordResetTokens(sql.FieldEQ(FieldToken, v))diff --git a/backend/internal/data/ent/passwordresettokens_create.go b/backend/internal/data/ent/passwordresettokens_create.goindex eeb3887b..90e9f224 100644--- a/backend/internal/data/ent/passwordresettokens_create.go+++ b/backend/internal/data/ent/passwordresettokens_create.go@@ -50,6 +50,12 @@ func (_c *PasswordResetTokensCreate) SetNillableUpdatedAt(v *time.Time) *Passworreturn _c}+// SetUserID sets the "user_id" field.+func (_c *PasswordResetTokensCreate) SetUserID(v uuid.UUID) *PasswordResetTokensCreate {+ _c.mutation.SetUserID(v)+ return _c+}+// SetToken sets the "token" field.func (_c *PasswordResetTokensCreate) SetToken(v []byte) *PasswordResetTokensCreate {_c.mutation.SetToken(v)@@ -98,12 +104,6 @@ func (_c *PasswordResetTokensCreate) SetNillableID(v *uuid.UUID) *PasswordResetTreturn _c}-// SetUserID sets the "user" edge to the User entity by ID.-func (_c *PasswordResetTokensCreate) SetUserID(id uuid.UUID) *PasswordResetTokensCreate {- _c.mutation.SetUserID(id)- return _c-}-// SetUser sets the "user" edge to the User entity.func (_c *PasswordResetTokensCreate) SetUser(v *User) *PasswordResetTokensCreate {return _c.SetUserID(v.ID)@@ -170,6 +170,9 @@ func (_c *PasswordResetTokensCreate) check() error {if _, ok := _c.mutation.UpdatedAt(); !ok {return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "PasswordResetTokens.updated_at"`)}}+ if _, ok := _c.mutation.UserID(); !ok {+ return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "PasswordResetTokens.user_id"`)}+ }if _, ok := _c.mutation.Token(); !ok {return &ValidationError{Name: "token", err: errors.New(`ent: missing required field "PasswordResetTokens.token"`)}}@@ -248,7 +251,7 @@ func (_c *PasswordResetTokensCreate) createSpec() (*PasswordResetTokens, *sqlgrafor _, k := range nodes {edge.Target.Nodes = append(edge.Target.Nodes, k)}- _node.user_password_reset_tokens = &nodes[0]+ _node.UserID = nodes[0]_spec.Edges = append(_spec.Edges, edge)}return _node, _specdiff --git a/backend/internal/data/ent/passwordresettokens_query.go b/backend/internal/data/ent/passwordresettokens_query.goindex d684b9a8..59863a80 100644--- a/backend/internal/data/ent/passwordresettokens_query.go+++ b/backend/internal/data/ent/passwordresettokens_query.go@@ -25,7 +25,6 @@ type PasswordResetTokensQuery struct {inters []Interceptorpredicates []predicate.PasswordResetTokenswithUser *UserQuery- withFKs bool// intermediate query (i.e. traversal path).sql *sql.Selectorpath func(context.Context) (*sql.Selector, error)@@ -371,18 +370,11 @@ func (_q *PasswordResetTokensQuery) prepareQuery(ctx context.Context) error {func (_q *PasswordResetTokensQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*PasswordResetTokens, error) {var (nodes = []*PasswordResetTokens{}- withFKs = _q.withFKs_spec = _q.querySpec()loadedTypes = [1]bool{_q.withUser != nil,})- if _q.withUser != nil {- withFKs = true- }- if withFKs {- _spec.Node.Columns = append(_spec.Node.Columns, passwordresettokens.ForeignKeys...)- }_spec.ScanValues = func(columns []string) ([]any, error) {return (*PasswordResetTokens).scanValues(nil, columns)}@@ -414,10 +406,7 @@ func (_q *PasswordResetTokensQuery) loadUser(ctx context.Context, query *UserQueids := make([]uuid.UUID, 0, len(nodes))nodeids := make(map[uuid.UUID][]*PasswordResetTokens)for i := range nodes {- if nodes[i].user_password_reset_tokens == nil {- continue- }- fk := *nodes[i].user_password_reset_tokens+ fk := nodes[i].UserIDif _, ok := nodeids[fk]; !ok {ids = append(ids, fk)}@@ -434,7 +423,7 @@ func (_q *PasswordResetTokensQuery) loadUser(ctx context.Context, query *UserQuefor _, n := range neighbors {nodes, ok := nodeids[n.ID]if !ok {- return fmt.Errorf(`unexpected foreign-key "user_password_reset_tokens" returned %v`, n.ID)+ return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)}for i := range nodes {assign(nodes[i], n)@@ -468,6 +457,9 @@ func (_q *PasswordResetTokensQuery) querySpec() *sqlgraph.QuerySpec {_spec.Node.Columns = append(_spec.Node.Columns, fields[i])}}+ if _q.withUser != nil {+ _spec.Node.AddColumnOnce(passwordresettokens.FieldUserID)+ }}if ps := _q.predicates; len(ps) > 0 {_spec.Predicate = func(selector *sql.Selector) {diff --git a/backend/internal/data/ent/passwordresettokens_update.go b/backend/internal/data/ent/passwordresettokens_update.goindex 94f08c16..95931284 100644--- a/backend/internal/data/ent/passwordresettokens_update.go+++ b/backend/internal/data/ent/passwordresettokens_update.go@@ -36,6 +36,20 @@ func (_u *PasswordResetTokensUpdate) SetUpdatedAt(v time.Time) *PasswordResetTokreturn _u}+// SetUserID sets the "user_id" field.+func (_u *PasswordResetTokensUpdate) SetUserID(v uuid.UUID) *PasswordResetTokensUpdate {+ _u.mutation.SetUserID(v)+ return _u+}++// SetNillableUserID sets the "user_id" field if the given value is not nil.+func (_u *PasswordResetTokensUpdate) SetNillableUserID(v *uuid.UUID) *PasswordResetTokensUpdate {+ if v != nil {+ _u.SetUserID(*v)+ }+ return _u+}+// SetToken sets the "token" field.func (_u *PasswordResetTokensUpdate) SetToken(v []byte) *PasswordResetTokensUpdate {_u.mutation.SetToken(v)@@ -76,12 +90,6 @@ func (_u *PasswordResetTokensUpdate) ClearUsedAt() *PasswordResetTokensUpdate {return _u}-// SetUserID sets the "user" edge to the User entity by ID.-func (_u *PasswordResetTokensUpdate) SetUserID(id uuid.UUID) *PasswordResetTokensUpdate {- _u.mutation.SetUserID(id)- return _u-}-// SetUser sets the "user" edge to the User entity.func (_u *PasswordResetTokensUpdate) SetUser(v *User) *PasswordResetTokensUpdate {return _u.SetUserID(v.ID)@@ -224,6 +232,20 @@ func (_u *PasswordResetTokensUpdateOne) SetUpdatedAt(v time.Time) *PasswordResetreturn _u}+// SetUserID sets the "user_id" field.+func (_u *PasswordResetTokensUpdateOne) SetUserID(v uuid.UUID) *PasswordResetTokensUpdateOne {+ _u.mutation.SetUserID(v)+ return _u+}++// SetNillableUserID sets the "user_id" field if the given value is not nil.+func (_u *PasswordResetTokensUpdateOne) SetNillableUserID(v *uuid.UUID) *PasswordResetTokensUpdateOne {+ if v != nil {+ _u.SetUserID(*v)+ }+ return _u+}+// SetToken sets the "token" field.func (_u *PasswordResetTokensUpdateOne) SetToken(v []byte) *PasswordResetTokensUpdateOne {_u.mutation.SetToken(v)@@ -264,12 +286,6 @@ func (_u *PasswordResetTokensUpdateOne) ClearUsedAt() *PasswordResetTokensUpdatereturn _u}-// SetUserID sets the "user" edge to the User entity by ID.-func (_u *PasswordResetTokensUpdateOne) SetUserID(id uuid.UUID) *PasswordResetTokensUpdateOne {- _u.mutation.SetUserID(id)- return _u-}-// SetUser sets the "user" edge to the User entity.func (_u *PasswordResetTokensUpdateOne) SetUser(v *User) *PasswordResetTokensUpdateOne {return _u.SetUserID(v.ID)diff --git a/backend/internal/data/ent/runtime.go b/backend/internal/data/ent/runtime.goindex 41619843..d34282c3 100644--- a/backend/internal/data/ent/runtime.go+++ b/backend/internal/data/ent/runtime.go@@ -645,7 +645,7 @@ func init() {// passwordresettokens.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.passwordresettokens.UpdateDefaultUpdatedAt = passwordresettokensDescUpdatedAt.UpdateDefault.(func() time.Time)// passwordresettokensDescExpiresAt is the schema descriptor for expires_at field.- passwordresettokensDescExpiresAt := passwordresettokensFields[1].Descriptor()+ passwordresettokensDescExpiresAt := passwordresettokensFields[2].Descriptor()// passwordresettokens.DefaultExpiresAt holds the default value on creation for the expires_at field.passwordresettokens.DefaultExpiresAt = passwordresettokensDescExpiresAt.Default.(func() time.Time)// passwordresettokensDescID is the schema descriptor for id field.diff --git a/backend/internal/data/ent/schema/password_reset_tokens.go b/backend/internal/data/ent/schema/password_reset_tokens.goindex c21d463a..5f78e189 100644--- a/backend/internal/data/ent/schema/password_reset_tokens.go+++ b/backend/internal/data/ent/schema/password_reset_tokens.go@@ -8,6 +8,7 @@ import ("entgo.io/ent/schema/edge""entgo.io/ent/schema/field""entgo.io/ent/schema/index"+ "github.com/google/uuid""github.com/sysadminsmedia/homebox/backend/internal/data/ent/schema/mixins")@@ -26,6 +27,10 @@ func (PasswordResetTokens) Mixin() []ent.Mixin {func (PasswordResetTokens) Fields() []ent.Field {return []ent.Field{+ // user_id backs the `user` edge. It must match the column name created+ // by the released migration (20260512000000), so the edge is bound to+ // this field rather than ent's default `user_password_reset_tokens`.+ field.UUID("user_id", uuid.UUID{}),field.Bytes("token").Unique(),field.Time("expires_at").@@ -40,6 +45,7 @@ func (PasswordResetTokens) Edges() []ent.Edge {return []ent.Edge{edge.From("user", User.Type).Ref("password_reset_tokens").+ Field("user_id").Unique().Required().Annotations(entsql.Annotation{diff --git a/backend/internal/data/ent/user/user.go b/backend/internal/data/ent/user/user.goindex a9acadd3..b5b5330b 100644--- a/backend/internal/data/ent/user/user.go+++ b/backend/internal/data/ent/user/user.go@@ -71,7 +71,7 @@ const (// It exists in this package in order to avoid circular dependency with the "passwordresettokens" package.PasswordResetTokensInverseTable = "password_reset_tokens"// PasswordResetTokensColumn is the table column denoting the password_reset_tokens relation/edge.- PasswordResetTokensColumn = "user_password_reset_tokens"+ PasswordResetTokensColumn = "user_id"// APIKeysTable is the table that holds the api_keys relation/edge.APIKeysTable = "api_keys"// APIKeysInverseTable is the table name for the APIKey entity.diff --git a/backend/internal/data/ent/user_query.go b/backend/internal/data/ent/user_query.goindex a830f799..7c655471 100644--- a/backend/internal/data/ent/user_query.go+++ b/backend/internal/data/ent/user_query.go@@ -728,7 +728,9 @@ func (_q *UserQuery) loadPasswordResetTokens(ctx context.Context, query *Passworinit(nodes[i])}}- query.withFKs = true+ if len(query.ctx.Fields) > 0 {+ query.ctx.AppendFieldOnce(passwordresettokens.FieldUserID)+ }query.Where(predicate.PasswordResetTokens(func(s *sql.Selector) {s.Where(sql.InValues(s.C(user.PasswordResetTokensColumn), fks...))}))@@ -737,13 +739,10 @@ func (_q *UserQuery) loadPasswordResetTokens(ctx context.Context, query *Passworreturn err}for _, n := range neighbors {- fk := n.user_password_reset_tokens- if fk == nil {- return fmt.Errorf(`foreign-key "user_password_reset_tokens" is nil for node %v`, n.ID)- }- node, ok := nodeids[*fk]+ fk := n.UserID+ node, ok := nodeids[fk]if !ok {- return fmt.Errorf(`unexpected referenced foreign-key "user_password_reset_tokens" returned %v for node %v`, *fk, n.ID)+ return fmt.Errorf(`unexpected referenced foreign-key "user_id" returned %v for node %v`, fk, n.ID)}assign(node, n)}diff --git a/backend/internal/data/repo/repo_entities.go b/backend/internal/data/repo/repo_entities.goindex c92b1777..2f550010 100644--- a/backend/internal/data/repo/repo_entities.go+++ b/backend/internal/data/repo/repo_entities.go@@ -1101,6 +1101,18 @@ func (r *EntityRepository) CreateFromTemplate(ctx context.Context, gid uuid.UUIDreturn EntityOut{}, err}+ // entity_type is a required edge. The user-selected type takes precedence;+ // fall back to the group's default item type when none was provided so+ // creation from a template doesn't fail the required-edge validation.+ if data.EntityTypeID == uuid.Nil {+ etID, err := r.resolveDefaultEntityType(ctx, gid, false)+ if err != nil {+ recordSpanError(span, err)+ return EntityOut{}, err+ }+ data.EntityTypeID = etID+ }+tx, err := r.db.Tx(ctx)if err != nil {recordSpanError(span, err)@@ -1146,9 +1158,7 @@ func (r *EntityRepository) CreateFromTemplate(ctx context.Context, gid uuid.UUIDentityBuilder.SetParentID(data.ParentID)}- if data.EntityTypeID != uuid.Nil {- entityBuilder.SetEntityTypeID(data.EntityTypeID)- }+ entityBuilder.SetEntityTypeID(data.EntityTypeID)if len(data.TagIDs) > 0 {entityBuilder.AddTagIDs(data.TagIDs...)diff --git a/backend/internal/data/repo/repo_entities_test.go b/backend/internal/data/repo/repo_entities_test.goindex 3f8d2221..8917f047 100644--- a/backend/internal/data/repo/repo_entities_test.go+++ b/backend/internal/data/repo/repo_entities_test.go@@ -450,6 +450,69 @@ func TestEntityRepository_CreateFromTemplate_RejectsNonFiniteQuantity(t *testingrequire.NoError(t, err)}+// TestEntityRepository_CreateFromTemplate_DefaultsEntityType verifies that+// creating an entity from a template without an explicit entity type still+// succeeds and resolves the group's default item type, rather than failing the+// required entity_type edge (regression test for #1548).+func TestEntityRepository_CreateFromTemplate_DefaultsEntityType(t *testing.T) {+ containerET := useContainerEntityType(t)++ cf := containerFactory()+ cf.EntityTypeID = containerET.ID+ container, err := tRepos.Entities.Create(context.Background(), tGroup.ID, cf)+ require.NoError(t, err)++ out, err := tRepos.Entities.CreateFromTemplate(context.Background(), tGroup.ID, EntityCreateFromTemplate{+ Name: fk.Str(10),+ Description: fk.Str(20),+ Quantity: 1,+ ParentID: container.ID,+ // EntityTypeID intentionally left zero to exercise the fallback.+ })+ require.NoError(t, err)+ require.NotNil(t, out.EntityType)+ assert.False(t, out.EntityType.IsLocation)++ // Cleanup+ err = tRepos.Entities.Delete(context.Background(), out.ID)+ require.NoError(t, err)+ err = tRepos.Entities.Delete(context.Background(), container.ID)+ require.NoError(t, err)+}++// TestEntityRepository_CreateFromTemplate_UsesSelectedEntityType verifies that+// the user-selected entity type takes precedence over the default fallback.+func TestEntityRepository_CreateFromTemplate_UsesSelectedEntityType(t *testing.T) {+ containerET := useContainerEntityType(t)++ cf := containerFactory()+ cf.EntityTypeID = containerET.ID+ container, err := tRepos.Entities.Create(context.Background(), tGroup.ID, cf)+ require.NoError(t, err)++ selectedET, err := tRepos.EntityTypes.Create(context.Background(), tGroup.ID, EntityTypeCreate{+ Name: fk.Str(10),+ })+ require.NoError(t, err)++ out, err := tRepos.Entities.CreateFromTemplate(context.Background(), tGroup.ID, EntityCreateFromTemplate{+ Name: fk.Str(10),+ Description: fk.Str(20),+ Quantity: 1,+ ParentID: container.ID,+ EntityTypeID: selectedET.ID,+ })+ require.NoError(t, err)+ require.NotNil(t, out.EntityType)+ assert.Equal(t, selectedET.ID, out.EntityType.ID)++ // Cleanup+ err = tRepos.Entities.Delete(context.Background(), out.ID)+ require.NoError(t, err)+ err = tRepos.Entities.Delete(context.Background(), container.ID)+ require.NoError(t, err)+}+func TestEntityRepository_GetAllCustomFields(t *testing.T) {const FieldsCount = 5diff --git a/backend/internal/sys/validate/notifier_url.go b/backend/internal/sys/validate/notifier_url.goindex 60d44502..846f5ed5 100644--- a/backend/internal/sys/validate/notifier_url.go+++ b/backend/internal/sys/validate/notifier_url.go@@ -66,53 +66,73 @@ func ValidateNotifierURL(notifierURL string, cfg *config.NotifierConf) error {}ips = checkIPs- // If AllowNets is configured, only allow IPs in those networks+ // If AllowNets is configured it acts as an allowlist: every IP must match,+ // and passing skips the remaining block checks.if len(cfg.AllowNets) > 0 {- for _, ip := range ips {- allowed := false- for _, allowNet := range cfg.AllowNets {- _, ipNet, err := net.ParseCIDR(allowNet)- if err != nil {- log.Warn().- Err(err).- Str("cidr", allowNet).- Str("config", "AllowNets").- Msg("invalid CIDR in notifier AllowNets configuration, skipping")- continue // Skip invalid CIDR- }- if ipNet.Contains(ip) {- allowed = true- break- }+ return checkAllowNets(ips, cfg.AllowNets)+ }++ // Check BlockNets - block specific networks if configured+ if len(cfg.BlockNets) > 0 {+ if err := checkBlockNets(ips, cfg.BlockNets); err != nil {+ return err+ }+ }++ return checkBlockedCategories(ips, cfg)+}++// checkAllowNets verifies every IP falls within one of the allowNets. A nil+// return means validation is complete and no further block checks are needed.+func checkAllowNets(ips []net.IP, allowNets []string) error {+ for _, ip := range ips {+ allowed := false+ for _, allowNet := range allowNets {+ _, ipNet, err := net.ParseCIDR(allowNet)+ if err != nil {+ log.Warn().+ Err(err).+ Str("cidr", allowNet).+ Str("config", "AllowNets").+ Msg("invalid CIDR in notifier AllowNets configuration, skipping")+ continue // Skip invalid CIDR}- if !allowed {- return fmt.Errorf("IP %s is not in the allowed networks", ip.String())+ if ipNet.Contains(ip) {+ allowed = true+ break}}- // If explicitly allowed, skip other checks- return nil+ if !allowed {+ return fmt.Errorf("IP %s is not in the allowed networks", ip.String())+ }}+ return nil+}- // Check BlockNets - block specific networks if configured- if len(cfg.BlockNets) > 0 {- for _, ip := range ips {- for _, blockNet := range cfg.BlockNets {- _, ipNet, err := net.ParseCIDR(blockNet)- if err != nil {- log.Warn().- Err(err).- Str("cidr", blockNet).- Str("config", "BlockNets").- Msg("invalid CIDR in notifier BlockNets configuration, skipping")- continue // Skip invalid CIDR- }- if ipNet.Contains(ip) {- return fmt.Errorf("IP %s is in a blocked network (%s)", ip.String(), blockNet)- }+// checkBlockNets returns an error if any IP falls within one of the blockNets.+func checkBlockNets(ips []net.IP, blockNets []string) error {+ for _, ip := range ips {+ for _, blockNet := range blockNets {+ _, ipNet, err := net.ParseCIDR(blockNet)+ if err != nil {+ log.Warn().+ Err(err).+ Str("cidr", blockNet).+ Str("config", "BlockNets").+ Msg("invalid CIDR in notifier BlockNets configuration, skipping")+ continue // Skip invalid CIDR+ }+ if ipNet.Contains(ip) {+ return fmt.Errorf("IP %s is in a blocked network (%s)", ip.String(), blockNet)}}}+ return nil+}+// checkBlockedCategories applies the configured category-based blocks+// (localhost, RFC1918, bogon, cloud metadata) to every IP.+func checkBlockedCategories(ips []net.IP, cfg *config.NotifierConf) error {for _, ip := range ips {// Block localhost if configuredif cfg.BlockLocalhost && isLocalhost(ip) {diff --git a/backend/internal/sys/validate/notifier_url_test.go b/backend/internal/sys/validate/notifier_url_test.goindex a05e8b4c..92134aba 100644--- a/backend/internal/sys/validate/notifier_url_test.go+++ b/backend/internal/sys/validate/notifier_url_test.go@@ -511,18 +511,19 @@ func TestExtractGenericURL(t *testing.T) {func TestEmbeddedIPv4(t *testing.T) {// Layout examples are taken from RFC 6052 section 2.4, all embedding 192.0.2.33.+ const rfc6052Embedded = "192.0.2.33"tests := []struct {name stringip stringprefixLen intexpected string // empty means extraction must fail}{- {"rfc6052_example_32", "2001:db8:c000:221::", 32, "192.0.2.33"},- {"rfc6052_example_40", "2001:db8:1c0:2:21::", 40, "192.0.2.33"},- {"rfc6052_example_48", "2001:db8:122:c000:2:2100::", 48, "192.0.2.33"},- {"rfc6052_example_56", "2001:db8:122:3c0:0:221::", 56, "192.0.2.33"},- {"rfc6052_example_64", "2001:db8:122:344:c0:2:2100::", 64, "192.0.2.33"},- {"rfc6052_example_96", "2001:db8:122:344::c000:221", 96, "192.0.2.33"},+ {"rfc6052_example_32", "2001:db8:c000:221::", 32, rfc6052Embedded},+ {"rfc6052_example_40", "2001:db8:1c0:2:21::", 40, rfc6052Embedded},+ {"rfc6052_example_48", "2001:db8:122:c000:2:2100::", 48, rfc6052Embedded},+ {"rfc6052_example_56", "2001:db8:122:3c0:0:221::", 56, rfc6052Embedded},+ {"rfc6052_example_64", "2001:db8:122:344:c0:2:2100::", 64, rfc6052Embedded},+ {"rfc6052_example_96", "2001:db8:122:344::c000:221", 96, rfc6052Embedded},{"well_known_prefix_96", "64:ff9b::a9fe:a9fe", 96, "169.254.169.254"},{"nonzero_u_octet_rejected", "2001:db8:122:344:ffc0:2:2100::", 64, ""},{"nonzero_suffix_rejected", "2001:db8:122:344:c0:2:2100:1", 64, ""},diff --git a/docs/public/api/openapi-3.0.json b/docs/public/api/openapi-3.0.jsonindex a16bb34b..f2474084 100644--- a/docs/public/api/openapi-3.0.json+++ b/docs/public/api/openapi-3.0.json@@ -6622,6 +6622,10 @@"type": "string","maxLength": 1000},+ "entityTypeId": {+ "description": "EntityTypeID is the entity type selected by the user. When set it takes\nprecedence; when empty the repository falls back to the group's default.",+ "type": "string"+ },"name": {"type": "string","maxLength": 255,diff --git a/docs/public/api/openapi-3.0.yaml b/docs/public/api/openapi-3.0.yamlindex 867abc4f..c074bb7b 100644--- a/docs/public/api/openapi-3.0.yaml+++ b/docs/public/api/openapi-3.0.yaml@@ -4250,6 +4250,13 @@ components:description:type: stringmaxLength: 1000+ entityTypeId:+ description: >-+ EntityTypeID is the entity type selected by the user. When set it+ takes++ precedence; when empty the repository falls back to the group's default.+ type: stringname:type: stringmaxLength: 255diff --git a/docs/public/api/swagger-2.0.json b/docs/public/api/swagger-2.0.jsonindex 257fa81d..666f56c4 100644--- a/docs/public/api/swagger-2.0.json+++ b/docs/public/api/swagger-2.0.json@@ -6380,6 +6380,10 @@"type": "string","maxLength": 1000},+ "entityTypeId": {+ "description": "EntityTypeID is the entity type selected by the user. When set it takes\nprecedence; when empty the repository falls back to the group's default.",+ "type": "string"+ },"name": {"type": "string","maxLength": 255,diff --git a/docs/public/api/swagger-2.0.yaml b/docs/public/api/swagger-2.0.yamlindex 6332c8ec..2f828070 100644--- a/docs/public/api/swagger-2.0.yaml+++ b/docs/public/api/swagger-2.0.yaml@@ -2196,6 +2196,11 @@ definitions:description:maxLength: 1000type: string+ entityTypeId:+ description: |-+ EntityTypeID is the entity type selected by the user. When set it takes+ precedence; when empty the repository falls back to the group's default.+ type: stringname:maxLength: 255minLength: 1diff --git a/frontend/components/Entity/CreateModal.vue b/frontend/components/Entity/CreateModal.vueindex 2bd813c3..ba1b8641 100644--- a/frontend/components/Entity/CreateModal.vue+++ b/frontend/components/Entity/CreateModal.vue@@ -322,6 +322,13 @@const et = entityTypes.value.find(t => t.id === typeId);selectedEntityType.value = et || null;+ // A template the user picked explicitly takes precedence over the entity+ // type's default template, so don't overwrite it when the type changes.+ // (Locations don't use templates, so they still clear it below.)+ if (templateUserSelected.value && !et?.isLocation) {+ return;+ }+// If the selected type has a default template and is not a location, auto-apply itif (et?.isLocation || !et?.defaultTemplateId || !et.defaultTemplate) {clearTemplate();@@ -355,6 +362,9 @@const focused = ref(false);const selectedTemplate = ref<EntityTemplateSummary | null>(null);const templateData = ref<EntityTemplateOut | null>(null);+ // Tracks whether the current template was chosen explicitly by the user (vs.+ // auto-applied from an entity type's default template). User selections win.+ const templateUserSelected = ref(false);const showTemplateDetails = ref(false);const form = reactive({location: locations.value && locations.value.length > 0 ? locations.value[0] : ({} as EntityOut),@@ -371,11 +381,14 @@if (!template) {// Template was deselected, clear template data and remove from storagetemplateData.value = null;+ templateUserSelected.value = false;form.quantity = 1;localStorage.removeItem(LAST_TEMPLATE_KEY);return;}+ templateUserSelected.value = true;+// Load full template detailsconst { data, error } = await api.templates.get(template.id);if (error || !data) {@@ -424,9 +437,11 @@return;}- // Set the template+ // Set the template. A restored template reflects the user's last explicit+ // choice, so treat it as user-selected for override purposes.selectedTemplate.value = { id: data.id, name: data.name, description: data.description } as EntityTemplateSummary;templateData.value = data;+ templateUserSelected.value = true;form.quantity = data.defaultQuantity;if (data.defaultName) {form.name = data.defaultName;@@ -450,6 +465,7 @@function clearTemplate() {selectedTemplate.value = null;templateData.value = null;+ templateUserSelected.value = false;showTemplateDetails.value = false;form.quantity = 1;localStorage.removeItem(LAST_TEMPLATE_KEY);@@ -562,7 +578,16 @@});async function create(close = true) {- if (!form.location?.id) {+ // An empty entityTypeId serializes to "" and fails UUID unmarshalling on the+ // backend, so block creation up front rather than firing a doomed request.+ if (!selectedEntityType.value?.id) {+ toast.error(t("components.entity.create_modal.toast.please_select_entity_type"));+ return;+ }++ // Items must live somewhere, but a top-level location has no parent, so the+ // parent location selector is optional when creating a location.+ if (!selectedEntityType.value?.isLocation && !form.location?.id) {toast.error(t("components.entity.create_modal.toast.please_select_location"));return;}@@ -587,7 +612,7 @@const result = await api.items.createLocation({name: form.name,description: form.description,- parentId: form.location ? form.location.id : null,+ parentId: form.location?.id || null,entityTypeId: selectedEntityType.value?.id || "",quantity: 1,tagIds: form.tags,@@ -602,6 +627,7 @@parentId: form.location.id as string,tagIds: form.tags,quantity: form.quantity,+ entityTypeId: selectedEntityType.value?.id || "",};const result = await api.templates.createItem(templateData.value.id, templateRequest);@@ -672,6 +698,7 @@form.tags = [];selectedTemplate.value = null;templateData.value = null;+ templateUserSelected.value = false;showTemplateDetails.value = false;focused.value = false;loading.value = false;diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.tsindex 5417d8e3..e59d220f 100644--- a/frontend/lib/api/types/data-contracts.ts+++ b/frontend/lib/api/types/data-contracts.ts@@ -1342,6 +1342,11 @@ export interface CreateRequest {export interface EntityTemplateCreateItemRequest {/** @maxLength 1000 */description: string;+ /**+ * EntityTypeID is the entity type selected by the user. When set it takes+ * precedence; when empty the repository falls back to the group's default.+ */+ entityTypeId: string;/*** @minLength 1* @maxLength 255diff --git a/frontend/locales/en.json b/frontend/locales/en.jsonindex f8018d6f..d88fe4dd 100644--- a/frontend/locales/en.json+++ b/frontend/locales/en.json@@ -193,6 +193,7 @@"create_success": "{type} created","failed_load_parent": "Failed to load parent item - please select manually","no_canvas_support": "Your browser doesn't support canvas operations",+ "please_select_entity_type": "Please select an entity type.","please_select_location": "Please select a location.","rotate_failed": "Failed to rotate image: { error }","rotate_process_failed": "Failed to process rotated image",