Skip to content

Commit

Permalink
[IMP] Replaced in ui POST /case/ioc/update/{identifier} by PUT /api/v…
Browse files Browse the repository at this point in the history
…2/iocs/{identifier}
  • Loading branch information
c8y3 committed Oct 18, 2024
1 parent a011e4b commit 88fee39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
10 changes: 5 additions & 5 deletions ui/src/pages/case.ioc.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,21 +249,21 @@ function update_ioc(ioc_id) {
data['ioc_description'] = g_ioc_desc_editor.getValue();
data['custom_attributes'] = attributes;

post_request_api(`/case/ioc/update/${ioc_id}`, JSON.stringify(data), true)
.done((data) => {
if (data.status == 'success') {
put_request_api(`/api/v2/iocs/${ioc_id}`, JSON.stringify(data))
.done((data, textStatus) => {
if (textStatus == 'success') {
reload_iocs();

$('#submit_new_ioc').text("Saved").addClass('btn-outline-success').removeClass('btn-outline-danger').removeClass('btn-outline-warning');
$('#last_saved').removeClass('btn-danger').addClass('btn-success');
$('#last_saved > i').attr('class', "fa-solid fa-file-circle-check");
$('#last_saved > i').attr('class', 'fa-solid fa-file-circle-check');
$('#modal_add_ioc').modal('hide');

notify_success(data.message);

} else {
$('#submit_new_ioc').text('Save again');
swal("Oh no !", data.message, "error")
swal('Oh no !', data.message, 'error')
}
})

Expand Down
21 changes: 19 additions & 2 deletions ui/src/pages/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ function post_request_api(uri, data, propagate_api_error, beforeSend_fn, cid, on
url: uri + cid,
type: 'POST',
data: data,
dataType: "json",
contentType: "application/json;charset=UTF-8",
dataType: 'json',
contentType: 'application/json;charset=UTF-8',
beforeSend: function(jqXHR, settings) {
if (typeof beforeSend_fn === 'function') {
beforeSend_fn(jqXHR, settings);
Expand All @@ -400,6 +400,23 @@ function post_request_api(uri, data, propagate_api_error, beforeSend_fn, cid, on
});
}

function put_request_api(uri, data) {
return $.ajax({
url: uri,
type: 'PUT',
data: data,
dataType: 'json',
contentType: 'application/json;charset=UTF-8',
error: function(jqXHR) {
if (jqXHR.responseJSON && jqXHR.status == 400) {
propagate_form_api_errors(jqXHR.responseJSON.data);
} else {
ajax_notify_error(jqXHR, this.url);
}
}
});
}

function post_request_data_api(uri, data, beforeSend_fn) {
return $.ajax({
url: uri + case_param(),
Expand Down

0 comments on commit 88fee39

Please sign in to comment.