Skip to content

Commit

Permalink
Detach hash artifact from the incident when the file is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
gcrahay committed Oct 2, 2017
1 parent 06b0ba5 commit 1705ac0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fir_artifacts/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from fir_artifacts.artifacts import Hash
from fir_artifacts.models import File, Artifact
from fir_artifacts.signals import artifact_detached


def do_upload_file(request, content_type, object_id):
Expand Down Expand Up @@ -95,8 +96,14 @@ def do_download_archive(request, content_type, object_id):
def do_remove_file(request, file_id):
if request.method == "POST":
f = get_object_or_404(File, pk=file_id)
if not request.user.has_perm('incidents.handle_incidents', obj=f.get_related()):
related = f.get_related()
if not request.user.has_perm('incidents.handle_incidents', obj=related):
raise PermissionDenied()
for a in f.hashes.all():
a.relations.remove(related)
artifact_detached.send(sender=related.__class__, key=a.type, value=a.value, related=related)
if a.relations.count() == 0:
a.delete()
f.file.delete()
f.delete()
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

0 comments on commit 1705ac0

Please sign in to comment.