mirror of https://github.com/MISP/MISP
fix: [UI] Handling non exists user setting
parent
44db6accb3
commit
b29c0ccaca
|
@ -213,27 +213,28 @@ class UserSettingsController extends AppController
|
|||
if ($this->_isRest()) {
|
||||
// GET request via the API should describe the endpoint
|
||||
return $this->RestResponse->describe('UserSettings', 'setSetting', false, $this->response->type());
|
||||
} else {
|
||||
// load the valid settings from the model
|
||||
if ($this->_isSiteAdmin()) {
|
||||
$users = $this->UserSetting->User->find('list', array(
|
||||
'fields' => array('User.id', 'User.email')
|
||||
));
|
||||
} else if ($this->_isAdmin()) {
|
||||
$users = $this->UserSetting->User->find('list', array(
|
||||
'conditions' => array('User.org_id' => $this->Auth->user('org_id')),
|
||||
'fields' => array('User.id', 'User.email')
|
||||
));
|
||||
} else {
|
||||
$users = array($this->Auth->user('id') => $this->Auth->user('email'));
|
||||
}
|
||||
if (!empty($user_id) && $this->request->is('get')) {
|
||||
$this->request->data['UserSetting']['user_id'] = $user_id;
|
||||
}
|
||||
$this->set('setting', $setting);
|
||||
$this->set('users', $users);
|
||||
$this->set('validSettings', $this->UserSetting->settingPlaceholders($this->Auth->user()));
|
||||
}
|
||||
|
||||
// load the valid settings from the model
|
||||
if ($this->_isSiteAdmin()) {
|
||||
$users = $this->UserSetting->User->find('list', array(
|
||||
'fields' => array('User.id', 'User.email')
|
||||
));
|
||||
} else if ($this->_isAdmin()) {
|
||||
$users = $this->UserSetting->User->find('list', array(
|
||||
'conditions' => array('User.org_id' => $this->Auth->user('org_id')),
|
||||
'fields' => array('User.id', 'User.email')
|
||||
));
|
||||
} else {
|
||||
$users = array($this->Auth->user('id') => $this->Auth->user('email'));
|
||||
}
|
||||
if (!empty($user_id) && $this->request->is('get')) {
|
||||
$this->request->data['UserSetting']['user_id'] = $user_id;
|
||||
}
|
||||
$this->set('setting', $setting);
|
||||
$this->set('users', $users);
|
||||
$this->set('validSettings', $this->UserSetting->settingPlaceholders($this->Auth->user()));
|
||||
$this->set('title_for_layout', __('Set User Setting'));
|
||||
}
|
||||
|
||||
public function getSetting($userId = null, $setting = null)
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
array(
|
||||
'div' => 'clear',
|
||||
'class' => 'input input-xxlarge',
|
||||
'options' => array($users),
|
||||
'options' => $users,
|
||||
'disabled' => count($users) === 1
|
||||
)
|
||||
),
|
||||
|
@ -40,18 +40,16 @@
|
|||
?>
|
||||
<script type="text/javascript">
|
||||
var validSettings = <?= json_encode($validSettings); ?>;
|
||||
|
||||
$(function() {
|
||||
loadUserSettingValue();
|
||||
changeUserSettingPlaceholder();
|
||||
$('#UserSettingSetting').on('change', function() {
|
||||
loadUserSettingValue();
|
||||
changeUserSettingPlaceholder();
|
||||
});
|
||||
$('#UserSettingUserId').on('change', function() {
|
||||
$('#UserSettingSetting, #UserSettingUserId').on('change', function() {
|
||||
loadUserSettingValue();
|
||||
changeUserSettingPlaceholder();
|
||||
});
|
||||
});
|
||||
|
||||
function loadUserSettingValue() {
|
||||
var user_id = $('#UserSettingUserId').val();
|
||||
var setting = $('#UserSettingSetting').val();
|
||||
|
@ -66,6 +64,13 @@
|
|||
data = JSON.stringify(data, undefined, 4);
|
||||
}
|
||||
$('#UserSettingValue').val(data);
|
||||
},
|
||||
error: function (xhr) {
|
||||
if (xhr.status === 404) {
|
||||
$('#UserSettingValue').val('');
|
||||
} else {
|
||||
xhrFailCallback(xhr);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue