Skip to content

Commit

Permalink
Merge pull request #13650 from moolitayer/add_hide_action
Browse files Browse the repository at this point in the history
Add hide & show alert status actions
  • Loading branch information
gtanzillo authored Feb 13, 2017
2 parents 382636e + 47f08d5 commit ae43f33
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
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

0 comments on commit ae43f33

Please sign in to comment.