Skip to content

Commit

Permalink
#1410 Add assignee in tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jun 30, 2020
1 parent ff820ac commit d54b7ff
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions dto/src/main/scala/org/thp/thehive/dto/v1/Task.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ case class OutputTask(
flag: Boolean,
startDate: Option[Date],
endDate: Option[Date],
assignee: Option[String],
order: Int,
dueDate: Option[Date]
)
Expand Down
4 changes: 2 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v0/Conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ object Conversion {
.withFieldComputed(_.status, _.status.toString)
.withFieldConst(_._type, "case_task")
.withFieldConst(_.`case`, None)
.withFieldComputed(_.owner, _.owner.map(_.login))
.withFieldComputed(_.owner, _.assignee.map(_.login))
.withFieldRenamed(_._updatedAt, _.updatedAt)
.withFieldRenamed(_._updatedBy, _.updatedBy)
.withFieldRenamed(_._createdAt, _.createdAt)
Expand All @@ -548,7 +548,7 @@ object Conversion {
.withFieldComputed(_.status, _.status.toString)
.withFieldConst(_._type, "case_task")
.withFieldConst(_.`case`, richCase.map(_.toValue))
.withFieldComputed(_.owner, _.owner.map(_.login))
.withFieldComputed(_.owner, _.assignee.map(_.login))
.withFieldRenamed(_._updatedAt, _.updatedAt)
.withFieldRenamed(_._updatedBy, _.updatedBy)
.withFieldRenamed(_._createdAt, _.createdAt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class Properties @Inject() (
.property("dueDate", UniMapping.date.optional)(_.field.updatable)
.property("group", UniMapping.string)(_.field.updatable)
.property("owner", UniMapping.string.optional)(
_.select(_.user.login)
_.select(_.assignee.login)
.custom { (_, login: Option[String], vertex, _, graph, authContext) =>
for {
task <- taskSrv.get(vertex)(graph).getOrFail("Task")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ object Conversion {
_.into[OutputTask]
.withFieldConst(_._type, "Task")
.withFieldComputed(_.status, _.status.toString)
.withFieldComputed(_.assignee, _.assignee.map(_.login))
.transform
)

Expand Down
17 changes: 17 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.thp.thehive.services.{
ObservableSteps,
OrganisationSteps,
ProfileSteps,
TaskSrv,
TaskSteps,
UserSrv,
UserSteps
Expand All @@ -33,6 +34,7 @@ import scala.util.Failure
class Properties @Inject() (
alertSrv: AlertSrv,
caseSrv: CaseSrv,
taskSrv: TaskSrv,
userSrv: UserSrv,
caseTemplateSrv: CaseTemplateSrv,
observableSrv: ObservableSrv
Expand Down Expand Up @@ -202,6 +204,21 @@ class Properties @Inject() (
.property("endDate", UniMapping.date.optional)(_.field.updatable)
.property("order", UniMapping.int)(_.field.updatable)
.property("dueDate", UniMapping.date.optional)(_.field.updatable)
.property("assignee", UniMapping.string.optional)(_.select(_.assignee.login).custom {
case (_, value, vertex, _, graph, authContext) =>
taskSrv
.get(vertex)(graph)
.getOrFail("Task")
.flatMap { task =>
value.fold(taskSrv.unassign(task)(graph, authContext)) { user =>
userSrv
.get(user)(graph)
.getOrFail("User")
.flatMap(taskSrv.assign(task, _)(graph, authContext))
}
}
.map(_ => Json.obj("assignee" -> value))
})
.build

lazy val user: List[PublicProperty[_, _]] =
Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/models/Task.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ case class Task(

case class RichTask(
task: Task with Entity,
owner: Option[User with Entity]
assignee: Option[User with Entity]
) {
def _id: String = task._id
def _createdBy: String = task._createdBy
Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/CaseSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CaseSrv @Inject() (
_ <- caseUserSrv.create(CaseUser(), createdCase, assignee)
_ <- shareSrv.shareCase(owner = true, createdCase, organisation, profileSrv.orgAdmin)
_ <- caseTemplate.map(ct => caseCaseTemplateSrv.create(CaseCaseTemplate(), createdCase, ct.caseTemplate)).flip
createdTasks <- caseTemplate.fold(additionalTasks)(_.tasks.map(t => t.task -> t.owner)).toTry {
createdTasks <- caseTemplate.fold(additionalTasks)(_.tasks.map(t => t.task -> t.assignee)).toTry {
case (task, owner) => taskSrv.create(task, owner)
}
_ <- createdTasks.toTry(t => shareSrv.shareTask(t, createdCase, organisation))
Expand Down
4 changes: 2 additions & 2 deletions thehive/app/org/thp/thehive/services/TaskSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TaskSrv @Inject() (caseSrvProvider: Provider[CaseSrv], auditSrv: AuditSrv,

case TaskStatus.InProgress =>
for {
_ <- get(t).user.headOption().fold(assign(t, o))(_ => Success(()))
_ <- get(t).assignee.headOption().fold(assign(t, o))(_ => Success(()))
updated <- t.startDate.fold(get(t).updateOne("status" -> s, "startDate" -> Some(new Date())))(_ => setStatus())
} yield updated

Expand Down Expand Up @@ -133,7 +133,7 @@ class TaskSteps(raw: GremlinScala[Vertex])(implicit @Named("with-thehive-schema"

def logs = new LogSteps(raw.outTo[TaskLog])

def user = new UserSteps(raw.outTo[TaskUser])
def assignee = new UserSteps(raw.outTo[TaskUser])

def organisations = new OrganisationSteps(raw.inTo[ShareTask].inTo[OrganisationShare])
def organisations(permission: Permission) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ class LogInMyTask(logSrv: LogSrv) extends Trigger {
audit.objectId.fold(false)(taskAssignee(_).fold(false)(_ == u.login))
}

def taskAssignee(logId: String)(implicit graph: Graph): Option[String] = logSrv.getByIds(logId).task.user.login.headOption()
def taskAssignee(logId: String)(implicit graph: Graph): Option[String] = logSrv.getByIds(logId).task.assignee.login.headOption()
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ class TaskAssigned(taskSrv: TaskSrv) extends Trigger {
}

def taskAssignee(taskId: String, login: String)(implicit graph: Graph): Option[User with Entity] =
taskSrv.getByIds(taskId).user.has("login", login).headOption()
taskSrv.getByIds(taskId).assignee.has("login", login).headOption()
}

0 comments on commit d54b7ff

Please sign in to comment.