增加字典全局权限
This commit is contained in:
@@ -25,9 +25,18 @@ func (c *DictController) GetDictTypes() {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户ID
|
||||
userIdData := c.Ctx.Input.GetData("userId")
|
||||
userId := 0
|
||||
if userIdData != nil {
|
||||
if uid, ok := userIdData.(int); ok {
|
||||
userId = uid
|
||||
}
|
||||
}
|
||||
|
||||
parentId, _ := c.GetInt("parent_id", -1)
|
||||
statusStr := c.GetString("status")
|
||||
|
||||
|
||||
var status *int8
|
||||
if statusStr != "" {
|
||||
s, _ := strconv.ParseInt(statusStr, 10, 8)
|
||||
@@ -35,7 +44,7 @@ func (c *DictController) GetDictTypes() {
|
||||
status = &statusVal
|
||||
}
|
||||
|
||||
dictTypes, err := services.GetDictTypes(tenantId, parentId, status)
|
||||
dictTypes, err := services.GetDictTypes(tenantId, userId, parentId, status)
|
||||
if err != nil {
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
"success": false,
|
||||
@@ -109,6 +118,13 @@ func (c *DictController) AddDictType() {
|
||||
username = u
|
||||
}
|
||||
}
|
||||
userIdData := c.Ctx.Input.GetData("userId")
|
||||
userId := 0
|
||||
if userIdData != nil {
|
||||
if uid, ok := userIdData.(int); ok {
|
||||
userId = uid
|
||||
}
|
||||
}
|
||||
|
||||
// 设置租户ID和创建人
|
||||
dictType.TenantId = tenantId
|
||||
@@ -117,6 +133,17 @@ func (c *DictController) AddDictType() {
|
||||
dictType.Status = 1 // 默认启用
|
||||
}
|
||||
|
||||
// 根据用户角色设置是否全局展示
|
||||
// system_admin 和 admin 角色默认是全局,其他角色默认是租户私有
|
||||
dictType.IsGlobal = 0 // 默认为租户私有
|
||||
if userId > 0 {
|
||||
// 获取用户的角色信息
|
||||
roleCode, err := services.GetUserRoleCode(userId)
|
||||
if err == nil && (roleCode == "system_admin" || roleCode == "admin") {
|
||||
dictType.IsGlobal = 1 // system_admin 和 admin 角色默认全局
|
||||
}
|
||||
}
|
||||
|
||||
id, err := services.AddDictType(&dictType)
|
||||
if err != nil {
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
@@ -240,7 +267,7 @@ func (c *DictController) GetDictItems() {
|
||||
|
||||
parentIdStr := c.GetString("parent_id")
|
||||
statusStr := c.GetString("status")
|
||||
|
||||
|
||||
var parentId *int
|
||||
if parentIdStr != "" {
|
||||
pid, _ := strconv.Atoi(parentIdStr)
|
||||
@@ -508,4 +535,3 @@ func (c *DictController) BatchUpdateDictItemSort() {
|
||||
}
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user