fix: 解决主机默认分组失败的问题 (#2839)

This commit is contained in:
ssongliu 2023-11-07 23:41:28 +08:00 committed by GitHub
parent 8adca0efa2
commit d8588d06ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 265 additions and 72 deletions

View File

@ -9,7 +9,7 @@ type SSHUpdate struct {
}
type SSHInfo struct {
AutoStart bool `json:"authStart"`
AutoStart bool `json:"autoStart"`
Status string `json:"status"`
Message string `json:"message"`
Port string `json:"port"`

View File

@ -15,7 +15,7 @@ type IGroupRepo interface {
Update(id uint, vars map[string]interface{}) error
Delete(opts ...DBOption) error
CancelDefault(groupType string) error
WithByIsDefault(isDefault bool) DBOption
WithByHostDefault() DBOption
}
func NewIGroupRepo() IGroupRepo {
@ -50,9 +50,9 @@ func (u *GroupRepo) Update(id uint, vars map[string]interface{}) error {
return global.DB.Model(&model.Group{}).Where("id = ?", id).Updates(vars).Error
}
func (u *GroupRepo) WithByIsDefault(isDefault bool) DBOption {
func (u *GroupRepo) WithByHostDefault() DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("is_default = ?", isDefault)
return g.Where("is_default = ? AND type = ?", 1, "host")
}
}

View File

@ -249,7 +249,7 @@ func (u *HostService) Create(req dto.HostOperate) (*dto.HostInfo, error) {
return nil, errors.WithMessage(constant.ErrStructTransform, err.Error())
}
if req.GroupID == 0 {
group, err := groupRepo.Get(groupRepo.WithByIsDefault(true))
group, err := groupRepo.Get(groupRepo.WithByHostDefault())
if err != nil {
return nil, errors.New("get default group failed")
}

View File

@ -1,5 +1,5 @@
// Package docs GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
// Code generated by swaggo/swag. DO NOT EDIT.
package docs
import "github.com/swaggo/swag"
@ -5085,6 +5085,51 @@ const docTemplate = `{
}
}
},
"/files/batch/role": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "批量修改文件权限和用户/组",
"consumes": [
"application/json"
],
"tags": [
"File"
],
"summary": "Batch change file mode and owner",
"parameters": [
{
"description": "request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.FileRoleReq"
}
}
],
"responses": {
"200": {
"description": "OK"
}
},
"x-panel-log": {
"BeforeFunctions": [],
"bodyKeys": [
"paths",
"mode",
"user",
"group"
],
"formatEN": "Batch change file mode and owner [paths] =\u003e [mode]/[user]/[group]",
"formatZH": "批量修改文件权限和用户/组 [paths] =\u003e [mode]/[user]/[group]",
"paramKeys": []
}
}
},
"/files/check": {
"post": {
"security": [
@ -15411,7 +15456,7 @@ const docTemplate = `{
"dto.SSHInfo": {
"type": "object",
"properties": {
"authStart": {
"autoStart": {
"type": "boolean"
},
"listenAddress": {
@ -15711,6 +15756,9 @@ const docTemplate = `{
"appStoreLastModified": {
"type": "string"
},
"appStoreSyncStatus": {
"type": "string"
},
"appStoreVersion": {
"type": "string"
},
@ -16504,6 +16552,9 @@ const docTemplate = `{
"editCompose": {
"type": "boolean"
},
"hostMode": {
"type": "boolean"
},
"memoryLimit": {
"type": "number"
},
@ -16652,6 +16703,9 @@ const docTemplate = `{
"editCompose": {
"type": "boolean"
},
"hostMode": {
"type": "boolean"
},
"installId": {
"type": "integer"
},
@ -16873,7 +16927,6 @@ const docTemplate = `{
"request.FileDownload": {
"type": "object",
"required": [
"compress",
"name",
"paths",
"type"
@ -17019,12 +17072,40 @@ const docTemplate = `{
}
}
},
"request.FileRoleReq": {
"type": "object",
"required": [
"group",
"mode",
"paths",
"user"
],
"properties": {
"group": {
"type": "string"
},
"mode": {
"type": "integer"
},
"paths": {
"type": "array",
"items": {
"type": "string"
}
},
"sub": {
"type": "boolean"
},
"user": {
"type": "string"
}
}
},
"request.FileRoleUpdate": {
"type": "object",
"required": [
"group",
"path",
"sub",
"user"
],
"properties": {
@ -17163,6 +17244,9 @@ const docTemplate = `{
"editCompose": {
"type": "boolean"
},
"hostMode": {
"type": "boolean"
},
"memoryLimit": {
"type": "number"
},
@ -17181,7 +17265,6 @@ const docTemplate = `{
"request.NginxAntiLeechUpdate": {
"type": "object",
"required": [
"enable",
"extends",
"return",
"websiteID"
@ -17276,7 +17359,6 @@ const docTemplate = `{
"request.NginxConfigFileUpdate": {
"type": "object",
"required": [
"backup",
"content"
],
"properties": {
@ -17328,8 +17410,6 @@ const docTemplate = `{
"request.NginxRedirectReq": {
"type": "object",
"required": [
"enable",
"keepPath",
"name",
"operate",
"redirect",
@ -17900,18 +17980,14 @@ const docTemplate = `{
"request.WebsiteDomainCreate": {
"type": "object",
"required": [
"domain",
"port",
"websiteId"
"domains",
"websiteID"
],
"properties": {
"domain": {
"domains": {
"type": "string"
},
"port": {
"type": "integer"
},
"websiteId": {
"websiteID": {
"type": "integer"
}
}
@ -17930,7 +18006,6 @@ const docTemplate = `{
"request.WebsiteHTTPSOp": {
"type": "object",
"required": [
"enable",
"websiteId"
],
"properties": {
@ -18102,7 +18177,6 @@ const docTemplate = `{
"request.WebsitePHPVersionReq": {
"type": "object",
"required": [
"retainConfig",
"runtimeID",
"websiteID"
],
@ -18121,10 +18195,8 @@ const docTemplate = `{
"request.WebsiteProxyConfig": {
"type": "object",
"required": [
"cache",
"cacheTime",
"cacheUnit",
"enable",
"id",
"match",
"modifier",
@ -18207,7 +18279,6 @@ const docTemplate = `{
"type": "object",
"required": [
"acmeAccountId",
"autoRenew",
"primaryDomain",
"provider"
],
@ -18264,7 +18335,6 @@ const docTemplate = `{
"request.WebsiteSSLUpdate": {
"type": "object",
"required": [
"autoRenew",
"id"
],
"properties": {
@ -18414,7 +18484,6 @@ const docTemplate = `{
"request.WebsiteWafUpdate": {
"type": "object",
"required": [
"enable",
"key",
"websiteId"
],
@ -18531,6 +18600,9 @@ const docTemplate = `{
"enable": {
"type": "boolean"
},
"hostMode": {
"type": "boolean"
},
"id": {
"type": "integer"
},

View File

@ -5078,6 +5078,51 @@
}
}
},
"/files/batch/role": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "批量修改文件权限和用户/组",
"consumes": [
"application/json"
],
"tags": [
"File"
],
"summary": "Batch change file mode and owner",
"parameters": [
{
"description": "request",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.FileRoleReq"
}
}
],
"responses": {
"200": {
"description": "OK"
}
},
"x-panel-log": {
"BeforeFunctions": [],
"bodyKeys": [
"paths",
"mode",
"user",
"group"
],
"formatEN": "Batch change file mode and owner [paths] =\u003e [mode]/[user]/[group]",
"formatZH": "批量修改文件权限和用户/组 [paths] =\u003e [mode]/[user]/[group]",
"paramKeys": []
}
}
},
"/files/check": {
"post": {
"security": [
@ -15404,7 +15449,7 @@
"dto.SSHInfo": {
"type": "object",
"properties": {
"authStart": {
"autoStart": {
"type": "boolean"
},
"listenAddress": {
@ -15704,6 +15749,9 @@
"appStoreLastModified": {
"type": "string"
},
"appStoreSyncStatus": {
"type": "string"
},
"appStoreVersion": {
"type": "string"
},
@ -16497,6 +16545,9 @@
"editCompose": {
"type": "boolean"
},
"hostMode": {
"type": "boolean"
},
"memoryLimit": {
"type": "number"
},
@ -16645,6 +16696,9 @@
"editCompose": {
"type": "boolean"
},
"hostMode": {
"type": "boolean"
},
"installId": {
"type": "integer"
},
@ -16866,7 +16920,6 @@
"request.FileDownload": {
"type": "object",
"required": [
"compress",
"name",
"paths",
"type"
@ -17012,12 +17065,40 @@
}
}
},
"request.FileRoleReq": {
"type": "object",
"required": [
"group",
"mode",
"paths",
"user"
],
"properties": {
"group": {
"type": "string"
},
"mode": {
"type": "integer"
},
"paths": {
"type": "array",
"items": {
"type": "string"
}
},
"sub": {
"type": "boolean"
},
"user": {
"type": "string"
}
}
},
"request.FileRoleUpdate": {
"type": "object",
"required": [
"group",
"path",
"sub",
"user"
],
"properties": {
@ -17156,6 +17237,9 @@
"editCompose": {
"type": "boolean"
},
"hostMode": {
"type": "boolean"
},
"memoryLimit": {
"type": "number"
},
@ -17174,7 +17258,6 @@
"request.NginxAntiLeechUpdate": {
"type": "object",
"required": [
"enable",
"extends",
"return",
"websiteID"
@ -17269,7 +17352,6 @@
"request.NginxConfigFileUpdate": {
"type": "object",
"required": [
"backup",
"content"
],
"properties": {
@ -17321,8 +17403,6 @@
"request.NginxRedirectReq": {
"type": "object",
"required": [
"enable",
"keepPath",
"name",
"operate",
"redirect",
@ -17893,18 +17973,14 @@
"request.WebsiteDomainCreate": {
"type": "object",
"required": [
"domain",
"port",
"websiteId"
"domains",
"websiteID"
],
"properties": {
"domain": {
"domains": {
"type": "string"
},
"port": {
"type": "integer"
},
"websiteId": {
"websiteID": {
"type": "integer"
}
}
@ -17923,7 +17999,6 @@
"request.WebsiteHTTPSOp": {
"type": "object",
"required": [
"enable",
"websiteId"
],
"properties": {
@ -18095,7 +18170,6 @@
"request.WebsitePHPVersionReq": {
"type": "object",
"required": [
"retainConfig",
"runtimeID",
"websiteID"
],
@ -18114,10 +18188,8 @@
"request.WebsiteProxyConfig": {
"type": "object",
"required": [
"cache",
"cacheTime",
"cacheUnit",
"enable",
"id",
"match",
"modifier",
@ -18200,7 +18272,6 @@
"type": "object",
"required": [
"acmeAccountId",
"autoRenew",
"primaryDomain",
"provider"
],
@ -18257,7 +18328,6 @@
"request.WebsiteSSLUpdate": {
"type": "object",
"required": [
"autoRenew",
"id"
],
"properties": {
@ -18407,7 +18477,6 @@
"request.WebsiteWafUpdate": {
"type": "object",
"required": [
"enable",
"key",
"websiteId"
],
@ -18524,6 +18593,9 @@
"enable": {
"type": "boolean"
},
"hostMode": {
"type": "boolean"
},
"id": {
"type": "integer"
},

View File

@ -1953,7 +1953,7 @@ definitions:
type: object
dto.SSHInfo:
properties:
authStart:
autoStart:
type: boolean
listenAddress:
type: string
@ -2153,6 +2153,8 @@ definitions:
type: string
appStoreLastModified:
type: string
appStoreSyncStatus:
type: string
appStoreVersion:
type: string
bindAddress:
@ -2675,6 +2677,8 @@ definitions:
type: string
editCompose:
type: boolean
hostMode:
type: boolean
memoryLimit:
type: number
memoryUnit:
@ -2774,6 +2778,8 @@ definitions:
type: string
editCompose:
type: boolean
hostMode:
type: boolean
installId:
type: integer
memoryLimit:
@ -2934,7 +2940,6 @@ definitions:
type:
type: string
required:
- compress
- name
- paths
- type
@ -3021,6 +3026,26 @@ definitions:
- newName
- oldName
type: object
request.FileRoleReq:
properties:
group:
type: string
mode:
type: integer
paths:
items:
type: string
type: array
sub:
type: boolean
user:
type: string
required:
- group
- mode
- paths
- user
type: object
request.FileRoleUpdate:
properties:
group:
@ -3034,7 +3059,6 @@ definitions:
required:
- group
- path
- sub
- user
type: object
request.FileWget:
@ -3118,6 +3142,8 @@ definitions:
type: string
editCompose:
type: boolean
hostMode:
type: boolean
memoryLimit:
type: number
memoryUnit:
@ -3155,7 +3181,6 @@ definitions:
websiteID:
type: integer
required:
- enable
- extends
- return
- websiteID
@ -3199,7 +3224,6 @@ definitions:
content:
type: string
required:
- backup
- content
type: object
request.NginxConfigUpdate:
@ -3254,8 +3278,6 @@ definitions:
websiteID:
type: integer
required:
- enable
- keepPath
- name
- operate
- redirect
@ -3613,16 +3635,13 @@ definitions:
type: object
request.WebsiteDomainCreate:
properties:
domain:
domains:
type: string
port:
type: integer
websiteId:
websiteID:
type: integer
required:
- domain
- port
- websiteId
- domains
- websiteID
type: object
request.WebsiteDomainDelete:
properties:
@ -3668,7 +3687,6 @@ definitions:
websiteSSLId:
type: integer
required:
- enable
- websiteId
type: object
request.WebsiteInstallCheckReq:
@ -3756,7 +3774,6 @@ definitions:
websiteID:
type: integer
required:
- retainConfig
- runtimeID
- websiteID
type: object
@ -3793,10 +3810,8 @@ definitions:
type: string
type: object
required:
- cache
- cacheTime
- cacheUnit
- enable
- id
- match
- modifier
@ -3835,7 +3850,6 @@ definitions:
type: string
required:
- acmeAccountId
- autoRenew
- primaryDomain
- provider
type: object
@ -3865,7 +3879,6 @@ definitions:
id:
type: integer
required:
- autoRenew
- id
type: object
request.WebsiteSSLUpload:
@ -3968,7 +3981,6 @@ definitions:
websiteId:
type: integer
required:
- enable
- key
- websiteId
type: object
@ -4039,6 +4051,8 @@ definitions:
type: string
enable:
type: boolean
hostMode:
type: boolean
id:
type: integer
ignoreUpgrade:
@ -7595,6 +7609,36 @@ paths:
formatEN: Batch delete dir or file [paths]
formatZH: 批量删除文件/文件夹 [paths]
paramKeys: []
/files/batch/role:
post:
consumes:
- application/json
description: 批量修改文件权限和用户/组
parameters:
- description: request
in: body
name: request
required: true
schema:
$ref: '#/definitions/request.FileRoleReq'
responses:
"200":
description: OK
security:
- ApiKeyAuth: []
summary: Batch change file mode and owner
tags:
- File
x-panel-log:
BeforeFunctions: []
bodyKeys:
- paths
- mode
- user
- group
formatEN: Batch change file mode and owner [paths] => [mode]/[user]/[group]
formatZH: 批量修改文件权限和用户/组 [paths] => [mode]/[user]/[group]
paramKeys: []
/files/check:
post:
consumes:

View File

@ -117,6 +117,7 @@ export namespace Host {
}
export interface SSHInfo {
autoStart: boolean;
status: string;
message: string;
port: string;

View File

@ -880,6 +880,7 @@ const message = {
resource: 'Resource',
operate: 'Operate',
detail: {
groups: 'Group',
hosts: 'Host',
apps: 'App',
websites: 'Website',

View File

@ -844,6 +844,7 @@ const message = {
resource: '資源',
operate: '操作',
detail: {
groups: '分組',
hosts: '主機',
apps: '應用',
websites: '網站',

View File

@ -845,6 +845,7 @@ const message = {
resource: '资源',
operate: '操作',
detail: {
groups: '分组',
hosts: '主机',
apps: '应用',
websites: '网站',

View File

@ -322,6 +322,7 @@ const search = async () => {
const res = await getSSHInfo();
form.status = res.data.status;
form.port = Number(res.data.port);
autoStart.value = res.data.autoStart ? 'enable' : 'disable';
form.listenAddress = res.data.listenAddress;
form.passwordAuthentication = res.data.passwordAuthentication;
form.pubkeyAuthentication = res.data.pubkeyAuthentication;