-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Fix the mysql root account permission switchover exception #8378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code has several optimizations and corrections:
This refactored version of the function ensures cleaner logic by reducing nested structures where possible: |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no major irregularities or obvious issues in this code snippet, but there are some areas that can be optimized or improved:
Here is a revised version incorporating these suggestions: if (formEl && formEl.validate(async valid => {
if (!valid) {
return;
}
await validateEmail(changeForm.from);
if (changeForm.privilege === oldPrivilege.value && equalArrays(changeForm.privilegeIPs, oldPrivilegeIPs.value)) {
changeVisible.value = false;
return;
}
if (changeForm.privilege !== 'ip') {
param.value = changeForm.privilege;
} else {
// continue processing
}
})):Function function equalArrays(a, b) {
if (a.length !== b.length)
return false;
for (let i = 0; i < a.length; i++)
if (a[i] !== b[i])
return false;
return true;
}These improvements should enhance readability, maintainability, and potentially performance marginally. |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The given code snippet contains two main logic branches:
Regular Branch:
info.Permissionis equal toinfo.OldPermission.nil, effectively skipping the deletion step.Special Case for Root User:
info.Username) is "root", it also skips the deletion process.Potential Issues and Improvements:
Code Reorganization:
info.Permission == info.OldPermissioninto a separate function call to improve readability and maintainability.Error Handling:
CreateUser. Although it catches errors fromDeleteInfo, handling other functions should also be considered within this scope.Documentation/Comments:
Variable Naming:
Overall, the overall structure looks clean and well-organized, but these minor improvements can enhance its clarity and robustness.