fix: fix issue with set default group (#8717)

Refs https://github.com/1Panel-dev/1Panel/issues/8712
This commit is contained in:
CityFun 2025-05-18 11:21:58 +08:00 committed by GitHub
parent 8c46078b03
commit 12eb00d638
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 56 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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}, "")

View file

@ -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
}

View file

@ -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
}