Skip to content

Commit

Permalink
#1474 Fix dashboard sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Oct 19, 2020
1 parent 4393938 commit 4904265
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ScalliGraph
39 changes: 20 additions & 19 deletions thehive/app/org/thp/thehive/controllers/v0/DashboardCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,28 +110,29 @@ class PublicDashboard @Inject() (
.property("description", UMapping.string)(_.field.updatable)
.property("definition", UMapping.string)(_.field.updatable)
.property("status", UMapping.string)(
_.select(_.organisation.fold.domainMap(d => if (d.isEmpty) "Private" else "Shared")).custom { // TODO replace by choose step
case (_, "Shared", vertex, _, graph, authContext) =>
for {
dashboard <- dashboardSrv.get(vertex)(graph).filter(_.user.current(authContext)).getOrFail("Dashboard")
_ <- dashboardSrv.share(dashboard, authContext.organisation, writable = false)(graph, authContext)
} yield Json.obj("status" -> "Shared")
_.select(_.choose(_.organisation, "Shared", "Private"))
.custom {
case (_, "Shared", vertex, _, graph, authContext) =>
for {
dashboard <- dashboardSrv.get(vertex)(graph).filter(_.user.current(authContext)).getOrFail("Dashboard")
_ <- dashboardSrv.share(dashboard, authContext.organisation, writable = false)(graph, authContext)
} yield Json.obj("status" -> "Shared")

case (_, "Private", vertex, _, graph, authContext) =>
for {
d <- dashboardSrv.get(vertex)(graph).filter(_.user.current(authContext)).getOrFail("Dashboard")
_ <- dashboardSrv.unshare(d, authContext.organisation)(graph, authContext)
} yield Json.obj("status" -> "Private")
case (_, "Private", vertex, _, graph, authContext) =>
for {
d <- dashboardSrv.get(vertex)(graph).filter(_.user.current(authContext)).getOrFail("Dashboard")
_ <- dashboardSrv.unshare(d, authContext.organisation)(graph, authContext)
} yield Json.obj("status" -> "Private")

case (_, "Deleted", vertex, _, graph, authContext) =>
for {
d <- dashboardSrv.get(vertex)(graph).filter(_.user.current(authContext)).getOrFail("Dashboard")
_ <- dashboardSrv.remove(d)(graph, authContext)
} yield Json.obj("status" -> "Deleted")
case (_, "Deleted", vertex, _, graph, authContext) =>
for {
d <- dashboardSrv.get(vertex)(graph).filter(_.user.current(authContext)).getOrFail("Dashboard")
_ <- dashboardSrv.remove(d)(graph, authContext)
} yield Json.obj("status" -> "Deleted")

case (_, status, _, _, _, _) =>
Failure(InvalidFormatAttributeError("status", "String", Set("Shared", "Private", "Deleted"), FString(status)))
}
case (_, status, _, _, _, _) =>
Failure(InvalidFormatAttributeError("status", "String", Set("Shared", "Private", "Deleted"), FString(status)))
}
)
.build
}
4 changes: 2 additions & 2 deletions thehive/app/org/thp/thehive/services/DashboardSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ object DashboardOps {

def organisationShares: Traversal[Seq[(String, Boolean)], JList[JMap[String, Any]], Converter[Seq[(String, Boolean)], JList[JMap[String, Any]]]] =
traversal
.outE[OrganisationDashboard]
.inE[OrganisationDashboard]
.project(
_.byValue(_.writable)
.by(_.inV)
.by(_.outV)
)
.fold
.domainMap(_.map { case (writable, orgs) => (orgs.value[String]("name"), writable) })
Expand Down

0 comments on commit 4904265

Please # to comment.