From ac0421b6d140c1ac6d2d84d6103c06815ffa9225 Mon Sep 17 00:00:00 2001 From: To-om Date: Fri, 6 Nov 2020 08:36:37 +0100 Subject: [PATCH] #1621 Add properties "viewingOrganisation" and "owningOrganisation" to case --- ScalliGraph | 2 +- .../org/thp/thehive/controllers/v0/CaseCtrl.scala | 6 ++++++ .../org/thp/thehive/services/th3/Aggregation.scala | 12 ++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ScalliGraph b/ScalliGraph index 1d8f5e930e..5cf2957a52 160000 --- a/ScalliGraph +++ b/ScalliGraph @@ -1 +1 @@ -Subproject commit 1d8f5e930e59cfc71921e2b6e4ac8f6ba9b14a49 +Subproject commit 5cf2957a52bdc42e0fc73f95a6751ccec2997ef8 diff --git a/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala index 9cd28662a3..62015e054d 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala @@ -352,5 +352,11 @@ class PublicCase @Inject() ( ) ).readonly ) + .property("viewingOrganisation", UMapping.string)( + _.authSelect((cases, authContext) => cases.organisations.visible(authContext).value(_.name)).readonly + ) + .property("owningOrganisation", UMapping.string)( + _.authSelect((cases, authContext) => cases.origin.visible(authContext).value(_.name)).readonly + ) .build } diff --git a/thehive/app/org/thp/thehive/services/th3/Aggregation.scala b/thehive/app/org/thp/thehive/services/th3/Aggregation.scala index 0613df53a5..90032f84dc 100644 --- a/thehive/app/org/thp/thehive/services/th3/Aggregation.scala +++ b/thehive/app/org/thp/thehive/services/th3/Aggregation.scala @@ -161,7 +161,7 @@ case class AggSum(aggName: Option[String], fieldName: String) extends Aggregatio traversal.coalesce( t => property - .select(fieldPath, t) + .select(fieldPath, t, authContext) .sum .domainMap(sum => Output(Json.obj(name -> JsNumber(BigDecimal(sum.toString))))) .castDomain[Output[_]], @@ -184,7 +184,7 @@ case class AggAvg(aggName: Option[String], fieldName: String) extends Aggregatio traversal.coalesce( t => property - .select(fieldPath, t) + .select(fieldPath, t, authContext) .mean .domainMap(avg => Output(Json.obj(name -> avg.asInstanceOf[Double]))), Output(Json.obj(name -> JsNull)) @@ -207,7 +207,7 @@ case class AggMin(aggName: Option[String], fieldName: String) extends Aggregatio traversal.coalesce( t => property - .select(fieldPath, t) + .select(fieldPath, t, authContext) .min .domainMap(min => Output(Json.obj(name -> property.mapping.selectRenderer.toJson(min)))), Output(Json.obj(name -> JsNull)) @@ -230,7 +230,7 @@ case class AggMax(aggName: Option[String], fieldName: String) extends Aggregatio traversal.coalesce( t => property - .select(fieldPath, t) + .select(fieldPath, t, authContext) .max .domainMap(max => Output(Json.obj(name -> property.mapping.selectRenderer.toJson(max)))), Output(Json.obj(name -> JsNull)) @@ -275,7 +275,7 @@ case class FieldAggregation( val property = publicProperties .get[Traversal.UnkD, Traversal.UnkDU](fieldPath, traversalType) .getOrElse(throw BadRequestError(s"Property $fieldName for type $traversalType not found")) - val groupedVertices = property.select(fieldPath, traversal.as(label)).group(_.by, _.by(_.select(label).fold)).unfold + val groupedVertices = property.select(fieldPath, traversal.as(label), authContext).group(_.by, _.by(_.select(label).fold)).unfold val sortedAndGroupedVertex = orders .map { case order if order.headOption.contains('-') => order.tail -> Order.desc @@ -377,7 +377,7 @@ case class TimeAggregation( .getOrElse(throw BadRequestError(s"Property $fieldName for type $traversalType not found")) val label = StepLabel[Traversal.UnkD, Traversal.UnkG, Converter[Traversal.UnkD, Traversal.UnkG]] val groupedVertex = property - .select(fieldPath, traversal.as(label)) + .select(fieldPath, traversal.as(label), authContext) .cast[Date, Date] .graphMap[Long, JLong, Converter[Long, JLong]](dateToKey, Converter.long) .group(_.by, _.by(_.select(label).fold))