Skip to content

Commit

Permalink
#1741 Add organisation ID in user current API
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 2, 2021
1 parent b056e99 commit fb40f33
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dto/src/main/scala/org/thp/thehive/dto/v1/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
6 changes: 3 additions & 3 deletions thehive/app/org/thp/thehive/controllers/v1/Conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions thehive/app/org/thp/thehive/services/UserSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb40f33

Please sign in to comment.