Skip to content

Commit f28beb0

Browse files
authored
Merge pull request #526 from chaitin/feat-public-host-limit
feat: 公共主机创建开发环境的时间限制
2 parents 75ca7fe + 4886504 commit f28beb0

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

backend/biz/host/repo/host.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ func (h *HostRepo) CreateVirtualMachine(ctx context.Context, u *domain.User, req
285285
var res *domain.VirtualMachine
286286
err := entx.WithTx2(ctx, h.db, func(tx *db.Tx) error {
287287
dbHost, err := tx.Host.Query().
288+
WithUser().
288289
WithGroups().
289290
Where(hostWithUserPredicate(u.ID)).
290291
Where(host.ID(req.HostID)).
@@ -293,6 +294,12 @@ func (h *HostRepo) CreateVirtualMachine(ctx context.Context, u *domain.User, req
293294
return errcode.ErrPermision.Wrap(err)
294295
}
295296

297+
if u := dbHost.Edges.User; u != nil && u.Role == consts.UserRoleAdmin {
298+
if req.Life > 3*60*60 || req.Life <= 0 {
299+
return errcode.ErrPublicHostBeyondLimit
300+
}
301+
}
302+
296303
if len(dbHost.Edges.Groups) > 0 && (req.Life <= 0 || req.Life > 7*24*60*60) {
297304
return errcode.ErrVmBeyondExpireTime.Wrap(fmt.Errorf("团队宿主机不支持创建永久虚拟机"))
298305
}

0 commit comments

Comments
 (0)