- 修复资产新增、修改无权限的缺陷 fixed #314 - 修复执行动态指令时多行失败且无法自动执行的问题 fixed #313 #310 - 修复计划任务无法选择资产的问题 fixed #312 - 修复导入导出备份无效的问题 fixed #303 - 增加「资产详情」「资产授权」「用户详情」「用户授权」「用户组详情」「用户组授权」「角色详情」「授权策略详情」按钮 - 修复资产列表使用IP搜索无效的问题 - 资产列表增加最近接入时间排序、增加修改每页数量 fixed #311 - 修复登录页面双因素认证输入框无法自动获取焦点的问题 fixed #311 - 增加普通页面资产列表最后接入时间排序 fixed #311 - 计划任务增加执行本机系统命令
165 lines
6.1 KiB
Go
165 lines
6.1 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"next-terminal/server/dto"
|
|
"next-terminal/server/model"
|
|
)
|
|
|
|
var AuthorisedRepository = new(authorisedRepository)
|
|
|
|
type authorisedRepository struct {
|
|
baseRepository
|
|
}
|
|
|
|
func (r authorisedRepository) Create(c context.Context, m *model.Authorised) error {
|
|
return r.GetDB(c).Create(m).Error
|
|
}
|
|
|
|
func (r authorisedRepository) CreateInBatches(c context.Context, m []model.Authorised) error {
|
|
return r.GetDB(c).CreateInBatches(m, 100).Error
|
|
}
|
|
|
|
func (r authorisedRepository) DeleteByUserId(c context.Context, userId string) error {
|
|
return r.GetDB(c).Where("user_id = ?", userId).Delete(model.Authorised{}).Error
|
|
}
|
|
|
|
func (r authorisedRepository) DeleteByUserGroupId(c context.Context, userGroupId string) error {
|
|
return r.GetDB(c).Where("user_group_id = ?", userGroupId).Delete(model.Authorised{}).Error
|
|
}
|
|
|
|
func (r authorisedRepository) DeleteByAssetId(c context.Context, assetId string) error {
|
|
return r.GetDB(c).Where("asset_id = ?", assetId).Delete(model.Authorised{}).Error
|
|
}
|
|
|
|
func (r authorisedRepository) FindByUserId(c context.Context, userId string) (items []model.Authorised, err error) {
|
|
err = r.GetDB(c).Where("user_id = ?", userId).Find(&items).Error
|
|
return
|
|
}
|
|
|
|
func (r authorisedRepository) FindById(c context.Context, id string) (item model.Authorised, err error) {
|
|
err = r.GetDB(c).Where("id = ?", id).First(&item).Error
|
|
return
|
|
}
|
|
|
|
func (r authorisedRepository) FindByUserGroupId(c context.Context, userGroupId string) (items []model.Authorised, err error) {
|
|
err = r.GetDB(c).Where("user_group_id = ?", userGroupId).Find(&items).Error
|
|
return
|
|
}
|
|
|
|
func (r authorisedRepository) FindByUserGroupIdIn(c context.Context, userGroupIds []string) (items []model.Authorised, err error) {
|
|
err = r.GetDB(c).Where("user_group_id in ?", userGroupIds).Find(&items).Error
|
|
return
|
|
}
|
|
|
|
func (r authorisedRepository) FindAll(c context.Context, userId, userGroupId, assetId string) (items []model.Authorised, err error) {
|
|
db := r.GetDB(c)
|
|
if userId != "" {
|
|
db = db.Where("user_id = ?", userId)
|
|
}
|
|
if userGroupId != "" {
|
|
db = db.Where("user_group_id = ?", userGroupId)
|
|
}
|
|
if assetId != "" {
|
|
db = db.Where("asset_id = ?", assetId)
|
|
}
|
|
err = db.Find(&items).Error
|
|
return
|
|
}
|
|
|
|
func (r authorisedRepository) FindAssetPage(c context.Context, pageIndex, pageSize int, assetName, userId, userGroupId string) (o []dto.AssetPageForAuthorised, total int64, err error) {
|
|
db := r.GetDB(c).Table("assets").
|
|
Select("authorised.id, authorised.created, assets.id as asset_id, assets.name as asset_name, strategies.id as strategy_id, strategies.name as strategy_name ").
|
|
Joins("left join authorised on authorised.asset_id = assets.id").
|
|
Joins("left join strategies on strategies.id = authorised.strategy_id")
|
|
dbCounter := r.GetDB(c).Table("assets").Joins("left join authorised on assets.id = authorised.asset_id").Group("assets.id")
|
|
|
|
if assetName != "" {
|
|
db = db.Where("assets.name like ?", "%"+assetName+"%")
|
|
dbCounter = dbCounter.Where("assets.name like ?", "%"+assetName+"%")
|
|
}
|
|
|
|
if userId != "" {
|
|
db = db.Where("authorised.user_id = ?", userId)
|
|
dbCounter = dbCounter.Where("authorised.user_id = ?", userId)
|
|
}
|
|
|
|
if userGroupId != "" {
|
|
db = db.Where("authorised.user_group_id = ?", userGroupId)
|
|
dbCounter = dbCounter.Where("authorised.user_group_id = ?", userGroupId)
|
|
}
|
|
|
|
err = dbCounter.Count(&total).Error
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
err = db.Order("authorised.created desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Error
|
|
if o == nil {
|
|
o = make([]dto.AssetPageForAuthorised, 0)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (r authorisedRepository) DeleteById(c context.Context, id string) error {
|
|
return r.GetDB(c).Where("id = ?", id).Delete(model.Authorised{}).Error
|
|
}
|
|
|
|
func (r authorisedRepository) FindUserPage(c context.Context, pageIndex, pageSize int, userName, assetId string) (o []dto.UserPageForAuthorised, total int64, err error) {
|
|
db := r.GetDB(c).Table("users").
|
|
Select("authorised.id, authorised.created, users.id as user_id, users.nickname as user_name, strategies.id as strategy_id, strategies.name as strategy_name ").
|
|
Joins("left join authorised on authorised.user_id = users.id").
|
|
Joins("left join strategies on strategies.id = authorised.strategy_id")
|
|
dbCounter := r.GetDB(c).Table("assets").Joins("left join authorised on assets.id = authorised.asset_id").Group("assets.id")
|
|
|
|
if userName != "" {
|
|
db = db.Where("users.nickname like ?", "%"+userName+"%")
|
|
dbCounter = dbCounter.Where("users.nickname like ?", "%"+userName+"%")
|
|
}
|
|
|
|
if assetId != "" {
|
|
db = db.Where("authorised.asset_id = ?", assetId)
|
|
dbCounter = dbCounter.Where("authorised.asset_id = ?", assetId)
|
|
}
|
|
|
|
err = dbCounter.Count(&total).Error
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
err = db.Order("authorised.created desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Error
|
|
if o == nil {
|
|
o = make([]dto.UserPageForAuthorised, 0)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (r authorisedRepository) FindUserGroupPage(c context.Context, pageIndex, pageSize int, userName, assetId string) (o []dto.UserGroupPageForAuthorised, total int64, err error) {
|
|
db := r.GetDB(c).Table("user_groups").
|
|
Select("authorised.id, authorised.created, user_groups.id as user_group_id, user_groups.name as user_group_name, strategies.id as strategy_id, strategies.name as strategy_name ").
|
|
Joins("left join authorised on authorised.user_group_id = user_groups.id").
|
|
Joins("left join strategies on strategies.id = authorised.strategy_id")
|
|
dbCounter := r.GetDB(c).Table("assets").Joins("left join authorised on assets.id = authorised.asset_id").Group("assets.id")
|
|
|
|
if userName != "" {
|
|
db = db.Where("user_groups.name like ?", "%"+userName+"%")
|
|
dbCounter = dbCounter.Where("user_groups.name like ?", "%"+userName+"%")
|
|
}
|
|
|
|
if assetId != "" {
|
|
db = db.Where("authorised.asset_id = ?", assetId)
|
|
dbCounter = dbCounter.Where("authorised.asset_id = ?", assetId)
|
|
}
|
|
|
|
err = dbCounter.Count(&total).Error
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
err = db.Order("authorised.created desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Error
|
|
if o == nil {
|
|
o = make([]dto.UserGroupPageForAuthorised, 0)
|
|
}
|
|
return
|
|
}
|