feat: 业务组和应用支持多负责人,修复权限查询表名错误
- 业务组 MasterUid 改为 MasterUids(逗号分隔多用户ID) - 应用 OwnerId 改为 OwnerIds(逗号分隔多用户ID) - 前端负责人下拉框改为多选 - 权限查询改用 FIND_IN_SET 匹配多负责人 - 修复 user_permissions 表名错误(应为 user_permission) - 所有数据库实体添加 TableName() 方法显式指定表名 - xorm tag 显式指定 owner_ids/master_uids 列名 - 启动时自动清理 owner_ids 中的空格
This commit is contained in:
@@ -22,6 +22,7 @@ func Init() error {
|
|||||||
}
|
}
|
||||||
Engine.SetMaxOpenConns(20)
|
Engine.SetMaxOpenConns(20)
|
||||||
Engine.SetMaxIdleConns(5)
|
Engine.SetMaxIdleConns(5)
|
||||||
|
Engine.ShowSQL(true)
|
||||||
|
|
||||||
// sync table structures
|
// sync table structures
|
||||||
if err := Engine.Sync2(
|
if err := Engine.Sync2(
|
||||||
@@ -38,10 +39,20 @@ func Init() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 迁移旧数据 & 清理格式
|
||||||
|
migrateOldData()
|
||||||
|
|
||||||
// insert initial data if tables are empty
|
// insert initial data if tables are empty
|
||||||
return initSeedData()
|
return initSeedData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func migrateOldData() {
|
||||||
|
// 清理 owner_ids 中可能存在的空格
|
||||||
|
Engine.Exec("UPDATE application SET owner_ids = REPLACE(owner_ids, ' ', '') WHERE owner_ids LIKE '% %'")
|
||||||
|
// 清理 master_uids 中可能存在的空格
|
||||||
|
Engine.Exec("UPDATE business_group SET master_uids = REPLACE(master_uids, ' ', '') WHERE master_uids LIKE '% %'")
|
||||||
|
}
|
||||||
|
|
||||||
func initSeedData() error {
|
func initSeedData() error {
|
||||||
// check if profiles table is empty
|
// check if profiles table is empty
|
||||||
count, err := Engine.Count(new(model.Profile))
|
count, err := Engine.Count(new(model.Profile))
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"kenaito-conf/server/internal/model"
|
"kenaito-conf/server/internal/model"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -36,22 +37,30 @@ func (h *AppHandler) List(c *gin.Context) {
|
|||||||
query := dao.Engine.Where("enabled = 1")
|
query := dao.Engine.Where("enabled = 1")
|
||||||
|
|
||||||
if !userInfo.IsSuperAdmin() {
|
if !userInfo.IsSuperAdmin() {
|
||||||
if userInfo.IsGroupAdmin() && userInfo.GroupId != nil {
|
|
||||||
query = query.And("group_id = ?", *userInfo.GroupId)
|
|
||||||
} else {
|
|
||||||
userId, _ := strconv.Atoi(userInfo.Id)
|
userId, _ := strconv.Atoi(userInfo.Id)
|
||||||
query = query.And("(owner_id = ? OR id IN (SELECT app_id FROM user_permissions WHERE user_id = ?))", userId, userId)
|
userIdStr := strconv.Itoa(userId)
|
||||||
|
|
||||||
|
if userInfo.IsGroupAdmin() && userInfo.GroupId != nil {
|
||||||
|
// 组管理员:本组应用 + 自己是负责人的应用
|
||||||
|
query = query.And("(group_id = ? OR FIND_IN_SET('" + userIdStr + "', owner_ids) > 0 OR id IN (SELECT app_id FROM user_permission WHERE user_id = ?))", *userInfo.GroupId, userId)
|
||||||
|
} else {
|
||||||
|
// 普通用户:自己是负责人的应用 + 被授权的应用
|
||||||
|
query = query.And("(FIND_IN_SET('" + userIdStr + "', owner_ids) > 0 OR id IN (SELECT app_id FROM user_permission WHERE user_id = ?))", userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var apps []model.Application
|
var apps []model.Application
|
||||||
whereClause := "enabled = 1"
|
whereClause := "enabled = 1"
|
||||||
if !userInfo.IsSuperAdmin() {
|
if !userInfo.IsSuperAdmin() {
|
||||||
if userInfo.IsGroupAdmin() && userInfo.GroupId != nil {
|
|
||||||
whereClause += " AND group_id = " + strconv.Itoa(*userInfo.GroupId)
|
|
||||||
} else {
|
|
||||||
userId, _ := strconv.Atoi(userInfo.Id)
|
userId, _ := strconv.Atoi(userInfo.Id)
|
||||||
whereClause += " AND (owner_id = " + strconv.Itoa(userId) + " OR id IN (SELECT app_id FROM user_permissions WHERE user_id = " + strconv.Itoa(userId) + "))"
|
userIdStr := strconv.Itoa(userId)
|
||||||
|
|
||||||
|
if userInfo.IsGroupAdmin() && userInfo.GroupId != nil {
|
||||||
|
// 组管理员:本组应用 + 自己是负责人的应用
|
||||||
|
whereClause += " AND (group_id = " + strconv.Itoa(*userInfo.GroupId) + " OR FIND_IN_SET('" + userIdStr + "', owner_ids) > 0 OR id IN (SELECT app_id FROM user_permission WHERE user_id = " + strconv.Itoa(userId) + "))"
|
||||||
|
} else {
|
||||||
|
// 普通用户:自己是负责人的应用 + 被授权的应用
|
||||||
|
whereClause += " AND (FIND_IN_SET('" + userIdStr + "', owner_ids) > 0 OR id IN (SELECT app_id FROM user_permission WHERE user_id = " + strconv.Itoa(userId) + "))"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if req.AppType != "" {
|
if req.AppType != "" {
|
||||||
@@ -106,7 +115,7 @@ type AddAppRequest struct {
|
|||||||
Name string `json:"name" binding:"required"`
|
Name string `json:"name" binding:"required"`
|
||||||
Code string `json:"code" binding:"required"`
|
Code string `json:"code" binding:"required"`
|
||||||
ServiceId string `json:"serviceId"`
|
ServiceId string `json:"serviceId"`
|
||||||
OwnerId *int `json:"ownerId"`
|
OwnerIds []int `json:"ownerIds"`
|
||||||
Remarks string `json:"remarks"`
|
Remarks string `json:"remarks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,25 +135,35 @@ func (h *AppHandler) Add(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ownerId := req.OwnerId
|
// 处理负责人:如果未指定,默认为当前用户
|
||||||
if ownerId == nil {
|
ownerIds := req.OwnerIds
|
||||||
|
if len(ownerIds) == 0 {
|
||||||
uid, _ := strconv.Atoi(userInfo.Id)
|
uid, _ := strconv.Atoi(userInfo.Id)
|
||||||
ownerId = &uid
|
ownerIds = []int{uid}
|
||||||
}
|
}
|
||||||
|
|
||||||
var owner model.User
|
// 验证所有用户ID都存在
|
||||||
if has, _ := dao.Engine.ID(*ownerId).Get(&owner); !has {
|
var users []model.User
|
||||||
c.JSON(http.StatusOK, model.WrapperResponse{Code: 400, Msg: "负责人不存在"})
|
if err := dao.Engine.In("id", ownerIds).Find(&users); err != nil || len(users) != len(ownerIds) {
|
||||||
|
c.JSON(http.StatusOK, model.WrapperResponse{Code: 400, Msg: "部分负责人不存在"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建逗号分隔的用户名和ID字符串
|
||||||
|
ownerNames := make([]string, 0, len(users))
|
||||||
|
ownerIdStrs := make([]string, 0, len(users))
|
||||||
|
for _, u := range users {
|
||||||
|
ownerNames = append(ownerNames, u.Name)
|
||||||
|
ownerIdStrs = append(ownerIdStrs, strconv.Itoa(u.Id))
|
||||||
|
}
|
||||||
|
|
||||||
app := model.Application{
|
app := model.Application{
|
||||||
GroupId: req.GroupId,
|
GroupId: req.GroupId,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Code: req.Code,
|
Code: req.Code,
|
||||||
ServiceId: req.ServiceId,
|
ServiceId: req.ServiceId,
|
||||||
OwnerId: ownerId,
|
OwnerIds: strings.Join(ownerIdStrs, ","),
|
||||||
OwnerName: owner.Name,
|
OwnerNames: strings.Join(ownerNames, ","),
|
||||||
Remarks: req.Remarks,
|
Remarks: req.Remarks,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
CreatedAt: func() *time.Time { t := time.Now(); return &t }(),
|
CreatedAt: func() *time.Time { t := time.Now(); return &t }(),
|
||||||
@@ -180,20 +199,32 @@ func (h *AppHandler) Update(c *gin.Context) {
|
|||||||
app.Name = req.Name
|
app.Name = req.Name
|
||||||
app.ServiceId = req.ServiceId
|
app.ServiceId = req.ServiceId
|
||||||
app.Remarks = req.Remarks
|
app.Remarks = req.Remarks
|
||||||
if req.OwnerId != nil {
|
|
||||||
if app.OwnerId == nil || *req.OwnerId != *app.OwnerId {
|
// 更新负责人
|
||||||
var owner model.User
|
if len(req.OwnerIds) > 0 {
|
||||||
if has, _ := dao.Engine.ID(*req.OwnerId).Get(&owner); has {
|
// 验证所有用户ID都存在
|
||||||
app.OwnerName = owner.Name
|
var users []model.User
|
||||||
|
if err := dao.Engine.In("id", req.OwnerIds).Find(&users); err != nil || len(users) != len(req.OwnerIds) {
|
||||||
|
c.JSON(http.StatusOK, model.WrapperResponse{Code: 400, Msg: "部分负责人不存在"})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建逗号分隔的用户名和ID字符串
|
||||||
|
ownerNames := make([]string, 0, len(users))
|
||||||
|
ownerIdStrs := make([]string, 0, len(users))
|
||||||
|
for _, u := range users {
|
||||||
|
ownerNames = append(ownerNames, u.Name)
|
||||||
|
ownerIdStrs = append(ownerIdStrs, strconv.Itoa(u.Id))
|
||||||
}
|
}
|
||||||
app.OwnerId = req.OwnerId
|
app.OwnerIds = strings.Join(ownerIdStrs, ",")
|
||||||
|
app.OwnerNames = strings.Join(ownerNames, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UpdatedBy = userInfo.Name
|
app.UpdatedBy = userInfo.Name
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
app.UpdatedAt = &now
|
app.UpdatedAt = &now
|
||||||
|
|
||||||
dao.Engine.ID(app.Id).Cols("name", "service_id", "remarks", "owner_id", "owner_name", "updated_by", "updated_at").Update(&app)
|
dao.Engine.ID(app.Id).Cols("name", "service_id", "remarks", "owner_ids", "owner_names", "updated_by", "updated_at").Update(&app)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, model.WrapperResponse{Code: 0, Data: true})
|
c.JSON(http.StatusOK, model.WrapperResponse{Code: 0, Data: true})
|
||||||
}
|
}
|
||||||
@@ -255,7 +286,8 @@ func (h *AppHandler) Options(c *gin.Context) {
|
|||||||
query = query.And("group_id = ?", *userInfo.GroupId)
|
query = query.And("group_id = ?", *userInfo.GroupId)
|
||||||
} else {
|
} else {
|
||||||
userId, _ := strconv.Atoi(userInfo.Id)
|
userId, _ := strconv.Atoi(userInfo.Id)
|
||||||
query = query.And("owner_id = ?", userId)
|
userIdStr := strconv.Itoa(userId)
|
||||||
|
query = query.And("FIND_IN_SET(?, owner_ids) > 0", userIdStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"kenaito-conf/server/internal/model"
|
"kenaito-conf/server/internal/model"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -37,7 +38,7 @@ func (h *GroupHandler) GetById(c *gin.Context) {
|
|||||||
type AddGroupRequest struct {
|
type AddGroupRequest struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
Name string `json:"name" binding:"required"`
|
Name string `json:"name" binding:"required"`
|
||||||
MasterUid *int `json:"masterUid" binding:"required"`
|
MasterUids []int `json:"masterUids" binding:"required"`
|
||||||
Remarks string `json:"remarks"`
|
Remarks string `json:"remarks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,16 +61,25 @@ func (h *GroupHandler) Add(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var master model.User
|
// 验证所有用户ID都存在
|
||||||
if has, _ := dao.Engine.ID(*req.MasterUid).Get(&master); !has {
|
var users []model.User
|
||||||
c.JSON(http.StatusOK, model.WrapperResponse{Code: 400, Msg: "管理员不存在"})
|
if err := dao.Engine.In("id", req.MasterUids).Find(&users); err != nil || len(users) != len(req.MasterUids) {
|
||||||
|
c.JSON(http.StatusOK, model.WrapperResponse{Code: 400, Msg: "部分管理员不存在"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建逗号分隔的用户名和ID字符串
|
||||||
|
masterNames := make([]string, 0, len(users))
|
||||||
|
masterIds := make([]string, 0, len(users))
|
||||||
|
for _, u := range users {
|
||||||
|
masterNames = append(masterNames, u.Name)
|
||||||
|
masterIds = append(masterIds, strconv.Itoa(u.Id))
|
||||||
|
}
|
||||||
|
|
||||||
group := model.BusinessGroup{
|
group := model.BusinessGroup{
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Master: master.Name,
|
Master: strings.Join(masterNames, ","),
|
||||||
MasterUid: req.MasterUid,
|
MasterUids: strings.Join(masterIds, ","),
|
||||||
Remarks: req.Remarks,
|
Remarks: req.Remarks,
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
CreatedAt: func() *time.Time { t := time.Now(); return &t }(),
|
CreatedAt: func() *time.Time { t := time.Now(); return &t }(),
|
||||||
@@ -106,20 +116,30 @@ func (h *GroupHandler) Update(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证所有用户ID都存在
|
||||||
|
var users []model.User
|
||||||
|
if err := dao.Engine.In("id", req.MasterUids).Find(&users); err != nil || len(users) != len(req.MasterUids) {
|
||||||
|
c.JSON(http.StatusOK, model.WrapperResponse{Code: 400, Msg: "部分管理员不存在"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建逗号分隔的用户名和ID字符串
|
||||||
|
masterNames := make([]string, 0, len(users))
|
||||||
|
masterIds := make([]string, 0, len(users))
|
||||||
|
for _, u := range users {
|
||||||
|
masterNames = append(masterNames, u.Name)
|
||||||
|
masterIds = append(masterIds, strconv.Itoa(u.Id))
|
||||||
|
}
|
||||||
|
|
||||||
group.Name = req.Name
|
group.Name = req.Name
|
||||||
|
group.Master = strings.Join(masterNames, ",")
|
||||||
|
group.MasterUids = strings.Join(masterIds, ",")
|
||||||
group.Remarks = req.Remarks
|
group.Remarks = req.Remarks
|
||||||
if req.MasterUid != nil && (group.MasterUid == nil || *req.MasterUid != *group.MasterUid) {
|
|
||||||
var master model.User
|
|
||||||
if has, _ := dao.Engine.ID(*req.MasterUid).Get(&master); has {
|
|
||||||
group.Master = master.Name
|
|
||||||
group.MasterUid = req.MasterUid
|
|
||||||
}
|
|
||||||
}
|
|
||||||
group.UpdatedBy = userInfo.Name
|
group.UpdatedBy = userInfo.Name
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
group.UpdatedAt = &now
|
group.UpdatedAt = &now
|
||||||
|
|
||||||
dao.Engine.ID(group.Id).Cols("name", "remarks", "master", "master_uid", "updated_by", "updated_at").Update(&group)
|
dao.Engine.ID(group.Id).Cols("name", "remarks", "master", "master_uids", "updated_by", "updated_at").Update(&group)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, model.WrapperResponse{Code: 0})
|
c.JSON(http.StatusOK, model.WrapperResponse{Code: 0})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ type AppConfig struct {
|
|||||||
ClientCount int `xorm:"-" json:"clientCount,omitempty"`
|
ClientCount int `xorm:"-" json:"clientCount,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (AppConfig) TableName() string {
|
||||||
|
return "app_config"
|
||||||
|
}
|
||||||
|
|
||||||
type AppConfigHistory struct {
|
type AppConfigHistory struct {
|
||||||
Id int `xorm:"int autoincr pk" json:"id"`
|
Id int `xorm:"int autoincr pk" json:"id"`
|
||||||
OriginId int `xorm:"int" json:"originId"`
|
OriginId int `xorm:"int" json:"originId"`
|
||||||
@@ -37,3 +41,7 @@ type AppConfigHistory struct {
|
|||||||
CreatedAt *time.Time `xorm:"datetime" json:"createdAt"`
|
CreatedAt *time.Time `xorm:"datetime" json:"createdAt"`
|
||||||
CreatedBy string `xorm:"varchar(32)" json:"createdBy"`
|
CreatedBy string `xorm:"varchar(32)" json:"createdBy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (AppConfigHistory) TableName() string {
|
||||||
|
return "app_config_history"
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ type Application struct {
|
|||||||
Code string `xorm:"varchar(32)" json:"code"`
|
Code string `xorm:"varchar(32)" json:"code"`
|
||||||
ServiceId string `xorm:"varchar(64)" json:"serviceId"`
|
ServiceId string `xorm:"varchar(64)" json:"serviceId"`
|
||||||
Token string `xorm:"varchar(64)" json:"token"`
|
Token string `xorm:"varchar(64)" json:"token"`
|
||||||
OwnerId *int `xorm:"int" json:"ownerId"`
|
OwnerIds string `xorm:"varchar(255) 'owner_ids'" json:"ownerIds"`
|
||||||
OwnerName string `xorm:"varchar(16)" json:"ownerName"`
|
OwnerNames string `xorm:"varchar(255) 'owner_names'" json:"ownerNames"`
|
||||||
Remarks string `xorm:"text" json:"remarks"`
|
Remarks string `xorm:"text" json:"remarks"`
|
||||||
Enabled bool `xorm:"tinyint(1) default 1" json:"enabled"`
|
Enabled bool `xorm:"tinyint(1) default 1" json:"enabled"`
|
||||||
CreatedAt *time.Time `xorm:"datetime" json:"createdAt"`
|
CreatedAt *time.Time `xorm:"datetime" json:"createdAt"`
|
||||||
@@ -19,3 +19,7 @@ type Application struct {
|
|||||||
UpdatedBy string `xorm:"varchar(32)" json:"updatedBy"`
|
UpdatedBy string `xorm:"varchar(32)" json:"updatedBy"`
|
||||||
GroupName string `xorm:"-" json:"groupName,omitempty"`
|
GroupName string `xorm:"-" json:"groupName,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (Application) TableName() string {
|
||||||
|
return "application"
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import "time"
|
|||||||
type BusinessGroup struct {
|
type BusinessGroup struct {
|
||||||
Id int `xorm:"int autoincr pk" json:"id"`
|
Id int `xorm:"int autoincr pk" json:"id"`
|
||||||
Name string `xorm:"varchar(32) notnull" json:"name"`
|
Name string `xorm:"varchar(32) notnull" json:"name"`
|
||||||
Master string `xorm:"varchar(16)" json:"master"`
|
Master string `xorm:"varchar(255)" json:"master"`
|
||||||
MasterUid *int `xorm:"int" json:"masterUid"`
|
MasterUids string `xorm:"varchar(255) 'master_uids'" json:"masterUids"`
|
||||||
Remarks string `xorm:"text" json:"remarks"`
|
Remarks string `xorm:"text" json:"remarks"`
|
||||||
Enabled bool `xorm:"tinyint(1) default 1" json:"enabled"`
|
Enabled bool `xorm:"tinyint(1) default 1" json:"enabled"`
|
||||||
CreatedAt *time.Time `xorm:"datetime" json:"createdAt"`
|
CreatedAt *time.Time `xorm:"datetime" json:"createdAt"`
|
||||||
@@ -14,3 +14,7 @@ type BusinessGroup struct {
|
|||||||
UpdatedAt *time.Time `xorm:"datetime" json:"updatedAt"`
|
UpdatedAt *time.Time `xorm:"datetime" json:"updatedAt"`
|
||||||
UpdatedBy string `xorm:"varchar(32)" json:"updatedBy"`
|
UpdatedBy string `xorm:"varchar(32)" json:"updatedBy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (BusinessGroup) TableName() string {
|
||||||
|
return "business_group"
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,3 +14,7 @@ type ClientInstance struct {
|
|||||||
CreatedAt *time.Time `xorm:"datetime" json:"createdAt"`
|
CreatedAt *time.Time `xorm:"datetime" json:"createdAt"`
|
||||||
UpdatedAt *time.Time `xorm:"datetime" json:"updatedAt"`
|
UpdatedAt *time.Time `xorm:"datetime" json:"updatedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ClientInstance) TableName() string {
|
||||||
|
return "client_instance"
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,9 +12,17 @@ type Profile struct {
|
|||||||
UpdatedAt *time.Time `xorm:"datetime" json:"updatedAt"`
|
UpdatedAt *time.Time `xorm:"datetime" json:"updatedAt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (Profile) TableName() string {
|
||||||
|
return "profile"
|
||||||
|
}
|
||||||
|
|
||||||
type AppExtrAttr struct {
|
type AppExtrAttr struct {
|
||||||
AppId int `xorm:"int pk" json:"appId"`
|
AppId int `xorm:"int pk" json:"appId"`
|
||||||
Env string `xorm:"varchar(16) pk" json:"env"`
|
Env string `xorm:"varchar(16) pk" json:"env"`
|
||||||
AttrName string `xorm:"varchar(32) pk" json:"attrName"`
|
AttrName string `xorm:"varchar(32) pk" json:"attrName"`
|
||||||
AttrValue string `xorm:"varchar(100)" json:"attrValue"`
|
AttrValue string `xorm:"varchar(100)" json:"attrValue"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (AppExtrAttr) TableName() string {
|
||||||
|
return "app_extr_attr"
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ type User struct {
|
|||||||
GroupMaster bool `xorm:"-" json:"groupMaster,omitempty"`
|
GroupMaster bool `xorm:"-" json:"groupMaster,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (User) TableName() string {
|
||||||
|
return "user"
|
||||||
|
}
|
||||||
|
|
||||||
type UserPermission struct {
|
type UserPermission struct {
|
||||||
Id int `xorm:"int autoincr pk" json:"id"`
|
Id int `xorm:"int autoincr pk" json:"id"`
|
||||||
UserId int `xorm:"int" json:"userId"`
|
UserId int `xorm:"int" json:"userId"`
|
||||||
@@ -26,6 +30,10 @@ type UserPermission struct {
|
|||||||
Operate string `xorm:"varchar(8) default 'RW'" json:"operate"` // RO, RW
|
Operate string `xorm:"varchar(8) default 'RW'" json:"operate"` // RO, RW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (UserPermission) TableName() string {
|
||||||
|
return "user_permission"
|
||||||
|
}
|
||||||
|
|
||||||
type LoginUserInfo struct {
|
type LoginUserInfo struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|||||||
@@ -141,7 +141,8 @@ func (s *AuthService) loadPermissions(userInfo *model.LoginUserInfo, userId int)
|
|||||||
if userInfo.IsGroupAdmin() {
|
if userInfo.IsGroupAdmin() {
|
||||||
dao.Engine.Where("group_id = ?", userInfo.GroupId).Find(&apps)
|
dao.Engine.Where("group_id = ?", userInfo.GroupId).Find(&apps)
|
||||||
} else {
|
} else {
|
||||||
dao.Engine.Where("owner_id = ?", userId).Find(&apps)
|
userIdStr := strconv.Itoa(userId)
|
||||||
|
dao.Engine.Where("FIND_IN_SET(?, owner_ids) > 0", userIdStr).Find(&apps)
|
||||||
}
|
}
|
||||||
for _, app := range apps {
|
for _, app := range apps {
|
||||||
userInfo.GrantAppIds = append(userInfo.GrantAppIds, app.Id)
|
userInfo.GrantAppIds = append(userInfo.GrantAppIds, app.Id)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
<el-table-column prop="name" label="应用名称"></el-table-column>
|
<el-table-column prop="name" label="应用名称"></el-table-column>
|
||||||
<el-table-column prop="code" label="应用编码"></el-table-column>
|
<el-table-column prop="code" label="应用编码"></el-table-column>
|
||||||
<el-table-column prop="groupName" label="所属业务组" width="120"></el-table-column>
|
<el-table-column prop="groupName" label="所属业务组" width="120"></el-table-column>
|
||||||
<el-table-column prop="ownerName" label="负责人" width="100"></el-table-column>
|
<el-table-column prop="ownerNames" label="负责人" width="100"></el-table-column>
|
||||||
<el-table-column prop="token" label="Token" width="200">
|
<el-table-column prop="token" label="Token" width="200">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<template v-if="scope.row.token">
|
<template v-if="scope.row.token">
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="负责人">
|
<el-form-item label="负责人">
|
||||||
<el-select v-model="form.ownerId" placeholder="请选择">
|
<el-select v-model="form.ownerIds" multiple placeholder="请选择">
|
||||||
<el-option v-for="u in users" :key="u.value" :label="u.label" :value="parseInt(u.value)"></el-option>
|
<el-option v-for="u in users" :key="u.value" :label="u.label" :value="parseInt(u.value)"></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@@ -126,12 +126,18 @@ export default {
|
|||||||
},
|
},
|
||||||
showAdd() {
|
showAdd() {
|
||||||
this.dialogTitle = '新建应用'
|
this.dialogTitle = '新建应用'
|
||||||
this.form = { name: '', code: '', groupId: null, ownerId: null, remarks: '' }
|
this.form = { name: '', code: '', groupId: null, ownerIds: [], remarks: '' }
|
||||||
this.dialogVisible = true
|
this.dialogVisible = true
|
||||||
},
|
},
|
||||||
showEdit(row) {
|
showEdit(row) {
|
||||||
this.dialogTitle = '编辑应用'
|
this.dialogTitle = '编辑应用'
|
||||||
this.form = { ...row }
|
this.form = { ...row }
|
||||||
|
// 将逗号分隔的ID字符串转为数组
|
||||||
|
if (typeof this.form.ownerIds === 'string' && this.form.ownerIds) {
|
||||||
|
this.form.ownerIds = this.form.ownerIds.split(',').map(Number)
|
||||||
|
} else if (!Array.isArray(this.form.ownerIds)) {
|
||||||
|
this.form.ownerIds = []
|
||||||
|
}
|
||||||
this.dialogVisible = true
|
this.dialogVisible = true
|
||||||
},
|
},
|
||||||
handleSubmit() {
|
handleSubmit() {
|
||||||
|
|||||||
@@ -31,8 +31,8 @@
|
|||||||
<el-form-item label="组名称" prop="name">
|
<el-form-item label="组名称" prop="name">
|
||||||
<el-input v-model="form.name"></el-input>
|
<el-input v-model="form.name"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="负责人" prop="masterUid">
|
<el-form-item label="负责人" prop="masterUids">
|
||||||
<el-select v-model="form.masterUid" placeholder="请选择">
|
<el-select v-model="form.masterUids" multiple placeholder="请选择">
|
||||||
<el-option v-for="u in users" :key="u.value" :label="u.label" :value="parseInt(u.value)"></el-option>
|
<el-option v-for="u in users" :key="u.value" :label="u.label" :value="parseInt(u.value)"></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@@ -62,7 +62,7 @@ export default {
|
|||||||
form: {},
|
form: {},
|
||||||
rules: {
|
rules: {
|
||||||
name: [{ required: true, message: '请输入组名称', trigger: 'blur' }],
|
name: [{ required: true, message: '请输入组名称', trigger: 'blur' }],
|
||||||
masterUid: [{ required: true, message: '请选择负责人', trigger: 'change' }]
|
masterUids: [{ required: true, message: '请选择负责人', trigger: 'change', type: 'array', min: 1 }]
|
||||||
},
|
},
|
||||||
users: []
|
users: []
|
||||||
}
|
}
|
||||||
@@ -105,12 +105,18 @@ export default {
|
|||||||
},
|
},
|
||||||
showAdd() {
|
showAdd() {
|
||||||
this.dialogTitle = '新建业务组'
|
this.dialogTitle = '新建业务组'
|
||||||
this.form = { name: '', masterUid: null, remarks: '' }
|
this.form = { name: '', masterUids: [], remarks: '' }
|
||||||
this.dialogVisible = true
|
this.dialogVisible = true
|
||||||
},
|
},
|
||||||
showEdit(row) {
|
showEdit(row) {
|
||||||
this.dialogTitle = '编辑业务组'
|
this.dialogTitle = '编辑业务组'
|
||||||
this.form = { ...row }
|
this.form = { ...row }
|
||||||
|
// 将逗号分隔的ID字符串转为数组
|
||||||
|
if (typeof this.form.masterUids === 'string' && this.form.masterUids) {
|
||||||
|
this.form.masterUids = this.form.masterUids.split(',').map(Number)
|
||||||
|
} else {
|
||||||
|
this.form.masterUids = []
|
||||||
|
}
|
||||||
this.dialogVisible = true
|
this.dialogVisible = true
|
||||||
},
|
},
|
||||||
handleSubmit() {
|
handleSubmit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user