Skip to content

Commit

Permalink
[#65][ADD] Modification history for creatin and updates of events
Browse files Browse the repository at this point in the history
  • Loading branch information
whikernel committed May 8, 2022
1 parent e232fb1 commit e50a951
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
7 changes: 4 additions & 3 deletions source/app/blueprints/case/case_timeline_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from app.models.cases import Cases, CasesEvent
from app.models.models import CaseAssets, AssetsType, User, CaseEventsAssets, IocLink, Ioc, EventCategory, CaseEventsIoc
from app.schema.marshables import EventSchema
from app.util import response_success, response_error, login_required, api_login_required
from app.util import response_success, response_error, login_required, api_login_required, add_obj_history_entry
from app.datamgmt.case.case_events_db import get_events_categories, save_event_category, \
get_default_cat, \
delete_event_category, get_case_event, update_event_assets, get_event_category, get_event_assets_ids, \
Expand Down Expand Up @@ -714,8 +714,7 @@ def case_edit_event(cur_id, caseid):
)

event.case_id = caseid
event.event_added = datetime.utcnow()
event.user_id = current_user.id
add_obj_history_entry(event, 'updated')

update_timeline_state(caseid=caseid)
db.session.commit()
Expand Down Expand Up @@ -784,6 +783,8 @@ def case_add_event(caseid):
event.event_added = datetime.utcnow()
event.user_id = current_user.id

add_obj_history_entry(event, 'created')

db.session.add(event)
update_timeline_state(caseid=caseid)
db.session.commit()
Expand Down
1 change: 0 additions & 1 deletion source/app/models/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ class CasesEvent(db.Model):
event_raw = Column(Text)
event_date = Column(DateTime)
event_added = Column(DateTime)
event_updated = Column(DateTime)
event_in_graph = Column(Boolean)
event_in_summary = Column(Boolean)
user_id = Column(ForeignKey('user.id'))
Expand Down
1 change: 1 addition & 0 deletions source/app/schema/marshables.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class EventSchema(ma.SQLAlchemyAutoSchema):
event_tz = fields.String(required=True, allow_none=False)
event_category_id = fields.Integer(required=True, allow_none=False)
event_date_wtz = fields.DateTime("%Y-%m-%dT%H:%M:%S.%f", required=False, allow_none=False)
modification_history = auto_field('modification_history', required=False, readonly=True)

class Meta:
model = CasesEvent
Expand Down
24 changes: 24 additions & 0 deletions source/app/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,30 @@ def get_random_suffix(length):
return result_str


def add_obj_history_entry(obj, action):
if hasattr(obj, 'modification_history'):

if isinstance(obj.modification_history, dict):

obj.modification_history.update({
datetime.datetime.now().timestamp(): {
'user': current_user.user,
'user_id': current_user.id,
'action': action
}
})

else:

obj.modification_history = {
datetime.datetime.now().timestamp(): {
'user': current_user.user,
'user_id': current_user.id,
'action': action
}
}
return obj

# Set basic 404
@app.errorhandler(404)
def page_not_found(e):
Expand Down

0 comments on commit e50a951

Please sign in to comment.