Skip to content

Commit

Permalink
#1670 Permit to delete a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 5, 2021
1 parent 6b9d6d5 commit 9b61f78
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v1/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ class Router @Inject() (
case PATCH(p"/profile/$profileId") => profileCtrl.update(profileId)
case DELETE(p"/profile/$profileId") => profileCtrl.delete(profileId)

case GET(p"/tag/$id") => tagCtrl.get(id)
case PATCH(p"/tag/$id") => tagCtrl.update(id)
case GET(p"/tag/$id") => tagCtrl.get(id)
case PATCH(p"/tag/$id") => tagCtrl.update(id)
case DELETE(p"/tag/$id") => tagCtrl.delete(id)

case GET(p"/describe/_all") => describeCtrl.describeAll
case GET(p"/describe/$modelName") => describeCtrl.describe(modelName)
Expand Down
10 changes: 10 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,14 @@ class TagCtrl @Inject() (
.update(_.getFreetag(organisationSrv, EntityIdOrName(tagId)), propertyUpdaters)
.map(_ => Results.NoContent)
}

def delete(tagId: String): Action[AnyContent] =
entrypoint("delete tag")
.authPermittedTransaction(db, Permissions.manageTag) { implicit request => implicit graph =>
tagSrv
.getFreetag(EntityIdOrName(tagId))
.getOrFail("Tag")
.flatMap(tagSrv.delete)
.map(_ => Results.NoContent)
}
}
3 changes: 3 additions & 0 deletions thehive/app/org/thp/thehive/services/TagSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class TagSrv @Inject() (

def getTag(tag: Tag)(implicit graph: Graph): Traversal.V[Tag] = startTraversal.getTag(tag)

def getFreetag(idOrName: EntityIdOrName)(implicit graph: Graph, authContext: AuthContext): Traversal.V[Tag] =
startTraversal.getFreetag(organisationSrv, idOrName)

def getOrCreate(tagName: String)(implicit graph: Graph, authContext: AuthContext): Try[Tag with Entity] =
fromString(tagName)
.flatMap {
Expand Down

0 comments on commit 9b61f78

Please sign in to comment.