Skip to content

Commit

Permalink
#928 make case owner case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Apr 7, 2020
1 parent cb5dd47 commit bd76208
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions thehive-backend/app/models/Case.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ class CaseModel @Inject()(

override def creationHook(parent: Option[BaseEntity], attrs: JsObject): Future[JsObject] =
sequenceSrv("case").map { caseId
attrs + ("caseId" JsNumber(caseId))
attrs +
("caseId" JsNumber(caseId)) +
("owner" (attrs \ "owner").asOpt[String].fold[JsValue](JsNull)(o JsString(o.toLowerCase())))
}

override def updateHook(entity: BaseEntity, updateAttrs: JsObject): Future[JsObject] = Future.successful {
private def updateStatus(updateAttrs: JsObject): JsObject =
(updateAttrs \ "status").asOpt[CaseStatus.Type] match {
case Some(CaseStatus.Resolved) if !updateAttrs.keys.contains("endDate")
updateAttrs +
Expand All @@ -95,7 +97,12 @@ class CaseModel @Inject()(
case _
updateAttrs
}
}

private def lowercaseOwner(updateAttrs: JsObject): JsObject =
(updateAttrs \ "owner").asOpt[String].fold(updateAttrs)(o updateAttrs + ("owner" JsString(o.toLowerCase)))

override def updateHook(entity: BaseEntity, updateAttrs: JsObject): Future[JsObject] =
Future.successful(lowercaseOwner(updateStatus(updateAttrs)))

private[models] def buildArtifactStats(caze: Case): Future[JsObject] = {
import org.elastic4play.services.QueryDSL._
Expand Down

0 comments on commit bd76208

Please sign in to comment.