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.Password = r.Password
}
if info.Permission == info.OldPermission {
return nil
}
if err := r.Delete(DeleteInfo{
Version: info.Version,
Username: info.Username,
Permission: info.OldPermission,
ForceDelete: true,
Timeout: 300}); err != nil {
return err
}
if info.Username == "root" {
return nil
if info.Permission != info.OldPermission {
if err := r.Delete(DeleteInfo{
Version: info.Version,
Username: info.Username,
Permission: info.OldPermission,
ForceDelete: true,
Timeout: 300}); err != nil {
return err
}
if info.Username == "root" {
return nil
}
}
if err := r.CreateUser(CreateInfo{
Name: info.Name,

View file

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

View file

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