Skip to content

Commit

Permalink
#1543 Replaced soft delete by hard delete
Browse files Browse the repository at this point in the history
  • Loading branch information
rriclet authored and To-om committed Oct 29, 2020
1 parent 934548a commit 69b9425
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 23 deletions.
11 changes: 0 additions & 11 deletions thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,6 @@ class CaseCtrl @Inject() (
}

def delete(caseIdOrNumber: String): Action[AnyContent] =
entrypoint("delete case")
.authTransaction(db) { implicit request => implicit graph =>
caseSrv
.get(EntityIdOrName(caseIdOrNumber))
.can(Permissions.manageCase)
.update(_.status, CaseStatus.Deleted)
.getOrFail("Case")
.map(_ => Results.NoContent)
}

def realDelete(caseIdOrNumber: String): Action[AnyContent] =
entrypoint("delete case")
.authTransaction(db) { implicit request => implicit graph =>
for {
Expand Down
4 changes: 2 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v0/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ class Router @Inject() (
case PATCH(p"/case/_bulk") => caseCtrl.bulkUpdate // Not used by the frontend
case PATCH(p"/case/$caseId") => caseCtrl.update(caseId) // Audit ok
case POST(p"/case/_merge/$caseIds") => caseCtrl.merge(caseIds) // Not implemented in backend and not used by frontend
case DELETE(p"/case/$caseId") => caseCtrl.delete(caseId) // Not used by frontend
case POST(p"/case/_search") => caseCtrl.search
case POST(p"/case/_stats") => caseCtrl.stats
case DELETE(p"/case/$caseId/force") => caseCtrl.realDelete(caseId) // Audit ok
case DELETE(p"/case/$caseId") => caseCtrl.delete(caseId) // Not used by the frontend
case DELETE(p"/case/$caseId/force") => caseCtrl.delete(caseId) // Audit ok
case GET(p"/case/$caseId/links") => caseCtrl.linkedCases(caseId)

case GET(p"/case/template") => caseTemplateCtrl.search
Expand Down
14 changes: 8 additions & 6 deletions thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ class CaseCtrl @Inject() (
def delete(caseIdOrNumber: String): Action[AnyContent] =
entrypoint("delete case")
.authTransaction(db) { implicit request => implicit graph =>
caseSrv
.get(EntityIdOrName(caseIdOrNumber))
.can(Permissions.manageCase)
.update(_.status, CaseStatus.Deleted)
.getOrFail("Case")
.map(_ => Results.NoContent)
for {
c <-
caseSrv
.get(EntityIdOrName(caseIdOrNumber))
.can(Permissions.manageCase)
.getOrFail("Case")
_ <- caseSrv.remove(c)
} yield Results.NoContent
}

def merge(caseIdsOrNumbers: String): Action[AnyContent] =
Expand Down
1 change: 0 additions & 1 deletion thehive/app/org/thp/thehive/controllers/v1/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class Router @Inject() (
case DELETE(p"/case/$caseId") => caseCtrl.delete(caseId)
// case PATCH(p"api/case/_bulk") => caseCtrl.bulkUpdate()
// case POST(p"/case/_stats") => caseCtrl.stats()
// case DELETE(p"/case/$caseId/force") => caseCtrl.realDelete(caseId)
// case GET(p"/case/$caseId/links") => caseCtrl.linkedCases(caseId)

case GET(p"/caseTemplate") => caseTemplateCtrl.list
Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/models/Case.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.thp.scalligraph.models.{DefineIndex, Entity, IndexType}
import play.api.libs.json.{Format, Json}

object CaseStatus extends Enumeration {
val Open, Resolved, Deleted, Duplicated = Value
val Open, Resolved, Duplicated = Value

implicit val format: Format[CaseStatus.Value] = Json.formatEnum(CaseStatus)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.thp.scalligraph.traversal.{Converter, IdentityConverter, Traversal}
import org.thp.scalligraph.{BadConfigurationError, EntityIdOrName}
import org.thp.thehive.controllers.v0.AuditRenderer
import org.thp.thehive.controllers.v0.Conversion.fromObjectType
import org.thp.thehive.models.Audit._
import org.thp.thehive.models._
import org.thp.thehive.services.AlertOps._
import org.thp.thehive.services.AuditOps._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class CaseCtrlTest extends PlaySpecification with TestAppBuilder {

val requestDel = FakeRequest("DELETE", s"/api/v0/case/#1/force")
.withHeaders("user" -> "certuser@thehive.local")
val resultDel = app[CaseCtrl].realDelete("1")(requestDel)
val resultDel = app[CaseCtrl].delete("1")(requestDel)
status(resultDel) must equalTo(204).updateMessage(s => s"$s\n${contentAsString(resultDel)}")

app[Database].roTransaction { implicit graph =>
Expand Down

0 comments on commit 69b9425

Please sign in to comment.