fix: Fix the mysql root account permission switchover exception (#8378)
Some checks failed
SonarCloud Scan / SonarCloud (push) Has been cancelled

This commit is contained in:
ssongliu 2025-04-11 15:08:02 +08:00 committed by GitHub
parent e7670f96de
commit 600b769083
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 26 deletions

View file

@ -188,19 +188,18 @@ func (r *Local) ChangeAccess(info AccessChangeInfo) error {
info.Name = "*" info.Name = "*"
info.Password = r.Password info.Password = r.Password
} }
if info.Permission == info.OldPermission { if info.Permission != info.OldPermission {
return nil if err := r.Delete(DeleteInfo{
} Version: info.Version,
if err := r.Delete(DeleteInfo{ Username: info.Username,
Version: info.Version, Permission: info.OldPermission,
Username: info.Username, ForceDelete: true,
Permission: info.OldPermission, Timeout: 300}); err != nil {
ForceDelete: true, return err
Timeout: 300}); err != nil { }
return err if info.Username == "root" {
} return nil
if info.Username == "root" { }
return nil
} }
if err := r.CreateUser(CreateInfo{ if err := r.CreateUser(CreateInfo{
Name: info.Name, Name: info.Name,

View file

@ -199,19 +199,18 @@ func (r *Remote) ChangeAccess(info AccessChangeInfo) error {
info.Name = "*" info.Name = "*"
info.Password = r.Password info.Password = r.Password
} }
if info.Permission == info.OldPermission { if info.Permission != info.OldPermission {
return nil if err := r.Delete(DeleteInfo{
} Version: info.Version,
if err := r.Delete(DeleteInfo{ Username: info.Username,
Version: info.Version, Permission: info.OldPermission,
Username: info.Username, ForceDelete: true,
Permission: info.OldPermission, Timeout: 300}); err != nil {
ForceDelete: true, return err
Timeout: 300}); err != nil { }
return err if info.Username == "root" {
} return nil
if info.Username == "root" { }
return nil
} }
if err := r.CreateUser(CreateInfo{ if err := r.CreateUser(CreateInfo{
Name: info.Name, Name: info.Name,

View file

@ -74,6 +74,8 @@ const changeVisible = ref(false);
type FormInstance = InstanceType<typeof ElForm>; type FormInstance = InstanceType<typeof ElForm>;
const changeFormRef = ref<FormInstance>(); const changeFormRef = ref<FormInstance>();
const title = ref(); const title = ref();
const oldPrivilege = ref();
const oldPrivilegeIPs = ref();
const changeForm = reactive({ const changeForm = reactive({
id: 0, id: 0,
from: '', from: '',
@ -124,6 +126,8 @@ const acceptParams = (params: DialogProps): void => {
changeForm.privilegeIPs = params.privilegeIPs; changeForm.privilegeIPs = params.privilegeIPs;
changeForm.value = params.value; changeForm.value = params.value;
changeVisible.value = true; changeVisible.value = true;
oldPrivilege.value = params.privilege;
oldPrivilegeIPs.value = params.privilegeIPs;
}; };
const emit = defineEmits<{ (e: 'search'): void }>(); const emit = defineEmits<{ (e: 'search'): void }>();
@ -167,6 +171,10 @@ const submitChangeInfo = async (formEl: FormInstance | undefined) => {
} }
return; return;
} }
if (changeForm.privilege === oldPrivilege.value && changeForm.privilegeIPs === oldPrivilegeIPs.value) {
changeVisible.value = false;
return;
}
if (changeForm.privilege !== 'ip') { if (changeForm.privilege !== 'ip') {
param.value = changeForm.privilege; param.value = changeForm.privilege;
} else { } else {