From 08c8d6cdafdc17118d1dd2c42ac967617d29753b Mon Sep 17 00:00:00 2001 From: wubijie Date: Tue, 19 Nov 2024 10:56:17 +0800 Subject: [PATCH] Modify the logic for viewing configuration details --- configmanage/server/internal/dnsfile.go | 7 ++++--- configmanage/server/internal/hostfile.go | 7 ++++--- configmanage/server/internal/repofile.go | 7 ++++--- configmanage/server/internal/ssh.go | 7 ++++--- configmanage/server/internal/sshd.go | 8 +++++--- configmanage/server/internal/sysctl.go | 7 ++++--- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/configmanage/server/internal/dnsfile.go b/configmanage/server/internal/dnsfile.go index 5cc8e1fd..64379d9b 100644 --- a/configmanage/server/internal/dnsfile.go +++ b/configmanage/server/internal/dnsfile.go @@ -16,7 +16,7 @@ type DNSFile struct { Name string `json:"name"` Content json.RawMessage `gorm:"type:json" json:"content"` Version string `gorm:"type:varchar(50)" json:"version"` - IsActive bool `json:"isactive"` + IsActive bool `gorm:"default:false" json:"isactive"` IsFromHost bool `gorm:"default:false" json:"isfromhost"` Hostuuid string `gorm:"type:varchar(50)" json:"hostuuid"` CreatedAt time.Time @@ -50,13 +50,14 @@ func (df *DNSFile) Add() error { ).Error } +// 根据配置uuid获取用户自己创建的配置信息 func GetDNSFileByInfoUUID(uuid string, isindex interface{}) (DNSFile, error) { var file DNSFile if isindex != nil { - err := db.MySQL().Model(&DNSFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&DNSFile{}).Where("config_info_uuid=? and is_from_host=0 and is_index = ?", uuid, isindex).Find(&file).Error return file, err } - err := db.MySQL().Model(&DNSFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&DNSFile{}).Where("config_info_uuid=? and is_from_host=0", uuid).Find(&file).Error return file, err } diff --git a/configmanage/server/internal/hostfile.go b/configmanage/server/internal/hostfile.go index b37b3408..91137280 100644 --- a/configmanage/server/internal/hostfile.go +++ b/configmanage/server/internal/hostfile.go @@ -16,7 +16,7 @@ type HostFile struct { Name string `json:"name"` Content json.RawMessage `gorm:"type:json" json:"content"` Version string `gorm:"type:varchar(50)" json:"version"` - IsActive bool `json:"isactive"` + IsActive bool `gorm:"default:false" json:"isactive"` IsFromHost bool `gorm:"default:false" json:"isfromhost"` Hostuuid string `gorm:"type:varchar(50)" json:"hostuuid"` CreatedAt time.Time @@ -50,13 +50,14 @@ func (hf *HostFile) Add() error { ).Error } +// 根据配置uuid获取用户自己创建的配置信息 func GetHostFileByInfoUUID(uuid string, isindex interface{}) (HostFile, error) { var file HostFile if isindex != nil { - err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=? and is_from_host=0 and is_index = ?", uuid, isindex).Find(&file).Error return file, err } - err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&HostFile{}).Where("config_info_uuid=? and is_from_host=0 ", uuid).Find(&file).Error return file, err } diff --git a/configmanage/server/internal/repofile.go b/configmanage/server/internal/repofile.go index 872962b4..adae5f92 100644 --- a/configmanage/server/internal/repofile.go +++ b/configmanage/server/internal/repofile.go @@ -16,7 +16,7 @@ type RepoFile struct { Name string `json:"name"` Content json.RawMessage `gorm:"type:json" json:"content"` Version string `gorm:"type:varchar(50)" json:"version"` - IsActive bool `json:"isactive"` + IsActive bool `gorm:"default:false" json:"isactive"` IsFromHost bool `gorm:"default:false" json:"isfromhost"` Hostuuid string `gorm:"type:varchar(50)" json:"hostuuid"` CreatedAt time.Time @@ -26,13 +26,14 @@ func (rf *RepoFile) Add() error { return db.MySQL().Save(&rf).Error } +// 根据配置uuid获取用户自己创建的配置信息 func GetRepoFileByInfoUUID(uuid string, isindex interface{}) (RepoFile, error) { var file RepoFile if isindex != nil { - err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=? and is_from_host=0 and is_index = ?", uuid, isindex).Find(&file).Error return file, err } - err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&RepoFile{}).Where("config_info_uuid=? and is_from_host=0", uuid).Find(&file).Error return file, err } diff --git a/configmanage/server/internal/ssh.go b/configmanage/server/internal/ssh.go index 2ea1c78b..d42dc49c 100644 --- a/configmanage/server/internal/ssh.go +++ b/configmanage/server/internal/ssh.go @@ -16,7 +16,7 @@ type SSHFile struct { Name string `json:"name"` Content json.RawMessage `gorm:"type:json" json:"content"` Version string `gorm:"type:varchar(50)" json:"version"` - IsActive bool `json:"isactive"` + IsActive bool `gorm:"default:false" json:"isactive"` IsFromHost bool `gorm:"default:false" json:"isfromhost"` Hostuuid string `gorm:"type:varchar(50)" json:"hostuuid"` CreatedAt time.Time @@ -26,13 +26,14 @@ func (sf *SSHFile) Add() error { return db.MySQL().Save(&sf).Error } +// 根据配置uuid获取用户自己创建的配置信息 func GetSSHFileByInfoUUID(uuid string, isindex interface{}) (SSHFile, error) { var file SSHFile if isindex != nil { - err := db.MySQL().Model(&SSHFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&SSHFile{}).Where("config_info_uuid=? and is_from_host=0 and is_index = ?", uuid, isindex).Find(&file).Error return file, err } - err := db.MySQL().Model(&SSHFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&SSHFile{}).Where("config_info_uuid=? and is_from_host=0", uuid).Find(&file).Error return file, err } diff --git a/configmanage/server/internal/sshd.go b/configmanage/server/internal/sshd.go index f91156da..f7d51fd7 100644 --- a/configmanage/server/internal/sshd.go +++ b/configmanage/server/internal/sshd.go @@ -16,7 +16,7 @@ type SSHDFile struct { Name string `json:"name"` Content json.RawMessage `gorm:"type:json" json:"content"` Version string `gorm:"type:varchar(50)" json:"version"` - IsActive bool `json:"isactive"` + IsActive bool `gorm:"default:false" json:"isactive"` IsFromHost bool `gorm:"default:false" json:"isfromhost"` Hostuuid string `gorm:"type:varchar(50)" json:"hostuuid"` CreatedAt time.Time @@ -25,13 +25,15 @@ type SSHDFile struct { func (sdf *SSHDFile) Add() error { return db.MySQL().Save(&sdf).Error } + +// 根据配置uuid获取用户自己创建的配置信息 func GetSSHDFileByInfoUUID(uuid string, isindex interface{}) (SSHDFile, error) { var file SSHDFile if isindex != nil { - err := db.MySQL().Model(&SSHDFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&SSHDFile{}).Where("config_info_uuid=? and is_from_host=0 and is_index = ?", uuid, isindex).Find(&file).Error return file, err } - err := db.MySQL().Model(&SSHDFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&SSHDFile{}).Where("config_info_uuid=? and is_from_host=0", uuid).Find(&file).Error return file, err } diff --git a/configmanage/server/internal/sysctl.go b/configmanage/server/internal/sysctl.go index 0aae2383..4d6220b1 100644 --- a/configmanage/server/internal/sysctl.go +++ b/configmanage/server/internal/sysctl.go @@ -16,7 +16,7 @@ type SysctlFile struct { Name string `json:"name"` Content json.RawMessage `gorm:"type:json" json:"content"` Version string `gorm:"type:varchar(50)" json:"version"` - IsActive bool `json:"isactive"` + IsActive bool `gorm:"default:false" json:"isactive"` IsFromHost bool `gorm:"default:false" json:"isfromhost"` Hostuuid string `gorm:"type:varchar(50)" json:"hostuuid"` CreatedAt time.Time @@ -26,13 +26,14 @@ func (sysf *SysctlFile) Add() error { return db.MySQL().Save(&sysf).Error } +// 根据配置uuid获取用户自己创建的配置信息 func GetSysctlFileByInfoUUID(uuid string, isindex interface{}) (SysctlFile, error) { var file SysctlFile if isindex != nil { - err := db.MySQL().Model(&SysctlFile{}).Where("config_info_uuid=? && is_index = ?", uuid, isindex).Find(&file).Error + err := db.MySQL().Model(&SysctlFile{}).Where("config_info_uuid=? and is_from_host=0 and is_index = ?", uuid, isindex).Find(&file).Error return file, err } - err := db.MySQL().Model(&SysctlFile{}).Where("config_info_uuid=?", uuid).Find(&file).Error + err := db.MySQL().Model(&SysctlFile{}).Where("config_info_uuid=? and is_from_host=0", uuid).Find(&file).Error return file, err } -- Gitee