Skip to content

Commit

Permalink
#1754 Share dashboard if requested during creation
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Feb 5, 2021
1 parent 84faedb commit 42d554c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions thehive/app/org/thp/thehive/controllers/v0/DashboardCtrl.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.thp.thehive.controllers.v0

import javax.inject.{Inject, Named, Singleton}
import org.thp.scalligraph.controllers.{Entrypoint, FString, FieldsParser}
import org.thp.scalligraph.models.{Database, UMapping}
import org.thp.scalligraph.query._
Expand All @@ -17,7 +16,8 @@ import org.thp.thehive.services.{DashboardSrv, OrganisationSrv, UserSrv}
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent, Results}

import scala.util.Failure
import javax.inject.{Inject, Named, Singleton}
import scala.util.{Failure, Success}

@Singleton
class DashboardCtrl @Inject() (
Expand All @@ -33,7 +33,16 @@ class DashboardCtrl @Inject() (
.extract("dashboard", FieldsParser[InputDashboard])
.authTransaction(db) { implicit request => implicit graph =>
val dashboard: InputDashboard = request.body("dashboard")
dashboardSrv.create(dashboard.toDashboard).map(d => Results.Created(d.toJson))
dashboardSrv
.create(dashboard.toDashboard)
.flatMap {
case richDashboard if dashboard.status == "Shared" =>
dashboardSrv
.share(richDashboard.dashboard, request.organisation, writable = false)
.flatMap(_ => dashboardSrv.get(richDashboard.dashboard).richDashboard.getOrFail("Dashboard"))
case richDashboard => Success(richDashboard)
}
.map(richDashboard => Results.Created(richDashboard.toJson))
}

def get(dashboardId: String): Action[AnyContent] =
Expand Down

0 comments on commit 42d554c

Please sign in to comment.