From 7f32df8f1127e76c53708903696de59e007f7f67 Mon Sep 17 00:00:00 2001 From: Robin Riclet Date: Mon, 15 Feb 2021 16:20:36 +0100 Subject: [PATCH] #1766 getCasePatterns returns patterns instead of ids --- thehive/app/org/thp/thehive/controllers/v1/PatternCtrl.scala | 4 ++-- thehive/app/org/thp/thehive/services/PatternSrv.scala | 5 ++--- .../org/thp/thehive/controllers/v1/PatternCtrlTest.scala | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/thehive/app/org/thp/thehive/controllers/v1/PatternCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/PatternCtrl.scala index 6653c6d772..2d884a8e20 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/PatternCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/PatternCtrl.scala @@ -90,8 +90,8 @@ class PatternCtrl @Inject() ( entrypoint("get case patterns") .authRoTransaction(db) { implicit request => implicit graph => for { - patternIds <- patternSrv.getCasePatterns(caseId) - } yield Results.Ok(patternIds.toJson) + patterns <- patternSrv.getCasePatterns(caseId) + } yield Results.Ok(patterns.toJson) } def delete(patternId: String): Action[AnyContent] = diff --git a/thehive/app/org/thp/thehive/services/PatternSrv.scala b/thehive/app/org/thp/thehive/services/PatternSrv.scala index a9b18400ff..1cd7652716 100644 --- a/thehive/app/org/thp/thehive/services/PatternSrv.scala +++ b/thehive/app/org/thp/thehive/services/PatternSrv.scala @@ -37,11 +37,10 @@ class PatternSrv @Inject() ( override def getByName(name: String)(implicit graph: Graph): Traversal.V[Pattern] = Try(startTraversal.getByPatternId(name)).getOrElse(startTraversal.limit(0)) - def getCasePatterns(caseId: String)(implicit graph: Graph): Try[Seq[String]] = + def getCasePatterns(caseId: String)(implicit graph: Graph): Try[Seq[RichPattern]] = for { caze <- caseSrv.get(EntityIdOrName(caseId)).getOrFail("Case") - patterns = caseSrv.get(caze).procedure.pattern.richPattern.toSeq - } yield patterns.map(_.patternId) + } yield caseSrv.get(caze).procedure.pattern.richPattern.toSeq def update( pattern: Pattern with Entity, diff --git a/thehive/test/org/thp/thehive/controllers/v1/PatternCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v1/PatternCtrlTest.scala index 579f1b3211..aea6e1de5e 100644 --- a/thehive/test/org/thp/thehive/controllers/v1/PatternCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v1/PatternCtrlTest.scala @@ -94,7 +94,7 @@ class PatternCtrlTest extends PlaySpecification with TestAppBuilder { val result = app[PatternCtrl].getCasePatterns("1")(request) status(result) must beEqualTo(200).updateMessage(s => s"$s\n${contentAsString(result)}") - contentAsJson(result).as[JsArray].value.size must beEqualTo(2) + contentAsJson(result).as[Seq[OutputPattern]].size must beEqualTo(2) } "import & update a pattern" in testApp { app =>