From fb40f3396352df0d731fdd1971a75c977a6cb4fb Mon Sep 17 00:00:00 2001 From: To-om Date: Tue, 2 Mar 2021 13:27:02 +0100 Subject: [PATCH] #1741 Add organisation ID in user current API --- dto/src/main/scala/org/thp/thehive/dto/v1/User.scala | 2 +- .../org/thp/thehive/controllers/v1/Conversion.scala | 6 +++--- thehive/app/org/thp/thehive/services/UserSrv.scala | 11 ++++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dto/src/main/scala/org/thp/thehive/dto/v1/User.scala b/dto/src/main/scala/org/thp/thehive/dto/v1/User.scala index b92f479723..1dc2313358 100644 --- a/dto/src/main/scala/org/thp/thehive/dto/v1/User.scala +++ b/dto/src/main/scala/org/thp/thehive/dto/v1/User.scala @@ -11,7 +11,7 @@ object InputUser { implicit val writes: Writes[InputUser] = Json.writes[InputUser] } -case class OutputOrganisationProfile(organisation: String, profile: String) +case class OutputOrganisationProfile(organisationId: String, organisation: String, profile: String) object OutputOrganisationProfile { implicit val format: OFormat[OutputOrganisationProfile] = Json.format[OutputOrganisationProfile] } diff --git a/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala b/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala index 0945f89d29..b6e14d8bf8 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Conversion.scala @@ -331,15 +331,15 @@ object Conversion { .transform ) - implicit val userWithOrganisationOutput: Renderer.Aux[(RichUser, Seq[(String, String)]), OutputUser] = - Renderer.toJson[(RichUser, Seq[(String, String)]), OutputUser] { userWithOrganisations => + implicit val userWithOrganisationOutput: Renderer.Aux[(RichUser, Seq[(Organisation with Entity, String)]), OutputUser] = + Renderer.toJson[(RichUser, Seq[(Organisation with Entity, String)]), OutputUser] { userWithOrganisations => val (user, organisations) = userWithOrganisations user .into[OutputUser] .withFieldComputed(_._id, _._id.toString) .withFieldComputed(_.permissions, _.permissions.asInstanceOf[Set[String]]) .withFieldComputed(_.hasKey, _.apikey.isDefined) - .withFieldConst(_.organisations, organisations.map { case (org, role) => OutputOrganisationProfile(org, role) }) + .withFieldConst(_.organisations, organisations.map { case (org, role) => OutputOrganisationProfile(org._id.toString, org.name, role) }) .withFieldComputed(_.avatar, user => user.avatar.map(avatar => s"/api/v1/user/${user._id}/avatar/$avatar")) .enableMethodAccessors .transform diff --git a/thehive/app/org/thp/thehive/services/UserSrv.scala b/thehive/app/org/thp/thehive/services/UserSrv.scala index 757a0c1929..5467de2dea 100644 --- a/thehive/app/org/thp/thehive/services/UserSrv.scala +++ b/thehive/app/org/thp/thehive/services/UserSrv.scala @@ -187,13 +187,14 @@ object UserOps { else organisations0(requiredPermission) } - def organisationWithRole: Traversal[Seq[(String, String)], JList[JMap[String, Any]], CList[(String, String), JMap[String, Any], Converter[ - (String, String), - JMap[String, Any] - ]]] = + def organisationWithRole: Traversal[Seq[(Organisation with Entity, String)], JList[JMap[String, Any]], CList[ + (Organisation with Entity, String), + JMap[String, Any], + Converter[(Organisation with Entity, String), JMap[String, Any]] + ]] = role .project( - _.by(_.organisation.value(_.name)) + _.by(_.organisation) .by(_.profile.value(_.name)) ) .fold