chg: [investigation] fix investigation by user + delete an obj from all investigation

This commit is contained in:
Terrtia 2022-06-22 15:35:09 +02:00
parent 91010dddf1
commit 860ad9b67d
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0

View file

@ -270,7 +270,7 @@ def exists_investigation(investigation_uuid):
# created by user # created by user
def get_user_all_investigations(user_id): def get_user_all_investigations(user_id):
return r_tracking.smembers('investigations:user:{user_id}') return r_tracking.smembers(f'investigations:user:{user_id}')
def is_object_investigated(obj_id, obj_type, subtype=''): def is_object_investigated(obj_id, obj_type, subtype=''):
return r_tracking.exists(f'obj:investigations:{obj_type}:{subtype}:{obj_id}') return r_tracking.exists(f'obj:investigations:{obj_type}:{subtype}:{obj_id}')
@ -278,6 +278,15 @@ def is_object_investigated(obj_id, obj_type, subtype=''):
def get_obj_investigations(obj_id, obj_type, subtype=''): def get_obj_investigations(obj_id, obj_type, subtype=''):
return r_tracking.smembers(f'obj:investigations:{obj_type}:{subtype}:{obj_id}') return r_tracking.smembers(f'obj:investigations:{obj_type}:{subtype}:{obj_id}')
def delete_obj_investigations(obj_id, obj_type, subtype=''):
unregistred = False
for investigation_uuid in get_obj_investigations(obj_id, obj_type, subtype=subtype):
investigation = Investigation(investigation_uuid)
investigation.unregister_object(obj_id, obj_type, subtype)
unregistred = True
return unregistred
# # TODO: fix default threat_level analysis # # TODO: fix default threat_level analysis
# # TODO: limit description + name # # TODO: limit description + name
# # TODO: sanityze tags # # TODO: sanityze tags
@ -286,7 +295,7 @@ def create_investigation(user_id, date, name, threat_level, analysis, info, tags
investigation_uuid = generate_uuid() investigation_uuid = generate_uuid()
r_tracking.sadd('investigations:all', investigation_uuid) r_tracking.sadd('investigations:all', investigation_uuid)
# user map # user map
r_tracking.sadd('investigations:user:{user_id}', investigation_uuid) r_tracking.sadd(f'investigations:user:{user_id}', investigation_uuid)
# metadata # metadata
r_tracking.hset(f'investigations:data:{investigation_uuid}', 'creator_user', user_id) r_tracking.hset(f'investigations:data:{investigation_uuid}', 'creator_user', user_id)