mirror of https://github.com/Aidaho12/haproxy-wi
v7.2.5.0: Refactor execution of group changes in user settings
This commit streamlines the way user group data is handled, both in scripts and server-side logic. The group settings URL has been simplified and the logic for updating user groups also has been optimized. Eliminated unnecessary checks in the user.py module, and updated the routing logic for group data to utilize a single route with HTTP GET and PUT methods. Removed unsuccessful group changing errors.pull/384/head
parent
88471af613
commit
c56d105ef5
|
@ -56,13 +56,9 @@ def delete_user_groups(user_id):
|
|||
def update_user_current_groups(groups, user_uuid):
|
||||
user_id = get_user_id_by_uuid(user_uuid)
|
||||
try:
|
||||
user_update = User.update(groups=groups).where(User.user_id == user_id)
|
||||
user_update.execute()
|
||||
User.update(groups=groups).where(User.user_id == user_id).execute()
|
||||
except Exception as e:
|
||||
out_error(e)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def update_user_current_groups_by_id(groups, user_id):
|
||||
|
|
|
@ -98,12 +98,10 @@ def change_user_services(user: str, user_id: int, user_services: str) -> str:
|
|||
|
||||
def change_user_active_group(group_id: int, user_uuid: str) -> str:
|
||||
try:
|
||||
if user_sql.update_user_current_groups(group_id, user_uuid):
|
||||
return 'Ok'
|
||||
else:
|
||||
return 'error: Cannot change group'
|
||||
user_sql.update_user_current_groups(group_id, user_uuid)
|
||||
return 'Ok'
|
||||
except Exception as e:
|
||||
return f'error: Cannot change the group: {e}'
|
||||
roxywi_common.handle_exceptions(e, 'Roxy-WI server', 'Cannot change the group', roxywi=1, login=1)
|
||||
|
||||
|
||||
def get_user_active_group(uuid: str, group: str) -> str:
|
||||
|
|
|
@ -115,20 +115,17 @@ def show_user_services(user_id):
|
|||
return roxywi_user.change_user_services(user, user_id, user_services)
|
||||
|
||||
|
||||
@bp.route('/group/current')
|
||||
@bp.route('/group', methods=['GET', 'PUT'])
|
||||
def get_current_group():
|
||||
uuid = request.cookies.get('uuid')
|
||||
group = request.cookies.get('group')
|
||||
if request.method == 'GET':
|
||||
uuid = common.checkAjaxInput(request.cookies.get('uuid'))
|
||||
group = common.checkAjaxInput(request.cookies.get('group'))
|
||||
return roxywi_user.get_user_active_group(uuid, group)
|
||||
elif request.method == 'PUT':
|
||||
group_id = common.checkAjaxInput(request.form.get('group'))
|
||||
user_uuid = common.checkAjaxInput(request.form.get('uuid'))
|
||||
|
||||
return roxywi_user.get_user_active_group(uuid, group)
|
||||
|
||||
|
||||
@bp.post('/group/change')
|
||||
def change_current_group():
|
||||
group_id = common.checkAjaxInput(request.form.get('changeUserCurrentGroupId'))
|
||||
user_uuid = common.checkAjaxInput(request.form.get('changeUserGroupsUser'))
|
||||
|
||||
return roxywi_user.change_user_active_group(group_id, user_uuid)
|
||||
return roxywi_user.change_user_active_group(group_id, user_uuid)
|
||||
|
||||
|
||||
@bp.route('/groups/<int:user_id>')
|
||||
|
|
|
@ -941,7 +941,7 @@ $( function() {
|
|||
$('#disable_alerting').prop('checked', true).checkboxradio('refresh');
|
||||
}
|
||||
$.ajax({
|
||||
url: "/app/user/group/current",
|
||||
url: "/app/user/group",
|
||||
success: function (data) {
|
||||
if (data.indexOf('danger') != '-1') {
|
||||
$("#ajax").html(data);
|
||||
|
@ -1184,21 +1184,20 @@ createHistroy();
|
|||
listHistroy();
|
||||
|
||||
function changeCurrentGroupF() {
|
||||
Cookies.remove('group');
|
||||
Cookies.set('group', $('#newCurrentGroup').val(), {expires: 365, path: '/', samesite: 'strict', secure: 'true'});
|
||||
$.ajax({
|
||||
url: "/app/user/group/change",
|
||||
url: "/app/user/group",
|
||||
data: {
|
||||
changeUserCurrentGroupId: $('#newCurrentGroup').val(),
|
||||
changeUserGroupsUser: Cookies.get('uuid'),
|
||||
token: $('#token').val()
|
||||
group: $('#newCurrentGroup').val(),
|
||||
uuid: Cookies.get('uuid')
|
||||
},
|
||||
type: "POST",
|
||||
type: "PUT",
|
||||
success: function (data) {
|
||||
if (data.indexOf('error: ') != '-1') {
|
||||
toastr.error(data);
|
||||
} else {
|
||||
toastr.clear();
|
||||
Cookies.remove('group');
|
||||
Cookies.set('group', $('#newCurrentGroup').val(), {expires: 365, path: '/', samesite: 'strict', secure: 'true'});
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue