diff --git a/thehive/app/org/thp/thehive/controllers/v1/Router.scala b/thehive/app/org/thp/thehive/controllers/v1/Router.scala index aac67ed2bc..5f609a94be 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Router.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Router.scala @@ -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) diff --git a/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala index 4c83a40857..103dc91042 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala @@ -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) + } } diff --git a/thehive/app/org/thp/thehive/services/TagSrv.scala b/thehive/app/org/thp/thehive/services/TagSrv.scala index 823da0f84e..4b247a616c 100644 --- a/thehive/app/org/thp/thehive/services/TagSrv.scala +++ b/thehive/app/org/thp/thehive/services/TagSrv.scala @@ -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 {