diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/compliance_check_resource.rb | 2 | ||||
| -rw-r--r-- | app/models/compliance_check_set.rb | 44 |
2 files changed, 16 insertions, 30 deletions
diff --git a/app/models/compliance_check_resource.rb b/app/models/compliance_check_resource.rb index 2989bf3cf..777254aaf 100644 --- a/app/models/compliance_check_resource.rb +++ b/app/models/compliance_check_resource.rb @@ -3,7 +3,7 @@ class ComplianceCheckResource < ActiveRecord::Base belongs_to :compliance_check_set - enumerize :status, in: %i(OK ERROR WARNING IGNORED), scope: true + enumerize :status, in: %i(OK ERROR WARNING IGNORED) validates_presence_of :compliance_check_set end diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index 289fc134f..49d324c53 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -49,39 +49,25 @@ class ComplianceCheckSet < ActiveRecord::Base end def update_status - statuses = compliance_check_resources.map do |resource| - case resource.status - when 'ERROR' - return update(status: 'failed') - when 'WARNING' - return update(status: 'warning') - else - resource.status + status = + if compliance_check_resources.where(status: 'ERROR').count > 0 + 'failed' + elsif compliance_check_resources.where(status: ["WARNING", "IGNORED"]).count > 0 + 'warning' + elsif compliance_check_resources.where(status: "OK").count == compliance_check_resources.count + 'successful' end - end - if statuses_ok_or_ignored?(statuses) - return update(status: 'successful') + attributes = { + status: status + } + + if self.class.finished_statuses.include?(status) + attributes[:ended_at] = Time.now end - true + update attributes end - private - - def statuses_ok_or_ignored?(statuses) - uniform_statuses = statuses.uniq - - ( - # All statuses OK - uniform_statuses.length == 1 && - uniform_statuses.first == 'OK' - ) || - ( - # Statuses OK or IGNORED - uniform_statuses.length == 2 && - uniform_statuses.include?('OK') && - uniform_statuses.include?('IGNORED') - ) - end + end |
