Skip to content

Commit

Permalink
#1552 Renamed val & used contains()
Browse files Browse the repository at this point in the history
  • Loading branch information
rriclet authored and To-om committed Nov 6, 2020
1 parent 93837f2 commit 04fc1a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions thehive/app/org/thp/thehive/services/AlertSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class AlertSrv @Inject() (
_ <- alertOrganisationSrv.create(AlertOrganisation(), createdAlert, organisation)
_ <- caseTemplate.map(ct => alertCaseTemplateSrv.create(AlertCaseTemplate(), createdAlert, ct)).flip
_ <- tags.toTry(t => alertTagSrv.create(AlertTag(), createdAlert, t))
cfs <- customFields.toTry { simpleCf: InputCustomFieldValue => createCustomField(createdAlert, simpleCf) }
cfs <- customFields.toTry { cf: InputCustomFieldValue => createCustomField(createdAlert, cf) }
richAlert = RichAlert(createdAlert, organisation.name, tags, cfs, None, caseTemplate.map(_.name), 0)
_ <- auditSrv.alert.create(createdAlert, richAlert.toJson)
} yield richAlert
Expand Down Expand Up @@ -171,23 +171,23 @@ class AlertSrv @Inject() (

def createCustomField(
alert: Alert with Entity,
simpleCf: InputCustomFieldValue
inputCf: InputCustomFieldValue
)(implicit graph: Graph, authContext: AuthContext): Try[RichCustomField] =
for {
cf <- customFieldSrv.getOrFail(EntityIdOrName(simpleCf.name))
ccf <- CustomFieldType.map(cf.`type`).setValue(AlertCustomField(), simpleCf.value).map(_.order_=(simpleCf.order))
cf <- customFieldSrv.getOrFail(EntityIdOrName(inputCf.name))
ccf <- CustomFieldType.map(cf.`type`).setValue(AlertCustomField(), inputCf.value).map(_.order_=(inputCf.order))
ccfe <- alertCustomFieldSrv.create(ccf, alert, cf)
} yield RichCustomField(cf, ccfe)

def setOrCreateCustomField(alert: Alert with Entity, simpleCf: InputCustomFieldValue)(implicit
def setOrCreateCustomField(alert: Alert with Entity, cf: InputCustomFieldValue)(implicit
graph: Graph,
authContext: AuthContext
): Try[Unit] = {
val cfv = get(alert).customFields(simpleCf.name)
val cfv = get(alert).customFields(cf.name)
if (cfv.clone().exists)
cfv.setValue(simpleCf.value)
cfv.setValue(cf.value)
else
createCustomField(alert, simpleCf).map(_ => ())
createCustomField(alert, cf).map(_ => ())
}

def getCustomField(alert: Alert with Entity, customFieldName: String)(implicit graph: Graph): Option[RichCustomField] =
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 @@ -96,7 +96,7 @@ class CaseSrv @Inject() (

private def cleanCustomFields(caseTemplateCf: Seq[InputCustomFieldValue], caseCf: Seq[InputCustomFieldValue]): Seq[InputCustomFieldValue] = {
val uniqueFields = caseTemplateCf.filter {
case InputCustomFieldValue(name, _, _) => !caseCf.map(c => c.name).contains(name)
case InputCustomFieldValue(name, _, _) => !caseCf.exists(_.name == name)
}
(caseCf ++ uniqueFields)
.sortBy(cf => (cf.order.isEmpty, cf.order))
Expand Down

0 comments on commit 04fc1a8

Please sign in to comment.