Skip to content

Commit

Permalink
[#17][ADD] IOC types update, add and deletion from GUIsertially fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
whikernel committed Jan 8, 2022
1 parent 098279c commit df74631
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
19 changes: 10 additions & 9 deletions source/app/blueprints/manage/manage_assets_type_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,20 @@ def add_assets(caseid):
if not request.is_json:
return response_error("Invalid request")

asset_name = request.json.get('asset_name')
asset_description = request.json.get('asset_description')
asset_schema = AssetSchema()

asset = AssetsType(asset_name=asset_name,
asset_description=asset_description
)
try:

db.session.add(asset)
db.session.commit()
asset_sc = asset_schema.load(request.get_json())
db.session.add(asset_sc)
db.session.commit()

except marshmallow.exceptions.ValidationError as e:
return response_error(msg="Data error", data=e.messages, status=400)

track_activity("Added asset type {asset_name}".format(asset_name=asset.asset_name), caseid=caseid, ctx_less=True)
track_activity("Added asset type {asset_name}".format(asset_name=asset_sc.asset_name), caseid=caseid, ctx_less=True)
# Return the assets
return response_success("Added successfully", data=asset)
return response_success("Added successfully", data=asset_sc)


@manage_assets_blueprint.route('/manage/asset-type/delete/<int:cur_id>', methods=['GET'])
Expand Down
13 changes: 11 additions & 2 deletions source/app/blueprints/manage/manage_ioc_types_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ def view_ioc_modal(cur_id, caseid, url_redir):
return render_template("modal_add_ioc_type.html", form=form, ioc_type=ioct)


@manage_ioc_type_blueprint.route('/manage/ioc-types/add/modal', methods=['GET'])
@admin_required
def add_ioc_modal(caseid, url_redir):
if url_redir:
return redirect(url_for('manage_ioc_types.view_ioc_modal', cid=caseid))

form = AddIocTypeForm()

return render_template("modal_add_ioc_type.html", form=form, ioc_type=None)


@manage_ioc_type_blueprint.route('/manage/ioc-types/add', methods=['POST'])
@api_admin_required
def add_ioc_type_api(caseid):
Expand All @@ -99,8 +110,6 @@ def add_ioc_type_api(caseid):
@manage_ioc_type_blueprint.route('/manage/ioc-types/delete/<int:cur_id>', methods=['GET'])
@api_admin_required
def remove_ioc_type(cur_id, caseid):
if not request.is_json:
return response_error("Invalid request")

type_id = IocType.query.filter(
IocType.type_id == cur_id
Expand Down
3 changes: 2 additions & 1 deletion source/app/blueprints/manage/templates/manage_objects.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
</div>
</div>
</div>
<div class="modal " tabindex="-1" role="dialog" id="modal_add_type" data-backdrop="true">
</div>
<div class="modal" tabindex="-1" id="modal_add_type" data-backdrop="true">
<div class="modal-lg modal-dialog" role="document">
<div class="modal-content" id="modal_add_type_content">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ <h4>Add Asset Type</h4>
id="submit_new_assettype">Save</button>

{% endif %}
</div>
</form>
</div>

Expand Down
26 changes: 14 additions & 12 deletions source/app/static/assets/js/iris/manage_objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function add_asset_type() {
console.log(data);
if (data.status == 'success') {
swal("Done !",
"Your asset has been created successfully",
data.message,
{
icon: "success",
timer: 2000
Expand All @@ -33,7 +33,7 @@ function add_asset_type() {
},
error: function (error) {
$('#modal_add_type').text('Save');
notify_error(error.responseJSON.message);
propagate_form_api_errors(error.responseJSON.data);
}
});

Expand Down Expand Up @@ -99,7 +99,7 @@ function assettype_detail(asset_id) {
success: function (data) {
if (data.status == 'success') {
swal("You're set !",
"The asset has been updated successfully",
data.message,
{
icon: "success",
timer: 1500
Expand All @@ -116,6 +116,7 @@ function assettype_detail(asset_id) {
},
error: function (error) {
notify_error(error.responseJSON.message);
propagate_form_api_errors(error.responseJSON.data);
}
});

Expand Down Expand Up @@ -147,7 +148,7 @@ function delete_asset_type(id) {
dataType: 'JSON',
success: function (data) {
if (data.status == 'success') {
swal("Asset type deleted !", {
swal(data.message, {
icon: "success",
timer: 500
}).then((value) => {
Expand All @@ -171,7 +172,7 @@ function delete_asset_type(id) {
/*** IOC Type ***/

function add_ioc_type() {
url = 'ioc-type/add/modal' + case_param();
url = '/manage/ioc-types/add/modal' + case_param();
$('#modal_add_type_content').load(url, function () {

$('#submit_new_ioc_type').on("click", function () {
Expand All @@ -188,13 +189,13 @@ function add_ioc_type() {
console.log(data);
if (data.status == 'success') {
swal("Done !",
"Your IOC has been created successfully",
data.message,
{
icon: "success",
timer: 2000
}
).then((value) => {
refresh_asset_table();
refresh_ioc_table();
$('#modal_add_type').modal('hide');

});
Expand All @@ -205,7 +206,7 @@ function add_ioc_type() {
},
error: function (error) {
$('#modal_add_type').text('Save');
notify_error(error.responseJSON.message);
propagate_form_api_errors(error.responseJSON.data);
}
});

Expand Down Expand Up @@ -269,21 +270,21 @@ function ioc_type_detail(ioc_id) {
var form = $('form#form_new_ioc_type').serializeObject();

$.ajax({
url: '/manage/ioc-type/update/' + ioc_id + case_param(),
url: '/manage/ioc-types/update/' + ioc_id + case_param(),
type: "POST",
data: JSON.stringify(form),
dataType: "json",
contentType: "application/json;charset=UTF-8",
success: function (data) {
if (data.status == 'success') {
swal("You're set !",
"The IOC has been updated successfully",
data.message,
{
icon: "success",
timer: 1500
}
).then((value) => {
refresh_asset_table();
refresh_ioc_table();
$('#modal_add_type').modal('hide');
});

Expand All @@ -294,6 +295,7 @@ function ioc_type_detail(ioc_id) {
},
error: function (error) {
notify_error(error.responseJSON.message);
propagate_form_api_errors(error.responseJSON.data);
}
});

Expand Down Expand Up @@ -325,7 +327,7 @@ function delete_ioc_type(id) {
dataType: 'JSON',
success: function (data) {
if (data.status == 'success') {
swal("IOC type deleted !", {
swal(data.message, {
icon: "success",
timer: 500
}).then((value) => {
Expand Down

0 comments on commit df74631

Please sign in to comment.