Skip to content

Commit

Permalink
#1264 added delete route for CaseCustomField
Browse files Browse the repository at this point in the history
  • Loading branch information
rriclet committed Mar 3, 2021
1 parent be9fc12 commit 89f6e2c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
8 changes: 8 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ class CaseCtrl @Inject() (
} yield Results.NoContent
}

def deleteCustomField(cfId: String): Action[AnyContent] =
entrypoint("delete a custom field")
.authPermittedTransaction(db, Permissions.manageCase) { implicit request => implicit graph =>
for {
_ <- caseSrv.deleteCustomField(EntityIdOrName(cfId))
} yield Results.NoContent
}

def merge(caseIdsOrNumbers: String): Action[AnyContent] =
entrypoint("merge cases")
.authTransaction(db) { implicit request => implicit graph =>
Expand Down
13 changes: 7 additions & 6 deletions thehive/app/org/thp/thehive/controllers/v1/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ class Router @Inject() (
case POST(p"/auth/totp/unset") => authenticationCtrl.totpUnsetSecret(None)
case POST(p"/auth/totp/unset/$user") => authenticationCtrl.totpUnsetSecret(Some(user))

case POST(p"/case") => caseCtrl.create
case GET(p"/case/$caseId") => caseCtrl.get(caseId)
case PATCH(p"/case/$caseId") => caseCtrl.update(caseId)
case POST(p"/case/_merge/$caseIds") => caseCtrl.merge(caseIds)
case DELETE(p"/case/$caseId") => caseCtrl.delete(caseId)
// case PATCH(p"api/case/_bulk") => caseCtrl.bulkUpdate()
case POST(p"/case") => caseCtrl.create
case GET(p"/case/$caseId") => caseCtrl.get(caseId)
case PATCH(p"/case/$caseId") => caseCtrl.update(caseId)
case POST(p"/case/_merge/$caseIds") => caseCtrl.merge(caseIds)
case DELETE(p"/case/$caseId") => caseCtrl.delete(caseId)
case DELETE(p"/case/customField/$cfId") => caseCtrl.deleteCustomField(cfId)
// case PATCH(p"api/case/_bulk") => caseCtrl.bulkUpdate()
// case POST(p"/case/_stats") => caseCtrl.stats()
// case GET(p"/case/$caseId/links") => caseCtrl.linkedCases(caseId)

Expand Down
21 changes: 15 additions & 6 deletions thehive/app/org/thp/thehive/services/CaseSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ class CaseSrv @Inject() (
ccfe <- caseCustomFieldSrv.create(ccf, `case`, cf)
} yield RichCustomField(cf, ccfe)

def deleteCustomField(
cfIdOrName: EntityIdOrName
)(implicit graph: Graph, authContext: AuthContext): Try[Unit] =
Try(
caseCustomFieldSrv
.get(cfIdOrName)
.filter(_.outV.v[Case].can(Permissions.manageCase))
.remove()
)

def setImpactStatus(
`case`: Case with Entity,
impactStatus: String
Expand Down Expand Up @@ -408,18 +418,17 @@ object CaseOps {
) -> renderedEntity
}

def customFields: Traversal.E[CaseCustomField] = traversal.outE[CaseCustomField]

def customFields(idOrName: EntityIdOrName): Traversal.E[CaseCustomField] =
idOrName
.fold(
id => traversal.outE[CaseCustomField].filter(_.inV.getByIds(id)),
name => traversal.outE[CaseCustomField].filter(_.inV.v[CustomField].has(_.name, name))
id => customFields.filter(_.inV.getByIds(id)),
name => customFields.filter(_.inV.v[CustomField].has(_.name, name))
)

def customFields: Traversal.E[CaseCustomField] = traversal.outE[CaseCustomField]

def richCustomFields: Traversal[RichCustomField, JMap[String, Any], Converter[RichCustomField, JMap[String, Any]]] =
traversal
.outE[CaseCustomField]
customFields
.project(_.by.by(_.inV.v[CustomField]))
.domainMap {
case (cfv, cf) => RichCustomField(cf, cfv)
Expand Down

0 comments on commit 89f6e2c

Please sign in to comment.