@@ -61,6 +61,10 @@ case class AddLogToTask(content: String, owner: Option[String], status: ActionOp
61
61
override def updateStatus (newStatus : Type , newMessage : String ): ActionOperation = copy(status = newStatus, message = newMessage)
62
62
}
63
63
64
+ case class AddTagToAlert (tag : String , status : ActionOperationStatus .Type = ActionOperationStatus .Waiting , message : String = " " ) extends ActionOperation {
65
+ override def updateStatus (newStatus : ActionOperationStatus .Type , newMessage : String ): AddTagToAlert = copy(status = newStatus, message = newMessage)
66
+ }
67
+
64
68
object ActionOperation {
65
69
val addTagToCaseWrites = Json .writes[AddTagToCase ]
66
70
val addTagToArtifactWrites = Json .writes[AddTagToArtifact ]
@@ -69,6 +73,7 @@ object ActionOperation {
69
73
val closeTaskWrites = Json .writes[CloseTask ]
70
74
val markAlertAsReadWrites = Json .writes[MarkAlertAsRead ]
71
75
val addLogToTaskWrites = Json .writes[AddLogToTask ]
76
+ val addTagToAlertWrites = Json .writes[AddTagToAlert ]
72
77
implicit val actionOperationReads : Reads [ActionOperation ] = Reads [ActionOperation ](json ⇒
73
78
(json \ " type" ).asOpt[String ].fold[JsResult [ActionOperation ]](JsError (" type is missing in action operation" )) {
74
79
case " AddTagToCase" ⇒ (json \ " tag" ).validate[String ].map(tag ⇒ AddTagToCase (tag))
@@ -85,6 +90,7 @@ object ActionOperation {
85
90
content ← (json \ " content" ).validate[String ]
86
91
owner ← (json \ " owner" ).validateOpt[String ]
87
92
} yield AddLogToTask (content, owner)
93
+ case " AddTagToAlert" => (json \ " tag" ).validate[String ].map(tag ⇒ AddTagToAlert (tag))
88
94
case other ⇒ JsError (s " Unknown operation $other" )
89
95
})
90
96
implicit val actionOperationWrites : Writes [ActionOperation ] = Writes [ActionOperation ] {
@@ -95,6 +101,7 @@ object ActionOperation {
95
101
case a : CloseTask ⇒ closeTaskWrites.writes(a)
96
102
case a : MarkAlertAsRead ⇒ markAlertAsReadWrites.writes(a)
97
103
case a : AddLogToTask ⇒ addLogToTaskWrites.writes(a)
104
+ case a : AddTagToAlert ⇒ addTagToAlertWrites.writes(a)
98
105
case a ⇒ Json .obj(" unsupported operation" → a.toString)
99
106
}
100
107
}
@@ -198,6 +205,15 @@ class ActionOperationSrv @Inject() (
198
205
task ← findTaskEntity(entity)
199
206
_ ← logSrv.create(task, Fields .empty.set(" message" , content).set(" owner" , owner.map(JsString )))
200
207
} yield operation.updateStatus(ActionOperationStatus .Success , " " )
208
+ case AddTagToAlert (tag, _, _) =>
209
+ entity match {
210
+ case initialAlert : Alert ⇒
211
+ for {
212
+ alert ← alertSrv.get(initialAlert.id)
213
+ _ ← alertSrv.update(alert.id, Fields .empty.set(" tags" , Json .toJson((alert.tags() :+ tag).distinct)), ModifyConfig (retryOnConflict = 0 , version = Some (alert.version)))
214
+ } yield operation.updateStatus(ActionOperationStatus .Success , " " )
215
+ case _ ⇒ Future .failed(BadRequestError (" Alert not found" ))
216
+ }
201
217
case o ⇒ Future .successful(operation.updateStatus(ActionOperationStatus .Failure , s " Operation $o not supported " ))
202
218
}
203
219
}
0 commit comments