diff options
| author | Luc Donnet | 2018-03-09 08:57:48 +0100 |
|---|---|---|
| committer | GitHub | 2018-03-09 08:57:48 +0100 |
| commit | 523d3e418539cfe6af98bdcbae82d1f7d3fdd3c0 (patch) | |
| tree | 28af12464ebeb9368d9d9dd9c9970ea66003fa25 /app | |
| parent | 186662b9ef2e996ec649298debb3df352f9849bf (diff) | |
| parent | d79abf1d6c63004da9f1d969e8edee4d9cd52393 (diff) | |
| download | chouette-core-523d3e418539cfe6af98bdcbae82d1f7d3fdd3c0.tar.bz2 | |
Merge pull request #366 from af83/5989-fix_compliance_check_resource_status
Fix compliance_check_resource and compliance_check_set status Refs #5…
Diffstat (limited to 'app')
| -rw-r--r-- | app/helpers/compliance_check_resources_helper.rb | 4 | ||||
| -rw-r--r-- | app/models/compliance_check_resource.rb | 2 | ||||
| -rw-r--r-- | app/models/compliance_check_set.rb | 44 |
3 files changed, 18 insertions, 32 deletions
diff --git a/app/helpers/compliance_check_resources_helper.rb b/app/helpers/compliance_check_resources_helper.rb index 95cabed88..19b152e8d 100644 --- a/app/helpers/compliance_check_resources_helper.rb +++ b/app/helpers/compliance_check_resources_helper.rb @@ -4,8 +4,8 @@ module ComplianceCheckResourcesHelper def compliance_check_resource_status(status) cls = '' cls = 'success' if status == 'OK' - cls = 'warning' if status == 'WARNING' - cls = 'danger' if %w[ERROR IGNORED].include? status + cls = 'warning' if %w[WARNING IGNORED].include? status + cls = 'danger' if status == 'ERROR' content_tag :span, '', class: "fa fa-circle text-#{cls}" end 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 |
