forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ManageIQ#13325 from moolitayer/alert_actions_api
Add alert actions api
- Loading branch information
Showing
6 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Api | ||
class AlertActionsController < BaseController | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module Api | ||
class AlertsController < BaseController | ||
include Subcollections::AlertActions | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Api | ||
module Subcollections | ||
module AlertActions | ||
def alert_actions_query_resource(object) | ||
object.miq_alert_status_actions | ||
end | ||
|
||
def alert_actions_create_resource(object, type, _id, data) | ||
attributes = data.dup | ||
attributes['miq_alert_status_id'] = object.id | ||
attributes['user_id'] = User.current_user.id | ||
if data.key?('assignee') | ||
attributes['assignee_id'] = parse_id(attributes.delete('assignee'), :users) | ||
end | ||
alert_action = collection_class(type).create(attributes) | ||
if alert_action.invalid? | ||
raise BadRequestError, | ||
"Failed to add a new alert action resource - #{alert_action.errors.full_messages.join(', ')}" | ||
end | ||
alert_action | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters