feat: 添加数据库资产、命令拦截器、授权资产等功能,修复GitHub Actions工作流
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"next-terminal/server/model"
|
||||
)
|
||||
|
||||
const SuperAdminID = `abcdefghijklmnopqrstuvwxyz`
|
||||
|
||||
var UserRepository = new(userRepository)
|
||||
|
||||
type userRepository struct {
|
||||
@@ -18,7 +20,7 @@ func (r userRepository) FindAll(c context.Context) (o []model.User, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (r userRepository) Find(c context.Context, pageIndex, pageSize int, username, nickname, mail, online, loginPolicyId, order, field string) (o []model.UserForPage, total int64, err error) {
|
||||
func (r userRepository) Find(c context.Context, pageIndex, pageSize int, username, nickname, mail, online, userType, loginPolicyId, order, field string) (o []model.UserForPage, total int64, err error) {
|
||||
db := r.GetDB(c).Table("users").Select("users.id,users.username,users.nickname,users.mail,users.phone,users.online,users.created,users.type,users.status,users.source,users.recording,users.watermark, users.totp_secret")
|
||||
dbCounter := r.GetDB(c).Table("users")
|
||||
|
||||
@@ -54,6 +56,17 @@ func (r userRepository) Find(c context.Context, pageIndex, pageSize int, usernam
|
||||
dbCounter = dbCounter.Where("users.online = ?", _online)
|
||||
}
|
||||
|
||||
if userType == "super-admin" {
|
||||
db = db.Where("users.id = ?", SuperAdminID)
|
||||
dbCounter = dbCounter.Where("id = ?", SuperAdminID)
|
||||
} else if userType == "admin" {
|
||||
db = db.Where("users.type = ? and users.id != ?", "admin", SuperAdminID)
|
||||
dbCounter = dbCounter.Where("type = ? and id != ?", "admin", SuperAdminID)
|
||||
} else if userType == "user" {
|
||||
db = db.Where("users.type = ?", "user")
|
||||
dbCounter = dbCounter.Where("type = ?", "user")
|
||||
}
|
||||
|
||||
err = dbCounter.Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
||||
Reference in New Issue
Block a user