Skip to content

Commit

Permalink
#1643 Prevent creating a file observable if it already exist in the case
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 12, 2020
1 parent 389901f commit 8846067
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ class ObservableCtrl @Inject() (
.fold(
e =>
successes -> (failures :+ errorHandler.toErrorResult(e)._2 ++ Json
.obj("object" -> Json.obj("attachment" -> Json.obj("name" -> attachment.filename)))),
.obj(
"object" -> Json
.obj("data" -> s"file:${attachment.filename}", "attachment" -> Json.obj("name" -> attachment.filename))
)),
s => (successes :+ s) -> failures
)
}
Expand Down
21 changes: 14 additions & 7 deletions thehive/app/org/thp/thehive/services/CaseSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,20 @@ class CaseSrv @Inject() (
graph: Graph,
authContext: AuthContext
): Try[Unit] = {
val alreadyExistInThatCase = observableSrv
.get(richObservable.observable)
.filteredSimilar
.visible
.`case`
.hasId(`case`._id)
.exists || get(`case`).observables.filter(_.hasId(richObservable.observable._id)).exists // FIXME
val alreadyExistInThatCase = richObservable
.dataOrAttachment
.fold(
_ =>
observableSrv
.get(richObservable.observable)
.filteredSimilar
.visible
.`case`
.hasId(`case`._id)
.exists,
attachment => get(`case`).share.observables.attachments.has(_.attachmentId, attachment.attachmentId).exists
) || get(`case`).observables.filter(_.hasId(richObservable.observable._id)).exists

if (alreadyExistInThatCase)
Failure(CreateError("Observable already exists"))
else
Expand Down

0 comments on commit 8846067

Please sign in to comment.