Skip to content

Commit 03bfa6a

Browse files
committed
pref: Adjust node editing logic
1 parent 23a66af commit 03bfa6a

File tree

27 files changed

+403
-277
lines changed

27 files changed

+403
-277
lines changed

core/app/api/v2/upgrade.go

+22
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,25 @@ func (b *BaseApi) Upgrade(c *gin.Context) {
6565
}
6666
helper.SuccessWithData(c, nil)
6767
}
68+
69+
// @Tags System Setting
70+
// @Summary Upgrade
71+
// @Description 系统回滚
72+
// @Accept json
73+
// @Param request body dto.OperateByID true "request"
74+
// @Success 200
75+
// @Security ApiKeyAuth
76+
// @Router /core/settings/rollback [post]
77+
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"upgrade_logs","output_column":"old_version","output_value":"version"}],"formatZH":"回滚系统 => [version]","formatEN":"rollback system => [version]"}
78+
func (b *BaseApi) Rollback(c *gin.Context) {
79+
var req dto.OperateByID
80+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
81+
return
82+
}
83+
84+
if err := upgradeService.Rollback(req); err != nil {
85+
helper.InternalServer(c, err)
86+
return
87+
}
88+
helper.SuccessWithData(c, nil)
89+
}

core/app/repo/app_launcher.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ import (
88
type LauncherRepo struct{}
99

1010
type ILauncherRepo interface {
11-
Get(opts ...DBOption) (model.AppLauncher, error)
12-
List(opts ...DBOption) ([]model.AppLauncher, error)
11+
Get(opts ...global.DBOption) (model.AppLauncher, error)
12+
List(opts ...global.DBOption) ([]model.AppLauncher, error)
1313
Create(launcher *model.AppLauncher) error
14-
Delete(opts ...DBOption) error
14+
Delete(opts ...global.DBOption) error
1515
}
1616

1717
func NewILauncherRepo() ILauncherRepo {
1818
return &LauncherRepo{}
1919
}
2020

21-
func (u *LauncherRepo) Get(opts ...DBOption) (model.AppLauncher, error) {
21+
func (u *LauncherRepo) Get(opts ...global.DBOption) (model.AppLauncher, error) {
2222
var launcher model.AppLauncher
2323
db := global.DB
2424
for _, opt := range opts {
@@ -27,7 +27,7 @@ func (u *LauncherRepo) Get(opts ...DBOption) (model.AppLauncher, error) {
2727
err := db.First(&launcher).Error
2828
return launcher, err
2929
}
30-
func (u *LauncherRepo) List(opts ...DBOption) ([]model.AppLauncher, error) {
30+
func (u *LauncherRepo) List(opts ...global.DBOption) ([]model.AppLauncher, error) {
3131
var ops []model.AppLauncher
3232
db := global.DB.Model(&model.AppLauncher{})
3333
for _, opt := range opts {
@@ -41,7 +41,7 @@ func (u *LauncherRepo) Create(launcher *model.AppLauncher) error {
4141
return global.DB.Create(launcher).Error
4242
}
4343

44-
func (u *LauncherRepo) Delete(opts ...DBOption) error {
44+
func (u *LauncherRepo) Delete(opts ...global.DBOption) error {
4545
db := global.DB
4646
for _, opt := range opts {
4747
db = opt(db)

core/app/repo/backup.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import (
88
type BackupRepo struct{}
99

1010
type IBackupRepo interface {
11-
Get(opts ...DBOption) (model.BackupAccount, error)
12-
List(opts ...DBOption) ([]model.BackupAccount, error)
13-
Page(limit, offset int, opts ...DBOption) (int64, []model.BackupAccount, error)
11+
Get(opts ...global.DBOption) (model.BackupAccount, error)
12+
List(opts ...global.DBOption) ([]model.BackupAccount, error)
13+
Page(limit, offset int, opts ...global.DBOption) (int64, []model.BackupAccount, error)
1414
Create(backup *model.BackupAccount) error
1515
Save(backup *model.BackupAccount) error
16-
Delete(opts ...DBOption) error
16+
Delete(opts ...global.DBOption) error
1717
}
1818

1919
func NewIBackupRepo() IBackupRepo {
2020
return &BackupRepo{}
2121
}
2222

23-
func (u *BackupRepo) Get(opts ...DBOption) (model.BackupAccount, error) {
23+
func (u *BackupRepo) Get(opts ...global.DBOption) (model.BackupAccount, error) {
2424
var backup model.BackupAccount
2525
db := global.DB
2626
for _, opt := range opts {
@@ -30,7 +30,7 @@ func (u *BackupRepo) Get(opts ...DBOption) (model.BackupAccount, error) {
3030
return backup, err
3131
}
3232

33-
func (u *BackupRepo) Page(page, size int, opts ...DBOption) (int64, []model.BackupAccount, error) {
33+
func (u *BackupRepo) Page(page, size int, opts ...global.DBOption) (int64, []model.BackupAccount, error) {
3434
var ops []model.BackupAccount
3535
db := global.DB.Model(&model.BackupAccount{})
3636
for _, opt := range opts {
@@ -42,7 +42,7 @@ func (u *BackupRepo) Page(page, size int, opts ...DBOption) (int64, []model.Back
4242
return count, ops, err
4343
}
4444

45-
func (u *BackupRepo) List(opts ...DBOption) ([]model.BackupAccount, error) {
45+
func (u *BackupRepo) List(opts ...global.DBOption) ([]model.BackupAccount, error) {
4646
var ops []model.BackupAccount
4747
db := global.DB.Model(&model.BackupAccount{})
4848
for _, opt := range opts {
@@ -60,7 +60,7 @@ func (u *BackupRepo) Save(backup *model.BackupAccount) error {
6060
return global.DB.Save(backup).Error
6161
}
6262

63-
func (u *BackupRepo) Delete(opts ...DBOption) error {
63+
func (u *BackupRepo) Delete(opts ...global.DBOption) error {
6464
db := global.DB
6565
for _, opt := range opts {
6666
db = opt(db)

core/app/repo/command.go

+20-8
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@ package repo
33
import (
44
"github.com/1Panel-dev/1Panel/core/app/model"
55
"github.com/1Panel-dev/1Panel/core/global"
6+
"gorm.io/gorm"
67
)
78

89
type CommandRepo struct{}
910

1011
type ICommandRepo interface {
11-
List(opts ...DBOption) ([]model.Command, error)
12-
Page(limit, offset int, opts ...DBOption) (int64, []model.Command, error)
12+
List(opts ...global.DBOption) ([]model.Command, error)
13+
Page(limit, offset int, opts ...global.DBOption) (int64, []model.Command, error)
1314
Create(command *model.Command) error
1415
Update(id uint, vars map[string]interface{}) error
1516
UpdateGroup(group, newGroup uint) error
16-
Delete(opts ...DBOption) error
17-
Get(opts ...DBOption) (model.Command, error)
17+
Delete(opts ...global.DBOption) error
18+
Get(opts ...global.DBOption) (model.Command, error)
19+
20+
WithByInfo(info string) global.DBOption
1821
}
1922

2023
func NewICommandRepo() ICommandRepo {
2124
return &CommandRepo{}
2225
}
2326

24-
func (u *CommandRepo) Get(opts ...DBOption) (model.Command, error) {
27+
func (u *CommandRepo) Get(opts ...global.DBOption) (model.Command, error) {
2528
var command model.Command
2629
db := global.DB
2730
for _, opt := range opts {
@@ -31,7 +34,7 @@ func (u *CommandRepo) Get(opts ...DBOption) (model.Command, error) {
3134
return command, err
3235
}
3336

34-
func (u *CommandRepo) Page(page, size int, opts ...DBOption) (int64, []model.Command, error) {
37+
func (u *CommandRepo) Page(page, size int, opts ...global.DBOption) (int64, []model.Command, error) {
3538
var users []model.Command
3639
db := global.DB.Model(&model.Command{})
3740
for _, opt := range opts {
@@ -43,7 +46,7 @@ func (u *CommandRepo) Page(page, size int, opts ...DBOption) (int64, []model.Com
4346
return count, users, err
4447
}
4548

46-
func (u *CommandRepo) List(opts ...DBOption) ([]model.Command, error) {
49+
func (u *CommandRepo) List(opts ...global.DBOption) ([]model.Command, error) {
4750
var commands []model.Command
4851
db := global.DB.Model(&model.Command{})
4952
for _, opt := range opts {
@@ -64,10 +67,19 @@ func (h *CommandRepo) UpdateGroup(group, newGroup uint) error {
6467
return global.DB.Model(&model.Command{}).Where("group_id = ?", group).Updates(map[string]interface{}{"group_id": newGroup}).Error
6568
}
6669

67-
func (u *CommandRepo) Delete(opts ...DBOption) error {
70+
func (u *CommandRepo) Delete(opts ...global.DBOption) error {
6871
db := global.DB
6972
for _, opt := range opts {
7073
db = opt(db)
7174
}
7275
return db.Delete(&model.Command{}).Error
7376
}
77+
78+
func (c *CommandRepo) WithByInfo(info string) global.DBOption {
79+
return func(g *gorm.DB) *gorm.DB {
80+
if len(info) == 0 {
81+
return g
82+
}
83+
return g.Where("name like ? or command like ?", "%"+info+"%", "%"+info+"%")
84+
}
85+
}

core/app/repo/common.go

+33-32
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ import (
44
"fmt"
55

66
"github.com/1Panel-dev/1Panel/core/constant"
7+
"github.com/1Panel-dev/1Panel/core/global"
78
"gorm.io/gorm"
89
)
910

10-
type DBOption func(*gorm.DB) *gorm.DB
11-
1211
type ICommonRepo interface {
13-
WithByID(id uint) DBOption
14-
WithByIDs(ids []uint) DBOption
15-
WithByName(name string) DBOption
16-
WithLikeName(name string) DBOption
17-
WithByType(ty string) DBOption
18-
WithByKey(key string) DBOption
19-
WithOrderBy(orderStr string) DBOption
20-
WithByStatus(status string) DBOption
12+
WithByID(id uint) global.DBOption
13+
WithByGroupID(id uint) global.DBOption
14+
15+
WithByName(name string) global.DBOption
16+
WithByType(ty string) global.DBOption
17+
WithByKey(key string) global.DBOption
18+
WithOrderBy(orderStr string) global.DBOption
19+
WithByStatus(status string) global.DBOption
20+
WithByGroupBelong(group string) global.DBOption
2121

22-
WithOrderRuleBy(orderBy, order string) DBOption
22+
WithByIDs(ids []uint) global.DBOption
23+
24+
WithOrderRuleBy(orderBy, order string) global.DBOption
2325
}
2426

2527
type CommonRepo struct{}
@@ -28,57 +30,56 @@ func NewICommonRepo() ICommonRepo {
2830
return &CommonRepo{}
2931
}
3032

31-
func (c *CommonRepo) WithByID(id uint) DBOption {
33+
func (c *CommonRepo) WithByID(id uint) global.DBOption {
3234
return func(g *gorm.DB) *gorm.DB {
3335
return g.Where("id = ?", id)
3436
}
3537
}
36-
func (c *CommonRepo) WithByIDs(ids []uint) DBOption {
38+
func (c *CommonRepo) WithByGroupID(id uint) global.DBOption {
3739
return func(g *gorm.DB) *gorm.DB {
38-
return g.Where("id in (?)", ids)
40+
return g.Where("group_id = ?", id)
3941
}
4042
}
41-
func (c *CommonRepo) WithByName(name string) DBOption {
43+
44+
func (c *CommonRepo) WithByIDs(ids []uint) global.DBOption {
4245
return func(g *gorm.DB) *gorm.DB {
43-
if len(name) == 0 {
44-
return g
45-
}
46-
return g.Where("`name` = ?", name)
46+
return g.Where("id in (?)", ids)
4747
}
4848
}
49-
func (c *CommonRepo) WithLikeName(name string) DBOption {
49+
func (c *CommonRepo) WithByName(name string) global.DBOption {
5050
return func(g *gorm.DB) *gorm.DB {
51-
if len(name) == 0 {
52-
return g
53-
}
54-
return g.Where("name like ? or command like ?", "%"+name+"%", "%"+name+"%")
51+
return g.Where("`name` = ?", name)
5552
}
5653
}
57-
func (c *CommonRepo) WithByType(ty string) DBOption {
54+
55+
func (c *CommonRepo) WithByType(ty string) global.DBOption {
5856
return func(g *gorm.DB) *gorm.DB {
59-
if len(ty) == 0 {
60-
return g
61-
}
6257
return g.Where("`type` = ?", ty)
6358
}
6459
}
65-
func (c *CommonRepo) WithByKey(key string) DBOption {
60+
func (c *CommonRepo) WithByKey(key string) global.DBOption {
6661
return func(g *gorm.DB) *gorm.DB {
6762
return g.Where("key = ?", key)
6863
}
6964
}
70-
func (c *CommonRepo) WithByStatus(status string) DBOption {
65+
func (c *CommonRepo) WithByStatus(status string) global.DBOption {
7166
return func(g *gorm.DB) *gorm.DB {
7267
return g.Where("status = ?", status)
7368
}
7469
}
75-
func (c *CommonRepo) WithOrderBy(orderStr string) DBOption {
70+
func (c *CommonRepo) WithByGroupBelong(group string) global.DBOption {
71+
return func(g *gorm.DB) *gorm.DB {
72+
return g.Where("group_belong = ?", group)
73+
}
74+
}
75+
76+
func (c *CommonRepo) WithOrderBy(orderStr string) global.DBOption {
7677
return func(g *gorm.DB) *gorm.DB {
7778
return g.Order(orderStr)
7879
}
7980
}
8081

81-
func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) DBOption {
82+
func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) global.DBOption {
8283
switch order {
8384
case constant.OrderDesc:
8485
order = "desc"

core/app/repo/group.go

+8-29
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,27 @@ import (
99
type GroupRepo struct{}
1010

1111
type IGroupRepo interface {
12-
Get(opts ...DBOption) (model.Group, error)
13-
GetList(opts ...DBOption) ([]model.Group, error)
12+
Get(opts ...global.DBOption) (model.Group, error)
13+
GetList(opts ...global.DBOption) ([]model.Group, error)
1414
Create(group *model.Group) error
1515
Update(id uint, vars map[string]interface{}) error
16-
Delete(opts ...DBOption) error
16+
Delete(opts ...global.DBOption) error
1717

18-
WithByID(id uint) DBOption
19-
WithByGroupID(id uint) DBOption
20-
WithByGroupType(ty string) DBOption
21-
WithByDefault(isDefalut bool) DBOption
18+
WithByDefault(isDefalut bool) global.DBOption
2219
CancelDefault(groupType string) error
2320
}
2421

2522
func NewIGroupRepo() IGroupRepo {
2623
return &GroupRepo{}
2724
}
2825

29-
func (c *GroupRepo) WithByID(id uint) DBOption {
30-
return func(g *gorm.DB) *gorm.DB {
31-
return g.Where("id = ?", id)
32-
}
33-
}
34-
35-
func (c *GroupRepo) WithByGroupID(id uint) DBOption {
36-
return func(g *gorm.DB) *gorm.DB {
37-
return g.Where("group_id = ?", id)
38-
}
39-
}
40-
41-
func (c *GroupRepo) WithByGroupType(ty string) DBOption {
42-
return func(g *gorm.DB) *gorm.DB {
43-
return g.Where("`type` = ?", ty)
44-
}
45-
}
46-
47-
func (c *GroupRepo) WithByDefault(isDefalut bool) DBOption {
26+
func (c *GroupRepo) WithByDefault(isDefalut bool) global.DBOption {
4827
return func(g *gorm.DB) *gorm.DB {
4928
return g.Where("is_default = ?", isDefalut)
5029
}
5130
}
5231

53-
func (u *GroupRepo) Get(opts ...DBOption) (model.Group, error) {
32+
func (u *GroupRepo) Get(opts ...global.DBOption) (model.Group, error) {
5433
var group model.Group
5534
db := global.DB
5635
for _, opt := range opts {
@@ -60,7 +39,7 @@ func (u *GroupRepo) Get(opts ...DBOption) (model.Group, error) {
6039
return group, err
6140
}
6241

63-
func (u *GroupRepo) GetList(opts ...DBOption) ([]model.Group, error) {
42+
func (u *GroupRepo) GetList(opts ...global.DBOption) ([]model.Group, error) {
6443
var groups []model.Group
6544
db := global.DB.Model(&model.Group{})
6645
for _, opt := range opts {
@@ -78,7 +57,7 @@ func (u *GroupRepo) Update(id uint, vars map[string]interface{}) error {
7857
return global.DB.Model(&model.Group{}).Where("id = ?", id).Updates(vars).Error
7958
}
8059

81-
func (u *GroupRepo) Delete(opts ...DBOption) error {
60+
func (u *GroupRepo) Delete(opts ...global.DBOption) error {
8261
db := global.DB
8362
for _, opt := range opts {
8463
db = opt(db)

0 commit comments

Comments
 (0)