Implement review fixes - change modal constructor and add translation keys

This commit is contained in:
DianaXWiki 2024-07-16 11:40:44 +03:00
parent 9c032931d6
commit e4da9285d0
2 changed files with 27 additions and 65 deletions

View File

@ -133,7 +133,8 @@ define(req, function(AppConfig, Default, Language) {
return text;
}
};
Messages.admin_mfa_confirm_enable = "Are you sure you want to enable Multi-Factor Authentication?"; // XXX
Messages.admin_mfa_confirm_disable = "Are you sure you want to disable Multi-Factor Authentication?"; // XXX
return Messages;
});

View File

@ -579,71 +579,32 @@ define([
},
query: function (val, setState) {
var isChecked = APP.instanceStatus.enforceMFA;
var confirmationContent = isChecked
? 'Are you sure you want to disable enforced MFA? This action would lessen the security of your account.'
: 'Are you sure you want to enforce MFA? This action would require to set up an authenticator app.';
function showConfirmationModal(callback) {
var modal = UI.dialog.customModal(confirmationContent, {
buttons: [{
className: 'cancel',
name: Messages.cancel,
onClick: function () {
if (!isChecked) {
sFrameChan.query('Q_ADMIN_RPC', {
cmd: 'ADMIN_DECREE',
data: ['ENFORCE_MFA', [false]]
}, function (e, response) {
if (e || response.error) {
UI.warn(Messages.error);
console.error(e, response);
} else {
APP.updateStatus(function () {
setState(false);
flushCache();
});
}
});
}
//check the checkbox again
else {
APP.updateStatus(function () {
setState(APP.instanceStatus.enforceMFA);
flushCache();
});
}
},
keys: [27] // Esc key to close modal
}, {
className: 'primary',
name: Messages.settings_save,
onClick: function () {
sFrameChan.query('Q_ADMIN_RPC', {
cmd: 'ADMIN_DECREE',
data: ['ENFORCE_MFA', [val]]
}, function (e, response) {
if (e || response.error) {
UI.warn(Messages.error);
console.error(e, response);
} else {
APP.updateStatus(function () {
setState(APP.instanceStatus.enforceMFA);
flushCache();
});
}
});
},
keys: [13] // Enter key to confirm
}]
function showConfirmation(isChecked, setState) {
const confirmationContent = isChecked ? Messages.admin_mfa_confirm_disable : Messages.admin_mfa_confirm_enable;
UI.confirm(confirmationContent, function (confirmed) {
if (!confirmed) {
// User canceled their changes, restore the checkbox value
setState(isChecked);
return;
}
// User confirmed their changes, call the command and update the state
sFrameChan.query('Q_ADMIN_RPC', {
cmd: 'ADMIN_DECREE',
data: ['ENFORCE_MFA', [val]]
}, function (e, response) {
if (e || response.error) {
UI.warn(Messages.error);
console.error(e, response);
} else {
APP.updateStatus(function () {
setState(APP.instanceStatus.enforceMFA);
flushCache();
});
}
});
var $modal = $(modal);
UI.openCustomModal(modal);
$modal.closest('.alertify').on('mousedown', function (e) {
e.stopPropagation();
});
}
showConfirmationModal();
});
}
showConfirmation(isChecked, setState);
}
});