Skip to content

Commit

Permalink
#1264 Move permission check from service to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 11, 2021
1 parent 6066a58 commit 17662f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 3 additions & 4 deletions thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package org.thp.thehive.controllers.v0
import org.apache.tinkerpop.gremlin.process.traversal.P
import org.thp.scalligraph._
import org.thp.scalligraph.controllers.{Entrypoint, FPathElem, FPathEmpty, FieldsParser}
import org.thp.scalligraph.models.{Database, Entity, UMapping}
import org.thp.scalligraph.models.{Database, UMapping}
import org.thp.scalligraph.query._
import org.thp.scalligraph.traversal.TraversalOps._
import org.thp.scalligraph.traversal.{Graph, IteratorOutput, Traversal}
import org.thp.scalligraph.traversal.{IteratorOutput, Traversal}
import org.thp.thehive.controllers.v0.Conversion._
import org.thp.thehive.dto.v0.{InputCase, InputTask}
import org.thp.thehive.dto.v1.InputCustomFieldValue
Expand All @@ -17,14 +17,13 @@ import org.thp.thehive.services.CaseTemplateOps._
import org.thp.thehive.services.CustomFieldOps._
import org.thp.thehive.services.ObservableOps._
import org.thp.thehive.services.OrganisationOps._
import org.thp.thehive.services.ShareOps._
import org.thp.thehive.services.UserOps._
import org.thp.thehive.services._
import play.api.libs.json._
import play.api.mvc.{Action, AnyContent, Results}

import javax.inject.{Inject, Named, Singleton}
import scala.util.{Failure, Success, Try}
import scala.util.{Failure, Success}

@Singleton
class CaseCtrl @Inject() (
Expand Down
6 changes: 6 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class CaseCtrl @Inject() (
entrypoint("delete a custom field")
.authPermittedTransaction(db, Permissions.manageCase) { implicit request => implicit graph =>
for {
_ <-
caseSrv
.caseCustomFieldSrv
.get(EntityIdOrName(cfId))
.filter(_.outV.v[Case].can(Permissions.manageCase))
.existsOrFail
_ <- caseSrv.deleteCustomField(EntityIdOrName(cfId))
} yield Results.NoContent
}
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 @@ -265,7 +265,7 @@ class CaseSrv @Inject() (
Try(
caseCustomFieldSrv
.get(cfIdOrName)
.filter(_.outV.v[Case].can(Permissions.manageCase))
.filter(_.outV.v[Case])
.remove()
)

Expand Down

0 comments on commit 17662f6

Please sign in to comment.