diff --git a/ScalliGraph b/ScalliGraph index 493b07885c..f6fc23f06f 160000 --- a/ScalliGraph +++ b/ScalliGraph @@ -1 +1 @@ -Subproject commit 493b07885ce4988799e2cfbfb975856c9f71b966 +Subproject commit f6fc23f06f4db8a72303f6bf98e6bdd2e73f3fac diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/Organistion.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/Organistion.scala index 8ba075e52e..dc264d9dc1 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/Organistion.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/Organistion.scala @@ -18,7 +18,8 @@ case class OutputOrganisation( _createdAt: Date, _updatedAt: Option[Date] = None, name: String, - description: String + description: String, + links: Seq[String] ) object OutputOrganisation { diff --git a/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala b/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala index 50ac976d10..0047ef1c51 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala @@ -159,17 +159,32 @@ object Conversion { .transform } - implicit val organisationRenderer: Renderer.Aux[Organisation with Entity, OutputOrganisation] = - Renderer.json[Organisation with Entity, OutputOrganisation](organisation => + implicit val richOrganisationRenderer: Renderer.Aux[RichOrganisation, OutputOrganisation] = + Renderer.json[RichOrganisation, OutputOrganisation](organisation => organisation - .asInstanceOf[Entity] .into[OutputOrganisation] .withFieldConst(_._type, "Organisation") .withFieldConst(_.name, organisation.name) .withFieldConst(_.description, organisation.description) + .withFieldComputed(_.links, _.links.map(_.name)) .transform ) + implicit val organiastionRenderer: Renderer.Aux[Organisation with Entity, OutputOrganisation] = + Renderer.json[Organisation with Entity, OutputOrganisation](organisation => + OutputOrganisation( + organisation._id, + "organisation", + organisation._createdBy, + organisation._updatedBy, + organisation._createdAt, + organisation._updatedAt, + organisation.name, + organisation.description, + Nil + ) + ) + implicit class InputTaskOps(inputTask: InputTask) { def toTask: Task = diff --git a/thehive/app/org/thp/thehive/controllers/v1/OrganisationCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/OrganisationCtrl.scala index ee52e84d3d..46bbeebf6f 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/OrganisationCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/OrganisationCtrl.scala @@ -2,13 +2,13 @@ package org.thp.thehive.controllers.v1 import javax.inject.{Inject, Named, Singleton} import org.thp.scalligraph.controllers.{Entrypoint, FieldsParser} -import org.thp.scalligraph.models.{Database, Entity} +import org.thp.scalligraph.models.Database import org.thp.scalligraph.query.{ParamQuery, PropertyUpdater, PublicProperty, Query} import org.thp.scalligraph.steps.PagedResult import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.controllers.v1.Conversion._ import org.thp.thehive.dto.v1.InputOrganisation -import org.thp.thehive.models.{Organisation, Permissions} +import org.thp.thehive.models.{Permissions, RichOrganisation} import org.thp.thehive.services._ import play.api.mvc.{Action, AnyContent, Results} @@ -25,12 +25,12 @@ class OrganisationCtrl @Inject() ( override val publicProperties: List[PublicProperty[_, _]] = properties.organisation ::: metaProperties[OrganisationSteps] override val initialQuery: Query = Query.init[OrganisationSteps]("listOrganisation", (graph, authContext) => organisationSrv.initSteps(graph).visible(authContext)) - override val pageQuery: ParamQuery[OutputParam] = Query.withParam[OutputParam, OrganisationSteps, PagedResult[Organisation with Entity]]( + override val pageQuery: ParamQuery[OutputParam] = Query.withParam[OutputParam, OrganisationSteps, PagedResult[RichOrganisation]]( "page", FieldsParser[OutputParam], - (range, organisationSteps, _) => organisationSteps.page(range.from, range.to, withTotal = true) + (range, organisationSteps, _) => organisationSteps.richPage(range.from, range.to, withTotal = true)(_.richOrganisation) ) - override val outputQuery: Query = Query.output[Organisation with Entity] + override val outputQuery: Query = Query.output[RichOrganisation, OrganisationSteps](_.richOrganisation) override val getQuery: ParamQuery[IdOrName] = Query.initWithParam[IdOrName, OrganisationSteps]( "getOrganisation", FieldsParser[IdOrName],