Przeglądaj źródła

Merge branch 'hotfix/bug7230_role_type' into debug

# Conflicts:
#	controllers/sys_role.go
xyxie 1 tydzień temu
rodzic
commit
9d4a50de02
2 zmienionych plików z 21 dodań i 0 usunięć
  1. 13 0
      controllers/sys_role.go
  2. 8 0
      models/system/sys_role.go

+ 13 - 0
controllers/sys_role.go

@@ -122,6 +122,9 @@ func (this *SysRoleController) Edit() {
 		br.Msg = "admin用户不可编辑"
 		return
 	}
+
+	oldRoleCodeType := item.RoleTypeCode
+	oldRoleName := item.RoleName
 	exists, e := system.GetSysRoleByName(req.RoleName)
 	if e != nil && !utils.IsErrNoRow(e) {
 		br.Msg = "操作失败"
@@ -140,6 +143,16 @@ func (this *SysRoleController) Edit() {
 		return
 	}
 
+	if oldRoleName != req.RoleName || oldRoleCodeType != roleTypeCode {
+		// 查询所有和角色相关的管理员的信息,并更新成最新的角色
+		err = system.UpdateAdminRoleInfoByRoleId(req.RoleId, req.RoleName, roleTypeCode)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "更新管理员角色信息失败, Err: " + err.Error()
+			return
+		}
+	}
+
 	// 同步角色缓存
 	if utils.BusinessCode == utils.BusinessCodeRelease {
 		var syncData system.SyncRoleData

+ 8 - 0
models/system/sys_role.go

@@ -285,3 +285,11 @@ func GetSysRoleByIdList(id []int) (items []*SysRole, err error) {
 	err = o.Raw(sql, id).Find(&items).Error
 	return
 }
+
+
+// 更新所有管理员的角色信息
+func UpdateAdminRoleInfoByRoleId(roleId int, roleName, roleCodeType string) (err error) {
+	sql := `UPDATE admin SET role_name=?, role_code_type=? WHERE role_id=?`
+	err = global.DbMap[utils.DbNameMaster].Exec(sql, roleName, roleCodeType, roleId).Error
+	return
+}