Skip to content

Commit

Permalink
#1410 Add links to organisation output
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jun 29, 2020
1 parent eb539dc commit 09bf45a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
3 changes: 2 additions & 1 deletion dto/src/main/scala/org/thp/thehive/dto/v1/Organistion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ case class OutputOrganisation(
_createdAt: Date,
_updatedAt: Option[Date] = None,
name: String,
description: String
description: String,
links: Seq[String]
)

object OutputOrganisation {
Expand Down
21 changes: 18 additions & 3 deletions thehive/app/org/thp/thehive/controllers/v1/Conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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],
Expand Down

0 comments on commit 09bf45a

Please sign in to comment.