diff --git a/TODO b/TODO index 8fe8ab9..9e2085c 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,7 @@ - [x] Web UI - [x] i18n - [x] modals -- [] debug +- [x] debug - [x] swagger - [] comments - [] Nix Module diff --git a/controllers/domain.go b/controllers/domain.go index 273de25..c92a874 100644 --- a/controllers/domain.go +++ b/controllers/domain.go @@ -138,7 +138,7 @@ func DeleteDomain(id string) error { return err } - if err := (recordsDAO{}).Delete(tx, &models.Record[models.RecordContentDefault]{Zone: domain.WithDotEnd()}); err != nil { + if err := (recordsDAO{}).Delete(tx, &models.Record[models.RecordContentDefault]{}, &models.Record[models.RecordContentDefault]{Zone: domain.WithDotEnd()}); err != nil { tx.Rollback() return err } diff --git a/database/basedao.go b/database/basedao.go index cc634fb..dc47632 100644 --- a/database/basedao.go +++ b/database/basedao.go @@ -90,8 +90,13 @@ func (b BaseDAO[T]) UpdateOrCreate(db *gorm.DB, e T, cond ...T) (T, error) { return e, err } -func (BaseDAO[T]) Delete(db *gorm.DB, e T) error { - if err := db.Delete(e).Error; err != nil { +func (BaseDAO[T]) Delete(db *gorm.DB, e T, cond ...T) error { + tx := db + for _, c := range cond { + tx = tx.Where(c) + } + + if err := tx.Delete(e).Error; err != nil { return err } return nil diff --git a/models/record_types.go b/models/record_types.go index 0a5a0f5..2a078e2 100644 --- a/models/record_types.go +++ b/models/record_types.go @@ -59,7 +59,7 @@ type CNAMERecord struct { } func (r CNAMERecord) Validate() error { - if strings.HasSuffix(r.Host, ".") { + if !strings.HasSuffix(r.Host, ".") { return ErrNoDotSuffix } return nil @@ -70,7 +70,7 @@ type NSRecord struct { } func (r NSRecord) Validate() error { - if strings.HasSuffix(r.Host, ".") { + if !strings.HasSuffix(r.Host, ".") { return ErrNoDotSuffix } return nil @@ -81,7 +81,7 @@ type MXRecord struct { } func (r MXRecord) Validate() error { - if strings.HasSuffix(r.Host, ".") { + if !strings.HasSuffix(r.Host, ".") { return ErrNoDotSuffix } return nil @@ -92,7 +92,7 @@ type SRVRecord struct { } func (r SRVRecord) Validate() error { - if strings.HasPrefix(r.Target, ".") { + if !strings.HasPrefix(r.Target, ".") { return ErrNoDotSuffix } @@ -104,11 +104,7 @@ type SOARecord struct { } func (r SOARecord) Validate() error { - if strings.HasPrefix(r.MBox, ".") { - return ErrNoDotSuffix - } - - if strings.HasSuffix(r.Ns, ".") { + if !strings.HasSuffix(r.Ns, ".") { return ErrNoDotSuffix } diff --git a/server/handlers_records.go b/server/handlers_records.go index aca14a6..b2f7948 100644 --- a/server/handlers_records.go +++ b/server/handlers_records.go @@ -234,7 +234,7 @@ func updateRecord(c *gin.Context) { } domain := c.Param("domain") - if domain != record.Zone { + if domain != record.WithOutDotTail() { c.JSON(http.StatusBadRequest, Response{ Succeed: false, Message: "request body doesn't match URI", diff --git a/web/src/components/records/RecordEditModal.tsx b/web/src/components/records/RecordEditModal.tsx index b8e3b32..5d1ff18 100644 --- a/web/src/components/records/RecordEditModal.tsx +++ b/web/src/components/records/RecordEditModal.tsx @@ -227,6 +227,7 @@ export default function RecordEditModal({ open, record, onOk, onCancel, editReco validateTrigger='onBlur' > hidden name='id' /> + hidden name='zone' /> label={t('records.recordType')} required name='record_type'>