mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-30 02:36:18 +08:00
fix: fix issue with set default group (#8717)
Refs https://github.com/1Panel-dev/1Panel/issues/8712
This commit is contained in:
parent
8c46078b03
commit
12eb00d638
5 changed files with 13 additions and 56 deletions
|
|
@ -14,6 +14,7 @@ type IGroupRepo interface {
|
|||
Create(group *model.Group) error
|
||||
Update(id uint, vars map[string]interface{}) error
|
||||
Delete(opts ...DBOption) error
|
||||
CancelDefault(groupType string) error
|
||||
WithByDefault(isDefault bool) DBOption
|
||||
WithByWebsiteDefault() DBOption
|
||||
}
|
||||
|
|
@ -69,3 +70,9 @@ func (g *GroupRepo) WithByWebsiteDefault() DBOption {
|
|||
return g.Where("is_default = ? AND type = ?", 1, "website")
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupRepo) CancelDefault(groupType string) error {
|
||||
return global.DB.Model(&model.Group{}).
|
||||
Where("is_default = ? AND type = ?", 1, groupType).
|
||||
Updates(map[string]interface{}{"is_default": 0}).Error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,11 @@ func (u *GroupService) Delete(id uint) error {
|
|||
}
|
||||
|
||||
func (u *GroupService) Update(req dto.GroupUpdate) error {
|
||||
if req.IsDefault {
|
||||
if err := groupRepo.CancelDefault(req.Type); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
upMap := make(map[string]interface{})
|
||||
upMap["name"] = req.Name
|
||||
upMap["is_default"] = req.IsDefault
|
||||
|
|
|
|||
|
|
@ -1378,6 +1378,7 @@ func (w WebsiteService) ChangePHPVersion(req request.WebsitePHPVersionReq) error
|
|||
return buserr.New("ErrPHPResource")
|
||||
}
|
||||
website.RuntimeID = req.RuntimeID
|
||||
website.AppInstallID = 0
|
||||
phpProxy := fmt.Sprintf("127.0.0.1:%s", runtime.Port)
|
||||
website.Proxy = phpProxy
|
||||
server.UpdatePHPProxy([]string{website.Proxy}, "")
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
package dto
|
||||
|
||||
import "github.com/1Panel-dev/1Panel/core/app/model"
|
||||
|
||||
type SearchTaskLogReq struct {
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
PageInfo
|
||||
}
|
||||
|
||||
type TaskDTO struct {
|
||||
model.Task
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"github.com/1Panel-dev/1Panel/core/app/dto"
|
||||
"github.com/1Panel-dev/1Panel/core/app/repo"
|
||||
"github.com/1Panel-dev/1Panel/core/global"
|
||||
)
|
||||
|
||||
type TaskLogService struct{}
|
||||
|
||||
type ITaskLogService interface {
|
||||
Page(req dto.SearchTaskLogReq) (int64, []dto.TaskDTO, error)
|
||||
}
|
||||
|
||||
func NewITaskService() ITaskLogService {
|
||||
return &TaskLogService{}
|
||||
}
|
||||
|
||||
func (u *TaskLogService) Page(req dto.SearchTaskLogReq) (int64, []dto.TaskDTO, error) {
|
||||
opts := []global.DBOption{
|
||||
repo.WithOrderBy("created_at desc"),
|
||||
}
|
||||
if req.Status != "" {
|
||||
opts = append(opts, repo.WithByStatus(req.Status))
|
||||
}
|
||||
if req.Type != "" {
|
||||
opts = append(opts, repo.WithByType(req.Type))
|
||||
}
|
||||
|
||||
total, tasks, err := taskRepo.Page(
|
||||
req.Page,
|
||||
req.PageSize,
|
||||
opts...,
|
||||
)
|
||||
var items []dto.TaskDTO
|
||||
for _, t := range tasks {
|
||||
item := dto.TaskDTO{
|
||||
Task: t,
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
return total, items, err
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue