Skip to content

Commit

Permalink
chg: [website] use ui-priority
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidCruciani committed Feb 26, 2024
1 parent 50d6e60 commit a2721c9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -2,3 +2,6 @@
path = misp_modules/lib/misp-objects
url = https://github.com/MISP/misp-objects.git
branch = main
[submodule "website/data/misp-objects"]
path = website/data/misp-objects
url = https://github.com/MISP/misp-objects
16 changes: 15 additions & 1 deletion website/app/session.py
Expand Up @@ -3,7 +3,7 @@
from queue import Queue
from threading import Thread
from uuid import uuid4
from .utils.utils import query_post_query, query_get_module
from .utils.utils import query_post_query, query_get_module, get_object
from . import home_core as HomeModel
import uuid
from . import db
Expand Down Expand Up @@ -131,6 +131,20 @@ def process(self):
else:
send_to = {"module": work[1], self.input_query: self.query, "config": loc_config}
res = query_post_query(send_to)

## Sort attr in object by ui-priority
if "results" in res:
if "Object" in res["results"]:
for obj in res["results"]["Object"]:
loc_obj = get_object(obj["name"])
if loc_obj:
for attr in obj["Attribute"]:
attr["ui-priority"] = loc_obj["attributes"][attr["object_relation"]]["ui-priority"]

# After adding 'ui-priority'
obj["Attribute"].sort(key=lambda x: x["ui-priority"], reverse=True)


# print(res)
if "error" in res:
self.nb_errors += 1
Expand Down
11 changes: 10 additions & 1 deletion website/app/utils/utils.py
@@ -1,4 +1,4 @@
# import os
import os
import uuid
import json
import requests
Expand Down Expand Up @@ -37,6 +37,15 @@ def isUUID(uid):
return True
except ValueError:
return False

def get_object(obj_name):
loc_path = os.path.join(os.getcwd(), "data", "misp-objects", "objects")
if os.path.isdir(loc_path):
with open(os.path.join(loc_path, obj_name, "definition.json"), "r") as read_json:
loc_json = json.load(read_json)
return loc_json
return False



# def form_to_dict(form):
Expand Down
2 changes: 2 additions & 0 deletions website/install.sh
Expand Up @@ -8,5 +8,7 @@ source env/bin/activate

pip install -r requirements.txt

git submodule init && git submodule update

python app.py -i
deactivate

0 comments on commit a2721c9

Please sign in to comment.