Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hide & show alert status actions #13650

Merged
merged 1 commit into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/models/miq_alert_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class MiqAlertStatus < ApplicationRecord
belongs_to :ext_management_system
has_many :miq_alert_status_actions, -> { order "created_at" }, :dependent => :destroy
virtual_column :assignee, :type => :string
virtual_column :hidden, :type => :boolean

validates :severity, :acceptance => { :accept => SEVERITY_LEVELS }

Expand All @@ -19,4 +20,8 @@ def assignee
def assigned?
assignee.present?
end

def hidden?
miq_alert_status_actions.where(:action_type => %w(hide show)).last.try(:action_type) == 'hide'
end
end
7 changes: 4 additions & 3 deletions app/models/miq_alert_status_action.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class MiqAlertStatusAction < ApplicationRecord
ACTION_TYPES = %w(assign acknowledge comment unassign unacknowledge).freeze
ACTION_TYPES = %w(assign acknowledge comment unassign unacknowledge hide show).freeze

belongs_to :miq_alert_status
belongs_to :assignee, :class_name => 'User'
Expand All @@ -15,8 +15,9 @@ class MiqAlertStatusAction < ApplicationRecord
after_save :update_status_acknowledgement

def only_assignee_can_acknowledge
if action_type == 'acknowledge' && miq_alert_status.assignee.try(:id) != user.id
errors.add(:user, "that is not assigned cannot acknowledge")
if ['acknowledge', 'unacknowledge', 'hide', 'show'].include?(action_type) &&
miq_alert_status.assignee.try(:id) != user.id
errors.add(:user, "that is not assigned cannot #{action_type}")
end
end

Expand Down
22 changes: 22 additions & 0 deletions spec/models/miq_alert_status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
FactoryGirl.create(:miq_alert_status_action, :action_type => 'assign', :user => user1, :assignee => user1,
:miq_alert_status => alert)
end
let(:hide_action) do
FactoryGirl.create(:miq_alert_status_action, :action_type => 'hide', :user => user1, :miq_alert_status => alert)
end
let(:show_action) do
FactoryGirl.create(:miq_alert_status_action, :action_type => 'show', :user => user1, :miq_alert_status => alert)
end

describe "Validation" do
it "should reject unexpected severities" do
Expand Down Expand Up @@ -106,4 +112,20 @@
expect(alert.assignee).to be_nil
end
end

describe "#hidden?" do
it "returns false for new" do
expect(alert.hidden?).to be_falsey
end

it "returns true after hide action" do
alert.miq_alert_status_actions = [assignment_action, hide_action]
expect(alert.hidden?).to be_truthy
end

it "returns false after show action" do
alert.miq_alert_status_actions = [assignment_action, hide_action, show_action]
expect(alert.hidden?).to be_falsey
end
end
end