Skip to content

Commit

Permalink
#2010 Add the API GET /api/v1/case/$caseId/links
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Apr 30, 2021
1 parent df2e8a4 commit 158e3c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import org.thp.thehive.services.ShareOps._
import org.thp.thehive.services.TaskOps._
import org.thp.thehive.services.UserOps._
import org.thp.thehive.services._
import play.api.libs.json.{JsArray, JsNumber, JsObject}
import play.api.mvc.{Action, AnyContent, Results}

import javax.inject.{Inject, Singleton}
import scala.util.Success

@Singleton
class CaseCtrl @Inject() (
Expand Down Expand Up @@ -180,4 +182,21 @@ class CaseCtrl @Inject() (
mergedCase <- caseSrv.merge(cases)
} yield Results.Created(mergedCase.toJson)
}

def linkedCases(caseIdOrNumber: String): Action[AnyContent] =
entrypoint("case link")
.authRoTransaction(db) { implicit request => implicit graph =>
val relatedCases = caseSrv
.get(EntityIdOrName(caseIdOrNumber))
.visible(organisationSrv)
.linkedCases
.map {
case (c, o) =>
c.toJson.as[JsObject] +
("linkedWith" -> o.toJson) +
("linksCount" -> JsNumber(o.size))
}

Success(Results.Ok(JsArray(relatedCases)))
}
}
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/controllers/v1/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Router @Inject() (
case DELETE(p"/case/customField/$cfId") => caseCtrl.deleteCustomField(cfId)
// case PATCH(p"api/case/_bulk") => caseCtrl.bulkUpdate()
// case POST(p"/case/_stats") => caseCtrl.stats()
// case GET(p"/case/$caseId/links") => caseCtrl.linkedCases(caseId)
case GET(p"/case/$caseId/links") => caseCtrl.linkedCases(caseId)

case POST(p"/case/$caseId/observable") => observableCtrl.createInCase(caseId)
case POST(p"/alert/$alertId/artifact") => observableCtrl.createInAlert(alertId)
Expand Down

0 comments on commit 158e3c6

Please sign in to comment.