diff --git a/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala index 04064ecfaf..155648d6fb 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala @@ -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() ( @@ -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))) + } } diff --git a/thehive/app/org/thp/thehive/controllers/v1/Router.scala b/thehive/app/org/thp/thehive/controllers/v1/Router.scala index e5b3ca9fa9..4d5d8b67e6 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Router.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Router.scala @@ -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)