aptible-rails 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03af48a4efa5ddec7cc540f0d01a87828f4b420d
4
- data.tar.gz: 6868c21741dd2783adc69152b13d234d0428a5c2
3
+ metadata.gz: f8c8647181f9193e2dadf52dce8b7c51a55f2ca9
4
+ data.tar.gz: 53bad54d3476718edeb52c6fb58309a5a5583856
5
5
  SHA512:
6
- metadata.gz: d0763d89950f3c8d29a12cd60e34f9790621dc370509a3ee94c3c81b9a5c0eb851f0ff288f5eba746a2efee95cef0161197d0996d223d0286407ecff85d4dd1f
7
- data.tar.gz: 538e8ba0e491028c6ed9d52c93ad4a38b722c817ad3e23108568165dd08edf4d707083ce4a0cfa2732aa4e3680eb9fe32cec55bc69dededbc83ef6d269cc7d1f
6
+ metadata.gz: 0298c7bc165caefcdf1707c75a208f84df1084d0ea6d41227de2517a5c3ee9f1538d2a9f3d68e72e0cc54c4e3e7ad0ff348ad482f7551a4c7a419f775a83519e
7
+ data.tar.gz: f936cf0cb63c5ded1e4954c6a900b54b95271927bab25783c887bbb02e0f95f78a19633d6c5e3b111e583dbb943689dab186b41d68d03af29e9213f70141adfa
@@ -11,7 +11,8 @@ module Aptible
11
11
  helper_method :current_user, :current_organization, :user_url,
12
12
  :organization_url, :criterion_by_handle, :auth_url,
13
13
  :risk_criterion, :policy_criterion, :security_criterion,
14
- :training_criterion, :url_helpers
14
+ :training_criterion, :url_helpers, :compliance_alerts,
15
+ :criteria
15
16
  end
16
17
 
17
18
  def current_user
@@ -79,6 +80,22 @@ module Aptible
79
80
  end
80
81
  end
81
82
 
83
+ def criteria
84
+ @criteria ||= Aptible::Gridiron::Criterion.where(
85
+ token: service_token,
86
+ organization: current_organization
87
+ )
88
+ end
89
+
90
+ def compliance_alerts
91
+ return @compliance_alerts if @compliance_alerts
92
+ @apps = Aptible::Api::App.all(token: service_token)
93
+ @users = current_organization.users
94
+ @compliance_alerts = ComplianceAlertCollection.new(
95
+ @criteria, @apps, @users
96
+ ).all
97
+ end
98
+
82
99
  def service_token
83
100
  return unless session_token && session_token.session
84
101
  return @service_token if @service_token
@@ -19,3 +19,4 @@ require_relative 'organization_decorator'
19
19
  require_relative 'role_decorator'
20
20
  require_relative 'user_decorator'
21
21
  require_relative 'database_decorator'
22
+ require_relative 'criterion_alert_decorator'
@@ -0,0 +1,61 @@
1
+ class CriterionAlertDecorator < Draper::Decorator
2
+ def alerts
3
+ return [] if object.status == 'green'
4
+ send "#{object.handle}_alerts"
5
+ end
6
+
7
+ def risk_assessment_alerts
8
+ risk_url = Compliance::Application.routes.url_helpers.aptible_risk_path
9
+
10
+ [Alert.new(subject: 'Risk Assessment', requirement: 'needs to be completed',
11
+ subject_href: risk_url, cta: 'Complete Risk Assessment')]
12
+ end
13
+
14
+ def policy_manual_alerts
15
+ policy_url = Compliance::Application.routes.url_helpers.aptible_policy_path
16
+
17
+ [Alert.new(subject: 'Policy Manual', requirement: 'needs to be completed',
18
+ subject_href: policy_url, cta: 'Complete Policy Manual')]
19
+ end
20
+
21
+ def app_security_interview_alerts
22
+ all_apps.reduce([]) do |memo, app|
23
+ next if completed_apps.any? { |href| href == app.href }
24
+ app_path = Aptible::Security::Engine.routes.url_helpers
25
+ .app_path(id: app.id)
26
+ memo + [Alert.new(subject: app.handle, subject_href: app_path,
27
+ requirement: 'needs an App Security Interview',
28
+ cta: 'Complete App Security Interview')]
29
+ end
30
+ end
31
+
32
+ def training_log_alerts
33
+ all_users.reduce([]) do |memo, user|
34
+ next if completed_users.any? { |href| href == user.href }
35
+ user_path = Aptible::Training::Engine.routes.url_helpers.root_path
36
+ memo + [Alert.new(subject: user.name, subject_href: user_path,
37
+ requirement: 'needs Basic HIPAA Training',
38
+ cta: 'Complete Training')]
39
+ end
40
+ end
41
+
42
+ def completed_users
43
+ object.documents.map { |d| d.links['user'].href }.uniq
44
+ end
45
+
46
+ def completed_apps
47
+ object.documents.map { |d| d.links['app'].href }.uniq
48
+ end
49
+
50
+ def all_users
51
+ context[:users]
52
+ end
53
+
54
+ def all_apps
55
+ context[:apps]
56
+ end
57
+
58
+ def method_missing(method)
59
+ return [] if method.to_s =~ /_alerts/
60
+ end
61
+ end
@@ -0,0 +1,14 @@
1
+ class ComplianceAlertCollection
2
+ def initialize(criteria, apps, users)
3
+ @criteria = criteria
4
+ @apps = apps
5
+ @users = users
6
+ end
7
+
8
+ def all
9
+ context = { users: @users, apps: @apps }
10
+ @criteria.map do |criterion|
11
+ CriterionAlertDecorator.decorate(criterion, context: context).alerts || []
12
+ end.flatten
13
+ end
14
+ end
@@ -8,6 +8,10 @@ require 'aptible/rails/garner'
8
8
  require 'draper'
9
9
  require 'aptible/rails/decorators/application_decorator'
10
10
 
11
+ Dir["#{File.dirname(__FILE__)}/models/**/*.rb"].each do |file|
12
+ require file
13
+ end
14
+
11
15
  module Aptible
12
16
  module Rails
13
17
  class Railtie < ::Rails::Railtie
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module Rails
3
- VERSION = '0.6.6'
3
+ VERSION = '0.6.7'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
@@ -185,6 +185,7 @@ files:
185
185
  - lib/aptible/rails/decorators/account_decorator.rb
186
186
  - lib/aptible/rails/decorators/app_decorator.rb
187
187
  - lib/aptible/rails/decorators/application_decorator.rb
188
+ - lib/aptible/rails/decorators/criterion_alert_decorator.rb
188
189
  - lib/aptible/rails/decorators/criterion_decorator.rb
189
190
  - lib/aptible/rails/decorators/database_decorator.rb
190
191
  - lib/aptible/rails/decorators/operation_decorator.rb
@@ -194,6 +195,7 @@ files:
194
195
  - lib/aptible/rails/decorators/user_decorator.rb
195
196
  - lib/aptible/rails/draper_extensions.rb
196
197
  - lib/aptible/rails/garner.rb
198
+ - lib/aptible/rails/models/compliance_alert_collection.rb
197
199
  - lib/aptible/rails/railtie.rb
198
200
  - lib/aptible/rails/url_helper.rb
199
201
  - lib/aptible/rails/version.rb